LCD Menu integration with keypad

Discussion in 'Embedded Systems and Microcontrollers' started by unexpert, Feb 5, 2010.

  1. unexpert

    Thread Starter New Member

    Feb 5, 2010
    1
    0
    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

    Here is our programme code below:

    #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);

    w_ctr_8bit(0b11000000);
    for (i=0; i<16; i++)
    w_data_8bit(MESS2);

    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);

    w_ctr_8bit(0b11000000);
    for (i=0; i<16; i++)
    w_data_8bit(MESS4);
    }
     
Loading...