latigerlilly
02-05-2007, 02:57 PM
Hi guys,
I wrote a program for the BS2P40 on the PDB to display "dog" on its 7 segment LED display as a default. When button 1 is pressed, it will display god for 1 second. When button 2 is pressed, it will display odd for 1 second. This first program works, but it is brute force computer programming. When you read it, you'll know what I mean.
The second post here in this thread has a more elegant computer program, but it doesn't work. The default only displays just the letter "d". When button 1 is pressed, it only displays "8" permenantly. When button 2 is pressed, it experiences no change.
How do I make the more elegant computer program work? What did I do wrong?
Also, I thought that a more elegant computer program will use less memory, but I checked and the more elegant version used 24% of the memory while the brute force computer program only used 19% of available memory. It doesn't make sense. I mean, wouldn't typing GOSUB X a million times take more memory than using a simple set of instructions set in EEPROM ?
Thanks a million,
Lilly. http://forums.parallax.com/images/smilies/tongue.gif
Here is the brute force program that works:
' Learning on the PDB - experimental.bs2p
' Spells "dog" on the 7 segment LED display on the PDB as the default.
' Spells "god" on the 7 segment LED display on the PDB when button 1 connected to RB0 is pressed.
' Spells "odd" on the 7 segment LED display on the PDB when button 2 connected to RB1 is pressed.
' 7 segment LED display has digits 4, 3, and 2 used on X19.
' 7 segment LED display has segments A through G used on X18. Segment DP is not used.
' Digits 4, 3, and 2 are connected to P5, P4, and P3, respectively.
' Segments A, B, C, D, E, and F are connected to P6, P7, P8, P9, P10, and P11, respectively.
' Segment G is connected to P14.
' {$STAMP BS2p}
' {$PBASIC 2.5}
DEBUG "Program Running!"
counter VAR Word
GOSUB l4
DO
MAINIO
IF (IN8 = 0) THEN
' If button 1 is pressed then display god
FOR counter = 1 TO 33
GOSUB hg
PAUSE 5
GOSUB h4
GOSUB l3
GOSUB lg
GOSUB ho
PAUSE 5
GOSUB h3
GOSUB l2
GOSUB lo
GOSUB hd
PAUSE 5
GOSUB h2
GOSUB l4
GOSUB ld
NEXT
ELSEIF (IN9 = 0) THEN
' If button 2 is pressed then display odd
FOR counter = 1 TO 33
GOSUB ho
PAUSE 5
GOSUB h4
GOSUB l3
GOSUB lo
GOSUB hd
PAUSE 5
GOSUB h3
GOSUB l2
GOSUB ld
GOSUB hd
PAUSE 5
GOSUB h2
GOSUB l4
GOSUB ld
NEXT
ELSE
'If no button is pressed then display dog.
GOSUB hd
PAUSE 5
GOSUB h4
GOSUB l3
GOSUB ld
GOSUB ho
PAUSE 5
GOSUB h3
GOSUB l2
GOSUB lo
GOSUB hg
PAUSE 5
GOSUB h2
GOSUB l4
GOSUB lg
ENDIF
LOOP
' Sets digit 4 of display on vss.
l4:
MAINIO
LOW 5
RETURN
' Sets digit 3 of display on vss.
l3:
MAINIO
LOW 4
RETURN
' Sets digit 2 of display on vss.
l2:
MAINIO
LOW 3
RETURN
' Sets digit 4 of display on vdd.
h4:
MAINIO
HIGH 5
RETURN
' Sets digit 3 of display on vdd.
h3:
MAINIO
HIGH 4
RETURN
'Sets digit 2 of display on vdd.
h2:
MAINIO
HIGH 3
RETURN
' Sets segments of display for the letter d on vdd.
hd:
MAINIO
HIGH 7
AUXIO
HIGH 14
HIGH 10
HIGH 8
HIGH 9
RETURN
' Sets segments of display for the letter d on vss.
ld:
MAINIO
LOW 7
AUXIO
LOW 14
LOW 10
LOW 8
LOW 9
RETURN
' Sets segments of display for the letter o on vdd.
ho:
AUXIO
HIGH 14
HIGH 10
HIGH 8
HIGH 9
RETURN
' Sets segments of display for the letter o on vss.
lo:
AUXIO
LOW 14
LOW 10
LOW 8
LOW 9
RETURN
' Sets segments of display for the letter g on vdd.
hg:
MAINIO
HIGH 6
HIGH 7
AUXIO
HIGH 14
HIGH 11
HIGH 8
HIGH 9
RETURN
' Sets segments of diplay for the letter g on vss.
lg:
MAINIO
LOW 6
LOW 7
AUXIO
LOW 14
LOW 11
LOW 8
LOW 9
RETURN
Pics;
http://i15.photobucket.com/albums/a371/MINGMAY/Image013.jpg
http://i15.photobucket.com/albums/a371/MINGMAY/Image014-1.jpg
http://i15.photobucket.com/albums/a371/MINGMAY/Image005.jpg
http://i15.photobucket.com/albums/a371/MINGMAY/Image020.jpg
Post Edited (latigerlilly) : 2/5/2007 4:13:19 PM GMT
I wrote a program for the BS2P40 on the PDB to display "dog" on its 7 segment LED display as a default. When button 1 is pressed, it will display god for 1 second. When button 2 is pressed, it will display odd for 1 second. This first program works, but it is brute force computer programming. When you read it, you'll know what I mean.
The second post here in this thread has a more elegant computer program, but it doesn't work. The default only displays just the letter "d". When button 1 is pressed, it only displays "8" permenantly. When button 2 is pressed, it experiences no change.
How do I make the more elegant computer program work? What did I do wrong?
Also, I thought that a more elegant computer program will use less memory, but I checked and the more elegant version used 24% of the memory while the brute force computer program only used 19% of available memory. It doesn't make sense. I mean, wouldn't typing GOSUB X a million times take more memory than using a simple set of instructions set in EEPROM ?
Thanks a million,
Lilly. http://forums.parallax.com/images/smilies/tongue.gif
Here is the brute force program that works:
' Learning on the PDB - experimental.bs2p
' Spells "dog" on the 7 segment LED display on the PDB as the default.
' Spells "god" on the 7 segment LED display on the PDB when button 1 connected to RB0 is pressed.
' Spells "odd" on the 7 segment LED display on the PDB when button 2 connected to RB1 is pressed.
' 7 segment LED display has digits 4, 3, and 2 used on X19.
' 7 segment LED display has segments A through G used on X18. Segment DP is not used.
' Digits 4, 3, and 2 are connected to P5, P4, and P3, respectively.
' Segments A, B, C, D, E, and F are connected to P6, P7, P8, P9, P10, and P11, respectively.
' Segment G is connected to P14.
' {$STAMP BS2p}
' {$PBASIC 2.5}
DEBUG "Program Running!"
counter VAR Word
GOSUB l4
DO
MAINIO
IF (IN8 = 0) THEN
' If button 1 is pressed then display god
FOR counter = 1 TO 33
GOSUB hg
PAUSE 5
GOSUB h4
GOSUB l3
GOSUB lg
GOSUB ho
PAUSE 5
GOSUB h3
GOSUB l2
GOSUB lo
GOSUB hd
PAUSE 5
GOSUB h2
GOSUB l4
GOSUB ld
NEXT
ELSEIF (IN9 = 0) THEN
' If button 2 is pressed then display odd
FOR counter = 1 TO 33
GOSUB ho
PAUSE 5
GOSUB h4
GOSUB l3
GOSUB lo
GOSUB hd
PAUSE 5
GOSUB h3
GOSUB l2
GOSUB ld
GOSUB hd
PAUSE 5
GOSUB h2
GOSUB l4
GOSUB ld
NEXT
ELSE
'If no button is pressed then display dog.
GOSUB hd
PAUSE 5
GOSUB h4
GOSUB l3
GOSUB ld
GOSUB ho
PAUSE 5
GOSUB h3
GOSUB l2
GOSUB lo
GOSUB hg
PAUSE 5
GOSUB h2
GOSUB l4
GOSUB lg
ENDIF
LOOP
' Sets digit 4 of display on vss.
l4:
MAINIO
LOW 5
RETURN
' Sets digit 3 of display on vss.
l3:
MAINIO
LOW 4
RETURN
' Sets digit 2 of display on vss.
l2:
MAINIO
LOW 3
RETURN
' Sets digit 4 of display on vdd.
h4:
MAINIO
HIGH 5
RETURN
' Sets digit 3 of display on vdd.
h3:
MAINIO
HIGH 4
RETURN
'Sets digit 2 of display on vdd.
h2:
MAINIO
HIGH 3
RETURN
' Sets segments of display for the letter d on vdd.
hd:
MAINIO
HIGH 7
AUXIO
HIGH 14
HIGH 10
HIGH 8
HIGH 9
RETURN
' Sets segments of display for the letter d on vss.
ld:
MAINIO
LOW 7
AUXIO
LOW 14
LOW 10
LOW 8
LOW 9
RETURN
' Sets segments of display for the letter o on vdd.
ho:
AUXIO
HIGH 14
HIGH 10
HIGH 8
HIGH 9
RETURN
' Sets segments of display for the letter o on vss.
lo:
AUXIO
LOW 14
LOW 10
LOW 8
LOW 9
RETURN
' Sets segments of display for the letter g on vdd.
hg:
MAINIO
HIGH 6
HIGH 7
AUXIO
HIGH 14
HIGH 11
HIGH 8
HIGH 9
RETURN
' Sets segments of diplay for the letter g on vss.
lg:
MAINIO
LOW 6
LOW 7
AUXIO
LOW 14
LOW 11
LOW 8
LOW 9
RETURN
Pics;
http://i15.photobucket.com/albums/a371/MINGMAY/Image013.jpg
http://i15.photobucket.com/albums/a371/MINGMAY/Image014-1.jpg
http://i15.photobucket.com/albums/a371/MINGMAY/Image005.jpg
http://i15.photobucket.com/albums/a371/MINGMAY/Image020.jpg
Post Edited (latigerlilly) : 2/5/2007 4:13:19 PM GMT