|
:: مهندس ::
تاريخ التسجيل: Feb 2007
المشاركات: 48
|
|
نشاط [ العابدي ]
قوة السمعة:
|
|
06-08-2009, 11:33 PM
المشاركة 2
|
|
يمكن ملاحظة الكود التالي:
Device = 16F877A
XTAL = 4
Declare LCD_TYPE 0
Declare LCD_DTPIN PORTD.4
Declare LCD_ENPIN PORTD.3
Declare LCD_INTERFACE 4
Declare LCD_RSPIN PORTD.2
DECLARE KEYPAD_PORT PORTB
' Define program variables
Dim Col as Byte ' Keypad column
Dim Row as Byte ' Keypad row
Dim Key as Byte ' Key value
Delayms 100 ' Wait for LCD to start
' Enable PORTB pullups
ALL_DIGITAL = True ' Set ports to digital mode
Print Cls, "Press any key" ' Display sign on message
Loop: Gosub Getkey ' Get a key from the keypad
Print Cls, #Key ' Display ASCII key number
Goto Loop ' Do it forever
' Subroutine to get a key from keypad
Getkey:
Delayms 50 ' Debounce
Getkeyu:
' Wait for all keys up
PORTb = 0 ' All output pins low
TRISb = $F0 ' Bottom 4 pins out, top 4 pins in
If (PORTb >> 4) <> $0F Then Getkeyu ' If any keys down, loop
Delayms 50 ' Debounce
Getkeyp:
' Wait for keypress
For Col = 0 to 3 ' 4 columns in keypad
PORTb = 0 ' All output pins low
TRISb = (Dcd Col) ^ $FF ' Set one column pin to output
Row = PORTb >> 4 ' Read row
If Row <> $0F Then Gotkey ' If any keydown, exit
Next
Goto Getkeyp ' No keys down, go look again
Gotkey: ' Change row and column to key number 1 - 16
Key = (Col * 4) + (Ncd (Row ^ $0F))
Return ' Subroutine over
Label:
End
|