Kód: Egész kijelölése
$regfile = "m32def.dat"
$crystal = 11059200
$baud = 115200
$hwstack=40
$swstack = 16
$framesize = 32
$lib "LUC_lcd4busy_timeout.lbx" 'Luciano's fast LCD lib
Config Lcd = 16x2
'Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portd.7 , Rs = Portd.6
'#######################Lucaiano's LCD LIB konstansok###########################
Const _lcddb4_portx = Portc 'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
Const _lcddb4_ddrx = Ddrc 'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
Const _lcddb4_pinnumber = 2 'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.
Const _lcddb5_portx = Portc 'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
Const _lcddb5_ddrx = Ddrc 'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
Const _lcddb5_pinnumber = 3 'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.
Const _lcddb6_portx = Portc 'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
Const _lcddb6_ddrx = Ddrc 'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
Const _lcddb6_pinnumber = 4 'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.
Const _lcddb7_portx = Portc 'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
Const _lcddb7_ddrx = Ddrc 'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
Const _lcddb7_pinx = Pinc 'Valid values: PINA, PINB, PINC, PIND, PINE.
Const _lcddb7_pinnumber = 5 'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.
Const _lcde_portx = Portd 'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
Const _lcde_ddrx = Ddrd 'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
Const _lcde_pinnumber = 7 'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.
Const _lcdrw_portx = Portc 'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
Const _lcdrw_ddrx = Ddrc 'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
Const _lcdrw_pinnumber = 6 'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.
Const _lcdrs_portx = Portd 'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
Const _lcdrs_ddrx = Ddrd 'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
Const _lcdrs_pinnumber = 6 'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.
'###############################################################################
Const Debouncetime = 150
Config Pind.5 = Output 'LED kimenet
Config Pind.2 = Input 'Megszakitás bemenet
Config Int0 = Falling 'Megszaktiás beállítása
Dim Keycoderow As Byte 'Gomb sor kód
Dim Keycodecol As Byte 'Gomb oszlop kód
Dim Keycode As Byte 'Gomb kód
Dim Keychar As String * 1 'Gomb érték (táblázatból)
On Int0 Button 'Megszakításkor a Button rutint hívja meg
'billentyűzet beállítása
Ddra = &B11110000
Porta = &B00001111
Cursor Off
Cls
Lcd "ready..."
Enable Interrupts
Enable Int0
Wait 1
Cls
Keychar = ""
Do
Set Portd.5
Waitms 250
Reset Portd.5
Waitms 250
If Keychar <> "" Or Keychar <> "?" Then
Locate 2 , 6 : Lcd Keychar
Keychar = ""
End If
Loop
Button:
Waitms Debouncetime
'read portb pins to determine which row is zero
Keycoderow = Pina
'set portb upper nibble to input, lower to output
Ddra = &B00001111
Porta = &B11110000
'give port time to settle
Waitms 1
'read portb pins to determine which col is zero
Keycodecol = Pina
'set portb back to original state
Ddra = &B11110000
Porta = &B00001111
'make keycode from portb pins read
Select Case Keycoderow
Case 7 : Keycode = 0
Case 11 : Keycode = 4
Case 13 : Keycode = 8
Case 14 : Keycode = 12
Case Else : Keycode = 99
End Select
'shift upper nibble to lower nibble
Shift Keycodecol , Right , 4
'make final keycode from portb pins read
Select Case Keycodecol
Case 7 : Keycode = Keycode + 0
Case 11 : Keycode = Keycode + 1
Case 13 : Keycode = Keycode + 2
Case 14 : Keycode = Keycode + 3
Case Else : Keycode = Keycode + 99
End Select
'illegal keycode from bounce effects
If Keycode > 15 Then Keycode = 16
Keychar = Lookupstr(keycode , Keycodes)
Gifr = 64
Return
End 'end program
Keycodes:
Data "1" , "4" , "7" , "E" , "2" , "5" , "8" , "0" ,
Data "3" , "6" , "9" , "R" , "A" , "B" , "C" , "D" , "?"
Ha ezt futtatom akkor is néha kijön a kérdőjel az LCD-re.