PDA

View Full Version : keypad



jonas2
- 6th March 2006, 11:04
Hello I have a small problem with this program, the data to send to the PC Are illegible, and for my beginning it is not obvious. If you can help me, I thank you.

jonas2
- 7th March 2006, 09:21
'************************************************* *****************************
Include "modedefs.bas"

DEFINE OSC 20 ' Oscillator speed in MHz:


'************************************************* ******************************
OPTION_REG.7 = 0 ' Enable pullups on PortB
TRISA=%00000000 ' make all port outputs initially
PORTA=%00000000

TRISB=%00000000
PORTB=%00000000

CMCON = %00000111
VRCON = %00000000

T1CON = %00110001



'************************************************* ********************************

'VARIABLES

datac VAR BYTE
Key VAR BYTE
'************************************************* *********************************
Start_loop:

'------------------------------PORTB 0 -----------------------------------------
TRISB=%1110
PORTB=%0000
IF PORTB = %0010 THEN'----------------------------CHIFFRE 1-----------------
Key = "1" : GOTO Exit_loop
ELSE

IF PORTB = %1000 THEN'------------------------CHIFFRE 2-----------------
Key= "2" : GOTO Exit_loop
ELSE

IF PORTB = %0100 THEN'--------------------CHIFFRE 3-----------------
Key = "3" : GOTO Exit_loop
ENDIF
ENDIF
ENDIF
'------------------------------PORTB 1------------------------------------------
TRISB=%1101
PORTB=%0000
IF PORTB = %0001 THEN'----------------------------CHIFFRE 4----------------
Key= "4" : GOTO Exit_loop
ELSE
IF PORTB = %1001 THEN'-------------------------CHIFFRE 5----------------
Key= "5" : GOTO Exit_loop
ELSE
IF PORTB=%0101 THEN'-----------------------CHIFFRE 6----------------
Key = "6" : GOTO Exit_loop
ENDIF
ENDIF
ENDIF
'------------------------------PORTB 2------------------------------------------
TRISB=%1011
PORTB=%0000
IF PORTB=%0011 THEN'------------------------------CHIFFRE 7----------------
Key= "7" : GOTO Exit_loop
ELSE
IF PORTB=%1001 THEN'-------------------------CHIFFRE 8-----------------
Key= "8" : GOTO Exit_loop
ELSE
IF PORTB=%0001 THEN'-----------------------CHIFFRE 9----------------
Key = "9" : GOTO Exit_loop
ENDIF
ENDIF
ENDIF
'--------------------------------PORTB 3----------------------------------------
TRISB=%0111
PORTB=%0000
IF PORTB=%0011 THEN'------------------------------ " * "-------------------
Key= "*" : GOTO Exit_loop
ELSE
IF PORTB=%0001 THEN'---------------------------CHIFFRE 0----------------
Key= "0" : GOTO Exit_loop
ELSE
IF PORTB=%0101 THEN'----------------------- " # " -----------------
Key = "#" : GOTO Exit_loop
ENDIF
ENDIF
ENDIF
'-------------------------------------------------------------------------------

goto Start_loop ' didn't find nothin

Exit_loop:
datac = KEY
SEROUT2 PORTA.3,84,[KEY]
LOOKUP2 datac,[17,33,65,18,34,66,19,35,67,20,36,68],KEY

GOTO Start_loop
' LookDown combined,[87,110,94,62,109,93,61,107,91,59,103,55,127],Keyindex ' 0,1,2,3...
' LookUp Keyindex,["0","1","2","3","4","5","6","7","8","9","*","#"," "],Key ' ascii