Maker Pro
Maker Pro

Need help storing keypad input - Hi-Tech C

Sadlercomfort

Ash
Feb 9, 2013
424
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):


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

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Hi Ash. Where do you want to store the values? What micro are you using?
Adam
 

Sadlercomfort

Ash
Feb 9, 2013
424
Joined
Feb 9, 2013
Messages
424
Hi Adam,

PIC16F877A

The above code is in a header file where the Keypad_scan() function is called from the main program. I would like the above program to combine each pressed key, into one value, then maybe return it. I will probably store this in the eeprom.

The person can write up too 20 characters, which is probably too much.. so I will be reducing this to 4.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Hi Ash
have you had a look on the MC website. They have lots of apps. If not I can send you some code from a kindle book I have but might not be until Monday. I am on my tablet and not sure if I can copy text. Let me see if I can.
Adam
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Just tried and I cant copy easily from my tablet. I will try from my PC latér.
Adam
 

Sadlercomfort

Ash
Feb 9, 2013
424
Joined
Feb 9, 2013
Messages
424
Okay, thanks.

What does the microchip website have? Don't think I've ever used there resources.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Why dont you have a look :) I think you will find it interesting.
Adam
 

Sadlercomfort

Ash
Feb 9, 2013
424
Joined
Feb 9, 2013
Messages
424
Thanks, Hi-tech C has a "eeprom_routines.h" file which can be used quite easily, similar to what you have shown. I haven't attempted the eeprom yet.

I'm now having even more issues with my microcontroller, which goes into unexpected reset.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
If you want a hand to sort the reset problem out. Post your circuit here and explain in detail what's happening and when.
Cheers
Adam
 

Sadlercomfort

Ash
Feb 9, 2013
424
Joined
Feb 9, 2013
Messages
424
I seem to have fixed the reset problem, I checked everything from the master clear circuit to the decoupling capacitors but everything was fine.

I'm guessing it was something to do with my interrupt routines, causing a reset.

I decided not to use my keypad, It's just to difficult to display the typed characters.. record each typed character and concatenate them together. I'm using a rotary encoder instead.. much easier to record a value since its a single variable thats incremented or decremented depending on the rotation.


P.S Learnt the word concatenate today and just had to use it!
 
Top