键盘不巴斯科姆的AVR程序和变形杆菌正常工作(keypad don't work corre

2019-10-20 09:04发布

我设计过bascome AVR和变形杆菌计算器,但在键盘的一些数字不正常工作。 只是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

Answer 1:

尝试组装这样,使用端口B针对键盘和470欧姆电阻... 看到该图片



文章来源: keypad don't work correctly in bascom avr program and proteus
标签: avr