w________1 发表于 2009-1-7 13:07:00

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

马老师,请问为什么4*4键盘的getkbd()的在bascom仿真时按键不起作用,返回值总是15?我使用的版本是1.11.9.1,即使是help中的例子也一样。

w________1 发表于 2009-1-7 14:46:20

我准备给初中生开设单片机课程,需要使用bascom,否则小孩子学不懂啊。

machao 发表于 2009-1-7 14:05:10

你是玩玩的,还是准备踏踏实实的学门技术,如果是后者的话,建议你学习使用C语言的开发平台。

w________1 发表于 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

fumingf 发表于 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 tothe 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 Offthe 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
页: [1]
查看完整版本: 为什么4*4键盘的getkbd()的在bascom仿真时按键不起作用,返回值总是15?【恢复】