搜索
bottom↓
回复: 4

为什么4*4键盘的getkbd()的在bascom仿真时按键不起作用,返回值总是15?【恢复】

[复制链接]

出0入0汤圆

发表于 2009-1-7 13:07:00 | 显示全部楼层 |阅读模式
马老师,请问为什么4*4键盘的getkbd()的在bascom仿真时按键不起作用,返回值总是15?我使用的版本是1.11.9.1,即使是help中的例子也一样。

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

 楼主| 发表于 2009-1-7 14:46:20 | 显示全部楼层
我准备给初中生开设单片机课程,需要使用bascom,否则小孩子学不懂啊。

出0入0汤圆

发表于 2009-1-7 14:05:10 | 显示全部楼层
你是玩玩的,还是准备踏踏实实的学门技术,如果是后者的话,建议你学习使用C语言的开发平台。

出0入0汤圆

 楼主| 发表于 2009-1-7 13:09:13 | 显示全部楼层
源程序:

$regfile = "m48def.dat"

$crystal = 4000000

Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portc.3 , Rs = Portc.2

Config Lcd = 20 * 2

$hwstack = 32

$swstack = 10

$framesize = 40

Config Kbd = Portd 



Dim D As Byte



Do

D = Getkbd()



Cls

Waitms 50

Lcd D

Waitms 50



Loop

End

出0入0汤圆

发表于 2009-12-28 22:12:12 | 显示全部楼层
I found some useful matairl in http://www.dontronics.com/basc-avrcf.html.It should resovle your problem.

From:        Ian Thomson

I have been having a rotten job of simulating a 16 button keypad in Bascom Avr... Just couldn't seen to be able to get a value into the variable assigned to  the getkbd() function. After a lot of brain busting I think I have the problem solved. So for those that are having the same problem I present my solution for your general use.(See text below)

Simulating a keypad in the Bascom Avr Simulator .............

Before running your code in the simulator Turn ON all of the Inputs Under Hardware Simulation for the port that the keyboard is attached to. ( All of the green Led's ) This mimics a keyboard with no keys pressed.

When no key press is simulated then the variable assigned to the getkbd() in Bascom will have a value of 16...  To simulate a key press You will need to pause simulation and use step by step for the key press simulation to work.

To simulate a key press,  Turn Off  the inputs on the port pins for the value required... then step through your code until the value is passed into the getkbd() variable.   ( You can watch the variable under the variables Tab to make sure it has worked. ) Then Turn both of the inputs Back On to simulate the key being released.

Port -> 7       6       5       4       3       2       1       0       Value Returned
Pins
                                     |                                  Dec     Hex
                                     |
No ---> on      on      on      on   |  on      on      on      on      16      10
Key     on      on      on      off  |  on      on      on      off     0       0
Pressed on      on      on      off  |  on      on      off     on      1       1
        on      on      on      off  |  on      off     on      on      2       2
        on      on      on      off  |  off     on      on      on      3       3
        on      on      off     on   |  on      on      on      off     4       4
        on      on      off     on   |  on      on      off     on      5       5
        on      on      off     on   |  on      off     on      on      6       6
        on      on      off     on   |  off     on      on      on      7       7
        on      off     on      on   |  on      on      on      off     8       8
        on      off     on      on   |  on      on      off     on      9       9
        on      off     on      on   |  on      off     on      on      10      A
        on      off     on      on   |  off     on      on      on      11      B
        off     on      on      on   |  on      on      on      off     12      C
        off     on      on      on   |  on      on      off     on      13      D
        off     on      on      on   |  on      off     on      on      14      E
        off     on      on      on   |  off     on      on      on      15      F
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-23 04:26

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表