Home » Source Code » » keypad.c

keypad.c ( File view )

From:
  • By 2010-08-05
  • View(s):20
  • Download(s):0
  • Point(s): 1
			#include <reg52.h>


void delay(unsigned int);
void lcdcmd (unsigned char);
void lcddata(unsigned char );
void lcddisplay(unsigned char *);
bit  keypress();

sbit en = P3^7;
sbit rs = P3^6;
//sbit rw = P1^5;

sbit col_1 = P2^4;
sbit col_2 = P2^5;
sbit col_3 = P2^6;

sbit row_a = P2^3;
sbit row_b = P2^2;
sbit row_c = P2^1;
sbit row_d = P2^0;
 
unsigned char keypad[4][3] = {
	'1','2','3',
								'4','5','6',
								'7','8','9',
								'*','0','#'
							 
};

void main()
{

	unsigned char rowloc;
	unsigned char lcd_text_1[] = "KEY PAD CHECK";
	
//-------------LCD COMMANDS----------------------//
	lcdcmd(0x33);
	delay(25);
	lcdcmd(0x32);
	delay(25);
	lcdcmd(0x28);
	delay(25);
	lcdcmd(0x0E);
	delay(25);
	lcdcmd(0x06);
	delay(25);
	lcdcmd(0x01);
	delay(25);

	lcdcmd(0x80);
	delay(25);
	lcddisplay(lcd_text_1);
	delay(25);
//-------------------------------------------------//
  while(1)
	{

	
		col_1=col_2=col_3=1;
		delay(25);
		row_a=row_b=row_c=row_d=0;
	
			if(!col_1||!col_2||!col_3)
			{

			while(1)
			{

				row_a=0;row_b=1;row_c=1;row_d=1;
				if(!col_1||!col_2||!col_3)
				{

					rowloc = 0;
					break;
				
}
				row_a=1;row_b=0;row_c=1;row_d=1;
				if(!col_1||!col_2||!col_3)
				{

					rowloc = 1;
					break;
				
}
				row_a=1;row_b=1;row_c=0;row_d=1;
				if(!col_1||!col_2||!col_3)
				{

					rowloc = 2;
					break;
				
}
				row_a=1;row_b=1;row_c=1;row_d=0;
				if(!col_1||!col_2||!col_3)
				{

					rowloc = 3;
					break;
				
}
			
}	
	

		if(col_1==0&&col_2==1&&col_3==1)
		{

			lcdcmd(0xc0);lcddata(keypad[rowloc][0]);
		
}
		else if(col_1==1&&col_2==0&&col_3==1)
		{

			lcdcmd(0xc0);lcddata(keypad[rowloc][1]);
		
}
		else if(col_1==1&&col_2==1&&col_3==0)
		{

			lcdcmd(0xc0);lcddata(keypad[rowloc][2]);
		
}
 	
}
 
}
//-------------------KEYPAD ROUTINE-------------------//


}	

	
	

	
void lcdcmd(unsigned char value)
{

	unsigned char val;
	val = value;
	val = val >>4;
	rs = 0;
    P1 = (val & 0x0F);
	en = 1;
	delay(1);
	en = 0;
    P1 = (value & 0x0F);
	en = 1;
	delay(1);
	en = 0;
	return;


}

void lcddata(unsigned char value)
{

	unsigned char val;
	val = value;
	val = val >>4;
	rs = 1;
    P1 = (val & 0x0F);
	en = 1;
	delay(1);
	en = 0;
    P1 = (value & 0x0F);
	en = 1;
	delay(1);
	en = 0;
	return;

}

void lcddisplay(unsigned char *take)
{

	while(*take)
	{

		lcddata(*take++);
	
}

}
	
void delay(unsigned int itime)
	{

		int i,j;
		for(i=0;i<itime;i++)
			for(j=0;j<100;j++);

	
}
	
			 
			 
		 
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
09.00 B
keypad7.01 kB09-03-09 06:52
keypad.c2.59 kB09-04-09 12:48
keypad.hex2.06 kB09-03-09 06:52
keypad.lnp45.00 B09-03-09 06:52
keypad.LST9.12 kB09-03-09 06:52
keypad.M5111.30 kB09-03-09 06:52
keypad.OBJ7.10 kB09-03-09 06:52
keypad.Opt1.01 kB09-04-09 12:48
keypad.plg189.00 B09-04-09 12:48
keypad.Uv22.13 kB09-03-09 06:53
keypad_Opt.Bak1.22 kB09-04-09 12:03
<keypad_Uv2.Bak>0.00 B09-03-09 06:43
STARTUP.A516.23 kB03-22-05 15:22
STARTUP.LST13.72 kB09-03-09 06:52
STARTUP.OBJ749.00 B09-03-09 06:52
08.00 B
keypad7.54 kB08-18-09 06:46
keypad.c2.53 kB08-18-09 06:39
keypad.hex2.61 kB08-18-09 06:46
keypad.lnp45.00 B08-18-09 06:46
keypad.LST7.60 kB08-18-09 06:46
keypad.M5111.11 kB08-18-09 06:46
keypad.OBJ7.57 kB08-18-09 06:46
keypad.Opt1.20 kB08-18-09 06:47
keypad.plg2.94 kB08-18-09 06:47
keypad.Uv22.15 kB06-30-09 19:58
keypad_Opt.Bak1.03 kB08-13-09 21:36
<keypad_Uv2.Bak>0.00 B06-30-09 18:48
STARTUP.A516.23 kB03-22-05 15:22
STARTUP.LST13.72 kB08-13-09 21:33
STARTUP.OBJ758.00 B08-13-09 21:33
key_pad.DSN80.32 kB09-03-09 06:53
key_pad.PWI768.00 B09-03-09 06:53
Last80.31 kB09-01-09 08:11
working_code.txt2.47 kB08-13-09 18:57
09.00 B
...
Sponsored links

keypad.c (73.22 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D