问题
I have designed a calculator through bascome avr and proteus, but some numbers in keypad dont work correctly. just 1 , 4 and 7 work nice. 2 and 3 show 1, 5 and 6 show 4, 8 and 9 show 7! where is the problem?
My bascom code:
$regfile = "M32DEF.DAT"
$crystal = 8000000
Config Kbd = Portd
Config Lcdpin = Pin , Db4 = Pinb.4 , Db5 = Pinb.5 , Db6 = Pinb.6 , Db7 = _ Pinb.7 , Rs = Pinb.2 , E = Pinb.3
Config Lcd = 20 * 2
Dim A As Single
Dim B As Single
Dim S As Byte
Dim Yab As Single
Dim X As Byte
Dim Y As Byte
Star:
A = 0
S = 0
B = 0
Cls
Do
Start1:
X = Getkbd()
If X >= 16 Then Goto Start1
X = Lookup(x , Key)
If X = 47 Or X = 42 Or X = 45 Or X = 13 Or X = 61 Or X = 43 Then Exit Do
If S > 5 Then Goto Start1
A = A * 10
A = A + X
Locate 1 , 1
Lcd A
Waitms 100
Incr S
Loop
Cls
If X = 13 Then Goto Star
Y = X
S = 0
Locate 1 , 1
Lcd A ; Chr(y)
Waitms 100
Do
Start2:
X = Getkbd()
If X >= 16 Then Goto Start2
X = Lookup(X , Key)
If X = 47 Or X = 42 Or X = 45 Or X = 13 Or X = 61 Or X = 43 Then Exit Do
If S > 5 Then Goto Start2
B = B * 10
B = B + X
Locate 1 , 1
Lcd A ; Chr(y) ; B
Waitms 100
Incr S
Loop
If X = 13 Then Goto Star
S = 0
Locate 1 , 1
Lcd A ; Chr(Y) ; B
Waitms 100
Select Case Y
Case 47 : Yab = A / B
Case 42 : Yab = A * B
Case 45 : Yab = A - B
Case 43 : Yab = A + B
End Select
Locate 2 , 1
Lcd " ="
Locate 2 , 2
Lcd Yab
A = Yab
S = 6
B = 0
Goto Start1
End
Key:
Data 7 , 8 , 9 , 47 , 4 , 5 , 6 , 42 , 1 , 2 , 3 , 45 , 13 , 0 , 61 , 43
回答1:
Try to assemble like this, Use portB for keypad and, 470 ohms resistor ... See this Image
来源:https://stackoverflow.com/questions/24558232/keypad-dont-work-correctly-in-bascom-avr-program-and-proteus