PDA

View Full Version : Cash dispenser



tigerflow
- 2nd June 2009, 10:20
I want the program to write "peddobears says:" "cash flow" when the code "5354" is writen out on the display, but it doesn't work. Instead it just keeps going (You can keep writing numbers even if you have written 5354 out on the display). Someone who knows what is wrong?

define loader_used 1
' Define LCD connections
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
' Define program variables
col VAR BYTE ' Kolumn
row VAR BYTE ' Rad
key VAR BYTE ' Tangent
code var byte
'
OPTION_REG.7 = 0 ' Enable PORTB pullups
TRISB = %11110000
ADCON1 = 7 ' Make PORTA and PORTE digital
Low PORTE.2 ' LCD R/W low (write)
Pause 500 ' Wait for LCD to start
LCDOut $FE, 1

'
loop: gosub key_encode ' Avkoda tangent
if key = $FF then loop ' Tillbaka om ingen är nedtryckt
iF KEY < 9999 THEN ' Kolla om siffra tryckts
code = KEY
LCDOut $FE,$0f, #key ' "fisk" och skriv tangent
ENDIF
IF key = $20 THEN ' Kolla om A tryckts = lagra
WRITE 0, code ' Lagra adval i EEPROM adress 0
LCDOut $FE, 1, "Save ", #code ' Skriv meddelande
ENDIF
IF key = $21 THEN ' Kolla om B tryckts = läsa
READ 0, code ' Läser från EEPROM adress 0 till code
LCDOut $FE, 1, "Read ", #code ' Skriv meddelande
ENDIF
if code = 5453 then
goto loop2
ENDIF

loop1: gosub key_encode ' Avkoda tangent
IF key <> $FF then loop1 ' Vänta tills ej tryckt
GoTo loop ' Tillbaka

loop2:
PAUSE 800
LCDOUT $FE,1, "PeddoBear Says:"
LCDOUT $Fe,$C0, "Cashfhlow <3"

Pause 1000
goto loop

key_encode:
pause 50
key = 0
PORTB = %11111110 ' kolla rad 1
if PORTB = %11111110 then key_1
row = 1
goto pressed
key_1: PORTB = %11111101 ' kolla rad 2
if PORTB = %11111101 then key_2
row = 2
goto pressed
key_2: PORTB = %11111011 ' kolla rad 3
if PORTB = %11111011 then key_3
row = 3
goto pressed
key_3: PORTB = %11110111 ' kolla rad 4
if PORTB = %11110111 then no_key
row = 4
goto pressed
no_key: key = $FF
return
pressed:
key = PORTB & %11110000
if key = %01110000 then col = 4
if key = %10110000 then col = 3
if key = %11010000 then col = 2
if key = %11100000 then col = 1
key = col + ((row - 1) * 4)
SELECT case key
CASE 1
key = 1
CASE 2
key = 2
CASE 3
key = 3
CASE 4
key = $20 ' Tangent A = lagra
CASE 5
key = 4
CASE 6
key = 5
CASE 7
key = 6
CASE 8
key = $21 ' Tangent B = läsa
CASE 9
key = 7
CASE 10
key = 8
CASE 11
key = 9
CASE 12
key = $FF ' Ej använd
CASE 13
key = $FF ' Ej använd
CASE 14
key = 0
CASE 15
key = $FF ' Ej använd
CASE 16
key = $FF ' Ej använd
END SELECT
return
end

aratti
- 2nd June 2009, 10:40
Welcome to the forum.

Your variable "code" has been declared as byte, so max nunber it could contains is 255. Declare variable code as Word and adjust your source code accordingly.


Al.