lcd menu pic
trying to build a menu with Pic16f628, lcd and four push buttons (up, down, enter, cancel)
May try doing the job by module basis in C programming language.
First, LCD module and secondly, keypad module. There will be API functions associated with these modules for basic functions like:
lcd_init(void) //LCD initialization
lcd_defchar(void) //define a custom character like the little arrow
lcd_gotoxy(x,y) //instruct the LCD cursor going to any position x,y
lcd_putc(c) //print a character at any designated position
For keypad, API functions can be:
keyInit() //initialize the keypad module, like config mcu I/O direction etc.
keyHit() //return TRUE/FALSE for any key press action
keyGetKey() //return the key code of that key press
So, the main program may look like this:
void main(void)
{
keyInit(); //Initialize the keypad
lcd_init(); //Initialize LCD for a 4x20 configuration
lcd_defchar(); //Custom define all characters for the static screen
//plus any initialization code you need
while(1) //endless loop
{
WaitKey();
UpdateLCD();
}
}
/*************************Functions**************************/
WaitKey(){
unsigned char kchar, i;
if(KeyHit()){ //detect a key press here
kchar = KeyGetKey(); //decode the key
switch(kchar){
case UP:
case DOWN:
case RIGHT:
case LEFT:
}
}
}
UpdateLCD()
{
.....
}
The UP side of this method is that, you can test each module independently, and easy for debug. The down side is, it takes more code space comparing to asm programming.
I have worked through this method with several systems for my client in the past. All devices worked in the field for several years without the need for local service.
Hope it helps.
John Leung
ARM boards, 8051 boards, PIC board, MSP boards @
www.TechToys.com.hk