- Joined
- Feb 9, 2013
- Messages
- 424
Hi Guys,
I'm trying to write a program which will record the pressed keys on the keypad, after the person hits enter from an external standard push button.
As the user presses buttons, the numbers get written on an LCD display one by one.
This works nicely, but I now need to record all the digits pressed.. and store them into one variable. I'm finding this very difficult..
heres the code so far (without recording anything, just writing the digits to LCD):
I'm trying to write a program which will record the pressed keys on the keypad, after the person hits enter from an external standard push button.
As the user presses buttons, the numbers get written on an LCD display one by one.
This works nicely, but I now need to record all the digits pressed.. and store them into one variable. I'm finding this very difficult..
heres the code so far (without recording anything, just writing the digits to LCD):
Code:
unsigned char i = 0; //Variable for LCD char position
unsigned char value;
Increment ()
{
if (i<19)
{
i = i++;
}
}
Keypad_init()
{
TRISD = 0b00000000; //Keypad Rows set as inputs
TRISCbits.TRISC5 = 1;
TRISCbits.TRISC6 = 1; //Keypad Columns set as outputs
TRISCbits.TRISC7 = 1;
}
Keypad_scan()
{
PORTD=0b10000000;
__delay_us(1);
if (RC7==1 && RC6==0 && RC5==0) { //#
i = 0;
LCD_cmd(LCD_LINE4); //* Clear all
LCD_string(" ");
__delay_ms(250);
}
if (RC7==0 && RC6==1 && RC5==0) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00110000); //0
Increment();
__delay_ms(250);
}
if (RC7==0 && RC6==0 && RC5==1) {
i = 0;
LCD_cmd(LCD_LINE4); //* Clear all
LCD_string(" ");
__delay_ms(250);
}
PORTD=0b01000000;
__delay_us(1);
if (RC7==1 && RC6==0 && RC5==0) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00111001); //9
Increment();
__delay_ms(250);
}
if (RC7==0 && RC6==1 && RC5==0) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00111000); //8
Increment();
__delay_ms(250);
}
if (RC7==0 && RC6==0 && RC5==1) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00110111); //7
Increment();
__delay_ms(250);
}
PORTD=0b00100000;
__delay_us(1);
if (RC7==1 && RC6==0 && RC5==0) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00110110); //6
Increment();
__delay_ms(250);
}
if (RC7==0 && RC6==1 && RC5==0) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00110101); //5
Increment();
__delay_ms(250);
}
if (RC7==0 && RC6==0 && RC5==1) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00110100); //4
Increment();
__delay_ms(250);
}
PORTD=0b00010000;
__delay_us(1);
if (RC7==1 && RC6==0 && RC5==0) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00110011); //Write 3
Increment();
__delay_ms(250);
}
if (RC7==0 && RC6==1 && RC5==0) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00110010); //Write 2 to LCD
Increment();
__delay_ms(250);
}
if (RC7==0 && RC6==0 && RC5==1) {
LCD_cmd(LCD_LINE4 + i);
LCD_data(0b00110001); //Write 1 to LCD
Increment();
__delay_ms(250);
}
}