我通过bascome avr和proteus设计了一个计算器,但键盘中的某些数字无法正常工作。只有1,4和7工作得很好。图2和图3显示1,5和6显示4,8和9显示7!问题出在哪里?
我的基本代码:
$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