Datasheet
Library Example
This is a simple example of using the Keypad Library. It supports keypads with 1..4
rows and 1..4 columns. The code being returned by Keypad_Key_Click() function is
in range from 1..16. In this example, the code returned is transformed into ASCII
codes [0..9,A..F] and displayed on Lcd. In addition, a small single-byte counter dis-
plays in the second Lcd row number of key presses.
program Keypad_Test
dim kp, cnt, oldstate as byte
txt as byte[7]
' Keypad module connections
dim keypadPort as byte at PORTB
dim keypadPort_Direction as byte at DDRB
' End Keypad module connections
' Lcd pinout definition
dim LCD_RS as sbit at PORTD.2
LCD_EN as sbit at PORTD.3
LCD_D4 as sbit at PORTD.4
LCD_D5 as sbit at PORTD.5
LCD_D6 as sbit at PORTD.6
LCD_D7 as sbit at PORTD.7
dim LCD_RS_Direction as sbit at DDRD.2
LCD_EN_Direction as sbit at DDRD.3
LCD_D4_Direction as sbit at DDRD.4
LCD_D5_Direction as sbit at DDRD.5
LCD_D6_Direction as sbit at DDRD.6
LCD_D7_Direction as sbit at DDRD.7
' end Lcd pinout definitions
main:
oldstate = 0
cnt = 0 ' Reset counter
Keypad_Init() ' Initialize Keypad
Lcd_Init() ' Initialize Lcd
Lcd_Cmd(LCD_CLEAR) ' Clear display
Lcd_Cmd(LCD_CURSOR_OFF) ' Cursor off
Lcd_Out(1, 1, "Key :") ' Write message text on
LCD
Lcd_Out(2, 1, "Times:")
while TRUE
kp = 0 ' Reset key code variable
236
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6