• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

4x4 keypad with LCD - code lock

Status
Not open for further replies.

CrEdo

New Member
Hi.
I want to make some basic keypad scanning program with C30 on Pic24 chip.
The program should read keypad press and display the char on LCD.
LCD driver is working fine but now i have to combine this with keypad.

Basically, its something like code lock with lcd.

This is the schematics:
4x4 keypad Pictures, 4x4 keypad Images, 4x4 keypad Photos, 4x4 keypad Videos - Image - TinyPic - Free Image Hosting, Photo Sharing & Video Hosting

and this is full program:
Code:
/*----------------
COLUMNS are on portC
ROWS are on portG
------------------*/

void ScanKeyMatrixInit();
char ScanKeyMatrix();
 

char keyPadMatrix[] = 
{ 
    '1','2','3','A',
    '4','5','6','B',
    '7','8','9','C',
    '*','0','#','D',
    0xFF
};


void ScanKeyMatrixInit()
{
    // reading the columns 
    row1tris = 0;
    row2tris = 0;
    row3tris = 0;
    row4tris = 0;
    col1tris = 0;
    col2tris = 0;
    col3tris = 0;
    col4tris = 0;
}

char ScanKeyMatrix()
{
    // This routine returns the first key found to be pressed during the scan.
	char key = 0,
	row;
    
    for( row = 0b00000001; row < 0b00010000; row <<= 1 )
    {       
       	{   // turn on row output
        row1port = (row & 0x0001)>>0;
        row2port = (row & 0x0002)>>1;
        row3port = (row & 0x0004)>>2;
        row4port = (row & 0x0008)>>3;
       	}
	        // read colums - break when key press detected
	        if( col1port ) break; key++;
	        if( col2port ) break; key++;
	        if( col3port ) break; key++;
	        if( col3port ) break; key++;    
    }

		    row1port = 0;
		    row2port = 0;
		    row3port = 0;
		    row4port = 0;
        
    return keyPadMatrix[ key ]; 
}

//------------ debouncing -----------------
int checkKey( void)
{  
	int i=0, r=0, j=0;
	int c;
// wait for a key pressed
	do{
	     delayms( 10);
	     if ((c = readKEY()))
	     {
	         if ( c>r)       // if more than one button pressed
	             r = c;     
	         i++;   
	     }
	     else
	         i=0;
	} while ( i<10);

// wait for key release
i =0;
do {
     delayms( 10);  
     if ( (c = readKEY()))
     {
         if (c>r)        // if more then one button pressed
             r = c;     
         i=0;           
         j++;            // detect long button hold
     }
     else
         i++;
} while ( i<10);       

if ( j>80)                  // longer than 500ms
     r+=0x80;
return r;
} 
	
//	key = ScanKeyMatrix();
What do i need to add to make this program work ?
Thank you very much in advance !
 

rurffy

New Member
i also have this project . please @CrEdo how did you go about with your project. pkease reply. im confused i dont know where to start from.

my project is electronic keypadlock with LCD and alarm.

the alarm is meant to ring when the wrong key sequecne is been pressed.

please house help me out !!!
 

CrEdo

New Member
Unfortunately i need to use the microchip C30 compiler to make this. Do not use this compiler!. It's much to complicated and totally useless in some parts of code development. Choose CCS instead. It's much better / faster / generated code is smaller.

To do this project goto CCS forum and use the search.
You will get bunch of data regarding LCD and Keypad.

C.E.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top