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
源码文件 009.00 B
源码文件 keypadkeypad7.01 kB09-03-09 06:52
code file keypad.ckeypad.c2.59 kB09-04-09 12:48
源码文件 keypad.hexkeypad.hex2.06 kB09-03-09 06:52
源码文件 keypad.lnpkeypad.lnp45.00 B09-03-09 06:52
源码文件 keypad.LSTkeypad.LST9.12 kB09-03-09 06:52
源码文件 keypad.M51keypad.M5111.30 kB09-03-09 06:52
源码文件 keypad.OBJkeypad.OBJ7.10 kB09-03-09 06:52
源码文件 keypad.Optkeypad.Opt1.01 kB09-04-09 12:48
源码文件 keypad.plgkeypad.plg189.00 B09-04-09 12:48
源码文件 keypad.Uv2keypad.Uv22.13 kB09-03-09 06:53
源码文件 keypad_Opt.Bakkeypad_Opt.Bak1.22 kB09-04-09 12:03
源码文件 <keypad_Uv2.Bak><keypad_Uv2.Bak>0.00 B09-03-09 06:43
源码文件 STARTUP.A51STARTUP.A516.23 kB03-22-05 15:22
源码文件 STARTUP.LSTSTARTUP.LST13.72 kB09-03-09 06:52
源码文件 STARTUP.OBJSTARTUP.OBJ749.00 B09-03-09 06:52
源码文件 008.00 B
源码文件 keypadkeypad7.54 kB08-18-09 06:46
code file keypad.ckeypad.c2.53 kB08-18-09 06:39
源码文件 keypad.hexkeypad.hex2.61 kB08-18-09 06:46
源码文件 keypad.lnpkeypad.lnp45.00 B08-18-09 06:46
源码文件 keypad.LSTkeypad.LST7.60 kB08-18-09 06:46
源码文件 keypad.M51keypad.M5111.11 kB08-18-09 06:46
源码文件 keypad.OBJkeypad.OBJ7.57 kB08-18-09 06:46
源码文件 keypad.Optkeypad.Opt1.20 kB08-18-09 06:47
源码文件 keypad.plgkeypad.plg2.94 kB08-18-09 06:47
源码文件 keypad.Uv2keypad.Uv22.15 kB06-30-09 19:58
源码文件 keypad_Opt.Bakkeypad_Opt.Bak1.03 kB08-13-09 21:36
源码文件 <keypad_Uv2.Bak><keypad_Uv2.Bak>0.00 B06-30-09 18:48
源码文件 STARTUP.A51STARTUP.A516.23 kB03-22-05 15:22
源码文件 STARTUP.LSTSTARTUP.LST13.72 kB08-13-09 21:33
源码文件 STARTUP.OBJSTARTUP.OBJ758.00 B08-13-09 21:33
源码文件 key_pad.DSNkey_pad.DSN80.32 kB09-03-09 06:53
源码文件 key_pad.PWIkey_pad.PWI768.00 B09-03-09 06:53
源码文件 LastLast80.31 kB09-01-09 08:11
code file working_code.txtworking_code.txt2.47 kB08-13-09 18:57
源码文件 009.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