按下按钮时,PIC18f4550 上的键盘不工作

Keypad on PIC18f4550 not working when I press a button

提问人:ace 提问时间:6/21/2023 最后编辑:Kozmotronikace 更新时间:7/12/2023 访问量:25

问:

我正在学习如何对 pic18f4550 进行编程,并尝试将其连接到 lcd 屏幕和键盘。我能够在屏幕上打印出第一个hello world。按钮按 WQS 不起作用。 这是我用 mikrobasic qs 编写的代码,我使用 mikrobasic 编写程序,使用 PIC K150 对 18f4550 芯片进行编程。

program Keypad_Test
dim kp as byte
dim GLCD_DataPort as byte at PORTd


dim GLCD_CS1 as sbit at LATa0_bit
    GLCD_CS2 as sbit at LATa1_bit
    GLCD_RS  as sbit at LATa2_bit
    GLCD_RW  as sbit at LATa3_bit
    GLCD_EN  as sbit at LATa4_bit
    GLCD_RST as sbit at LATa5_bit

dim GLCD_CS1_Direction as sbit at TRISa0_bit
    GLCD_CS2_Direction as sbit at TRISa1_bit
    GLCD_RS_Direction  as sbit at TRISa2_bit
    GLCD_RW_Direction  as sbit at TRISa3_bit
    GLCD_EN_Direction  as sbit at TRISa4_bit
    GLCD_RST_Direction as sbit at TRISa5_bit

 dim keypadPort as byte at PORTb
 

Sub Procedure cmd3
 kp = 0
    while ( kp = 0 )
    kp = Keypad_Key_Click()
    wend
    select case kp
    case 1       kp = 49  Sound_Play(1000, 50)' 1
    case 2       kp = 50  Sound_Play(1000, 50)' 2
    case 3       kp = 51  Sound_Play(1000, 50)' 3
    case 4       kp = 65  Sound_Play(1000, 50)' A
    case 5       kp = 52  Sound_Play(1000, 50)' 4
    case 6       kp = 53  Sound_Play(1000, 50)' 5
    case 7       kp = 54  Sound_Play(1000, 50)' 6
    case 8       kp = 66  Sound_Play(1000, 50)' B
    case 9       kp = 55  Sound_Play(1000, 50)' 7
    case 10      kp = 56  Sound_Play(1000, 50)' 8
    case 11      kp = 57  Sound_Play(1000, 50)' 9
    case 12      kp = 67  Sound_Play(1000, 50)' C
    case 13      kp = 87  Sound_Play(1000, 50)' W
    case 14      kp = 48  Sound_Play(1000, 50)' 0
    case 15      kp = 71  Sound_Play(1000, 50)' G
    case 16      kp = 68  Sound_Play(1000, 50)' D
    end select

 End sub

main:

  Keypad_Init()

  Glcd_Init() Glcd_Fill(0x00)


  Glcd_Write_text("Hello World", 15,7,0)
  label1:
   CMD3
   if kp=68 then Glcd_Fill(0x00)
    Glcd_Write_text("Button Pressed!", 50,0,2)
    else goto label1
   end if
end

LCD 屏幕工作正常,但按钮不工作。

基本 图18

评论

0赞 Kozmotronik 7/10/2023
你试过所有键吗?

答: 暂无答案