Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Regarding : Matrix 4x4 keypad interfacing with dsPIC30F4011 controller

Status
Not open for further replies.

htcompany

Junior Member level 2
Joined
Feb 2, 2016
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
220
Hello to all,
I am Working on dsPIC30F4011 microcontroller in MPLab in C programming. I need to use 4x4 matrix keypad. Please can any one suggest how can i interface that keypad with dsPIC30F4011 uController? and also kindly give programming instructions that need to be written in C code, like internal pull-up and all that. kindly provide solution as soon as possible...


Regards...
 

You're probably aware of this typical input array (4x4).
Sorry I don't know about programming the mcu.

3574765600_1489116905.png
 

hi,

I did not use that pic controller.

But i will give example coding for keypad.
below code is 8051 code for 4x4 matrix.
Code:
#include<reg51.h>
#define lcd P0
#define key P2
void delay();
void datas(unsigned char);
void cmd(unsigned char);
void lcdint(unsigned char);
sbit rs=P0^4;
sbit en=P0^5;

unsigned char keypad[4][4]	= {'0','1','2','3',
															'4','5','6','7',
															'8','9','A','B',
															'C','D','E','F'};
unsigned char rowloc,colloc,keypress;
void main()
{
	lcd=0xF0;		//INTIALIZING LCD PORT
	key=0xF0;		//INTIALIZING KEYPAD PORT
	
	while(1)
	{
		do							//KEY RELECE CHECK
			{
				key=0xF0;
				ACC=key;
				ACC=ACC&0XF0;
			}while(ACC != 0XF0);
		do
		{
			do						//KEY PRESS CHECK
			{
				delay();
				ACC=key;
				ACC=ACC&0XF0;
			}while(ACC == 0XF0);
			
			delay();			//DEBOUNCE CHECK
			ACC=key;
			ACC=ACC&0XF0;
			}while(ACC == 0XF0);
	while(1)
	{
		key=0xFE;				//CHECK COL LOCATION
		ACC=key;
		colloc=ACC & 0xF0;
		if(colloc != 0xF0)
		{
			rowloc=3;
			break;
		}
		key=0xFD;
		ACC=key;
		colloc=ACC & 0xF0;
		if(colloc != 0xF0)
		{
			rowloc=2;
			break;
		}
		key=0xFB;
		ACC=key;
		colloc=ACC & 0xF0;
		if(colloc != 0xF0)
		{
			rowloc=1;
			break;
		}
		key=0xF7;
		ACC=key;
		colloc=ACC&0xF0;
		rowloc=0;
		break;	
	}
	if(colloc==0XE0)		//CHECK ROW LOCATION
		colloc=3;
	else if(colloc==0XD0)
		colloc=2;
	else if(colloc==0XB0)
		colloc=1;
	else
		colloc=0;
	lcdint(keypad[rowloc][colloc]);
}
}
void lcdint(unsigned char keypress)		//SEND TO LCD
	{
		cmd(0X28);
		delay();
		cmd(0X0E);
		delay();
		cmd(0X01);
		delay();
		cmd(0X06);
		delay();
		cmd(0X80);
		delay();
		datas('K');
		delay();
		datas('E');
		delay();
		datas('Y');
		delay();
		cmd(0XC2);
		delay();
		datas(keypress);
		delay();
		
	}
void cmd(unsigned char value)		//LCD COMMAND PROGRAM
{
	ACC=value;
	ACC=ACC>>4;
	ACC=ACC&0X0F;
	P0=ACC;
	en=1;
	P0=ACC;
	ACC=value;
	ACC=ACC&0X0F;
	P0=ACC;
	en=1;
	P0=ACC;
}

void datas(unsigned char value)		//LCD DATA PROGRAM
{
	ACC=value;
	ACC=ACC>>4;
	ACC=ACC&0X0F;
	P0=ACC;
	rs=1;
	en=1;
	P0=ACC;
	ACC=value;
	ACC=ACC&0X0F;
	P0=ACC;
	rs=1;
	en=1;
	P0=ACC;
	delay();
}
 

Hi,

There are 4 rows an 4 columns
Making 8 lines
Connect these 8 lines to a microcontroller port

Initialize all 8 ports for input with pullup

To the four keys of a row:
Set the (single) row to output LOW(leave all other signals input with pullup)
Wait some microseconds (for the signals to stabilize)
Read the port
Now a LOW at a column represents a pressed key in that row. Decode it as you like.
Then make all signals input pullup again.
Finished

Do this for all four rows periodically. I recommend to use a timer interrupt to read the complete keypad every 50ms.

Multiple key press (at once) is a problem. Max two pressed keys can be decoded safely. But if more keys are pressed you get wrong readings.
I recommend to focus on single pressed keys. Make a single one byte variable as key_variable.
Where "0" = no key pressed
And "1" to "16" = according the pressed key.
I also recommend to focus on single key press, so multiple key press are shown as "0" = no key pressed.

Klaus
 

Hello,
I have connected keypad in B port of dsPIC30F4011 from pin no. 2 To 9. but i don't know how to write instructions for all pull-up. please kindly suggest C code statements for the pull up. some statements i wrote for keypad and pull-up are as below....



ADCON1 = 0x0F; // for analogue to digital conversion
TRISB = 0xF0; // for B port as input for keypad

CNPU1bits.CN2PUE = 1; // enable pullup
CNPU1bits.CN3PUE = 1; // enable pullup





Regards...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top