mikrobasic keypad
Hi I'm also newbie in PIC but I already try keypad and LCD once but for bluetooth not yet. I use MikroBasic V7.2 from MikroElektronika. i Attached the sample program. Just Checked. ( I Use PIC 16f877A).
LCD Connection :
Port b :
R/W = Gnd
E = pb.3
rs = pb.2
data = pb.4 - pb.7
Keypad Connection :
Row 1-4 = PC.0 - PC.3
Col 1-4 = PC.4 - PC.7
;=================================================
program new_lcd_keypad_done
dim kp, curX, curY as byte
main:
curX=1
curY=1 ' For keeping record of the 2x16 LCD cursor position
Keypad_Init(PORTD) ' Initialize Keypad on PORTC
Lcd_Init(PORTB) '
Lcd_Cmd(LCD_CLEAR) ' Clear display
while true
kp = 0
' Wait for key to be pressed and released
while kp = 0
kp = Keypad_Released()
Delay_ms(10)
wend
' Prepare value for output
select case kp
case 1 kp = "1"
case 2 kp = "2"
case 3 kp = "3"
case 4 kp = "A"
case 5 kp = "4"
case 6 kp = "5"
case 7 kp = "6"
case 8 kp = "B"
case 9 kp = "7"
case 10 kp = "8"
case 11 kp = "9"
case 12 kp = "C"
case 13 kp = "*"
case 14 kp = "0"
case 15 kp = "#"
case 16 kp = "D"
end select
if (curY > 16) then ' change cursor position
if (curX = 1) then
Lcd_Cmd(LCD_SECOND_ROW)
curX = 2
curY = 1
else
Lcd_Cmd(LCD_FIRST_ROW)
curX = 1
curY = 1
end if
end if
' Print on LCD
Lcd_Chr_CP(kp)
Inc(curY)
wend
end.
;==================================================