I am learning how to program a pic18f4550 and trying to connect it to an lcd screen and a keypad. I was able to print the first hello world on the screen. the button press wqs not working. here is my code written in mikrobasic qs I am using mikrobasic to write my program and the PIC K150 to program the 18f4550 chip.
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
the LCD Screen is working but the buttons are not.