unexpert
Joined: 05 Feb 2010 Posts: 2
|
LCD Menu integration with 4x4 keypad (c programming) |
Posted: Fri Feb 05, 2010 2:00 pm |
|
|
Hi,
I've been working on a project using MPLAB IDE v8.36.
I'm trying to make a menu using the keypad for eg,
1 pressed - measure heart rate
2 pressed - exit
We can't get the output when we press the allocated key.
Here is our program code below:
Code: |
#include <p18f4520.h>
#include <delays.h>
unsigned int LCD(void);
unsigned int EXIT(void);
void Init_LCD(void);
void w_ctr_8bit(char);
void w_data_8bit(char);
void Delay_1kcyc(void);
#define LCD_DATA PORTD
#define LCD_RS PORTBbits.RB1
#define LCD_E PORTBbits.RB2
unsigned char LCD_TEMP, i,j,k,m;
char MESS[16]=" WELCOME TO ECG ";
char MESS2[16]="1.MEASURE 2.EXIT";
void main()
{
unsigned int x, y, value;
ADCON1=0x0F;
TRISA=0xFF;
TRISB=0;
TRISD=0;
y=value;
PORTD=1;
Init_LCD();
w_ctr_8bit(0b10000000);
for (i=0; i<16; i++)
w_data_8bit(MESS[i]);
w_ctr_8bit(0b11000000);
for (i=0; i<16; i++)
w_data_8bit(MESS2[i]);
LCD();
while(1)
{ if (value==0b00000001)
for(i=0;i<16;i++)
{
unsigned int EXIT();
}
}
}
unsigned int LCD(void)
{
char value, keyInputs;
while(PORTAbits.RA4==0);
keyInputs = PORTA & 0x0F;
switch(keyInputs)
{
case 0: value='1';w_data_8bit(value);break;
case 1: value='2';w_data_8bit(value);break;
case 2: value='3';w_data_8bit(value);break;
case 3: value='F';w_data_8bit(value);break;
case 4: value='4';w_data_8bit(value);break;
case 5: value='5';w_data_8bit(value);break;
case 6: value='6';w_data_8bit(value);break;
case 7: value='E';w_data_8bit(value);break;
case 8: value='7';w_data_8bit(value);break;
case 9: value='8';w_data_8bit(value);break;
case 10: value='9';w_data_8bit(value);break;
case 11: value='D';w_data_8bit(value);break;
case 12: value='A';w_data_8bit(value);break;
case 13: value='0';w_data_8bit(value);break;
case 14: value='B';w_data_8bit(value);break;
case 15: value='C';w_data_8bit(value);break;
}
Delay10KTCYx(50);
return(value);
}
void Init_LCD()
{
w_ctr_8bit(0b00111000);
w_ctr_8bit(0b00001100);
w_ctr_8bit(0b00000110);
w_ctr_8bit(0b00000001);
w_ctr_8bit(0b00000010);
w_ctr_8bit(0b10000010);
}
void w_ctr_8bit(char w)
{
LCD_RS = 0;
LCD_E = 1;
LCD_DATA = w;
LCD_E = 0;
Delay10TCYx(50);
}
void w_data_8bit(char w)
{
LCD_RS = 1;
LCD_E = 1;
LCD_DATA = w;
LCD_E = 0;
Delay10TCYx(50);
}
unsigned int EXIT(void)
{
char MESS3[16]="THANK YOU FOR";
char MESS4[16]="USING ECG, BYE!";
w_ctr_8bit(0b10000000);
for (i=0; i<16; i++)
w_data_8bit(MESS3[i]);
w_ctr_8bit(0b11000000);
for (i=0; i<16; i++)
w_data_8bit(MESS4[i]);
}
|
We would appreciate help. Thanks .. |
|