键盘在bascom avr程序和proteus中无法正常工作 [英] keypad don't work correctly in bascom avr program and proteus

查看:144
本文介绍了键盘在bascom avr程序和proteus中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过bascome avr和proteus设计了一个计算器,但是键盘上的某些数字无法正常工作.只有1,4和7可以很好地工作. 2和3显示1,5和6显示4,8和9显示7!问题出在哪里?

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?

我的bascom代码:

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

推荐答案

尝试像这样组装,将portB用于键盘和470欧姆电阻器... 查看此图片

Try to assemble like this, Use portB for keypad and, 470 ohms resistor ... See this Image

这篇关于键盘在bascom avr程序和proteus中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆