初级会员
- 积分
- 57
- 金钱
- 57
- 注册时间
- 2020-3-9
- 在线时间
- 4 小时
|
函数源代码
#include<AT89X52.h>
#include <intrins.h>
#define Delaynop(){_nop_();_nop_();_nop_();_nop_();}
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
void Delayms(unsigned int ms);
bit LCD_Busy();
void LCD_Pos(unsigned char);
void LCD_Wcmd(unsigned char);
void LCD_Wdat(unsigned char);
char code Title_Text[]={"--Phone Code-- "};
unsigned char code Key_Table[]={'1','2','3','4','5','6','7','8','9','*','0','#'};
unsigned char Dial_Code_Str[]={" "};
unsigned char KeyNo=0xff;
int tCount=0;
//oáÃ뼶Ñóê±oˉêy
void Delayms(unsigned int x)
{
unsigned char i;
while(x--)
{
for(i=0;i<120;i++);
}
}
//ÏÔê¾×Ö·û′®
void Display_String(unsigned char *str,unsigned char LineNo)
{
unsigned char k;
LCD_Pos(LineNo);
for(k=0;k<16;k++)
{
LCD_Wdat(str[k]);
}
}
//¼ì2é1602êÇ·ñ′|óúÃ|×°ìî
bit LCD_Busy_Check()
{
bit Result;
RS=0;
RW=1;
EN=1;
Delaynop();
Result=(bit)(P0 & 0x80);
EN=0;
return Result;
}
//Ïò1602D′èëÖ¸áîμÄoˉêy
void LCD_Write_Command(unsigned char cmd)
{
while(LCD_Busy_Check()); //¼ì2éêÇ·ñ′|óúÃ|×′ì¬
RS=0;
RW=0;
EN=0;
_nop_();
_nop_();
P0=cmd; //D′èëÖ¸áî
Delaynop();
EN=1;
Delaynop();
EN=0;
}
//Ïò1602D′êy¾Y
void LCD_Wdat(unsigned char dat)
{
while(LCD_Busy_Check()); //¼ì2éêÇ·ñ′|óúÃ|×′ì¬
RS=1;
RW=0;
EN=0;
P0=dat; //D′èëêy¾Y
Delaynop();
EN=1;
Delaynop();
EN=0;
}
//3õê¼»ˉ1602
void Init_LCD()
{
LCD_Write_Command(0x38);Delayms(5);
LCD_Write_Command(0x01);Delayms(5);
LCD_Write_Command(0x06);Delayms(5);
LCD_Write_Command(0x0c);Delayms(5);
}
//éèÖÃÏÔê¾Î»ÖÃ
void LCD_Pos(unsigned char pos)
{
LCD_Write_Command(pos|0x80);
}
/*
//T0μÄÖD¶Ï·tÎñ×óoˉêy
void T0Deal()interrupt 1
{
TH0=-600/256;
TL0=-600%256;
if(++tCount==200)
{
tCount=0;
TR0=0;
}
}
*/
//°′¼üé¨Ãèoˉêy£¬·μ»ØÖμÎa¶Ôó|μÄ°′¼ü±àÂë
unsigned char GetKey()
{
unsigned char i,j,k=0;
unsigned char KeyScanCode[]={0xef,0xdf,0xbf,0x7f}; //DDáDé¨ÃèμÄDDáDÂë
unsigned char KeyCodeTable[]={
0xee,0xed,0xeb,0xde,0xdd,0xdb,0xbe,0xbd,0xbb,0x7e,0x7d,0x7b};
P3=0x0f;
if(P3!=0x0f) //èç1ûóD°′¼ü±»°′ÏÂ
{
for(i=0;i<4;i++) //òà′νøDDé¨Ãè
{
P3=KeyScanCode[i];
for(j=0;j<3;j++)
{
k=i*3+j; //¼ÆËã¶Ôó|μÄ°′¼ü±àÂë
if(P3==KeyCodeTable[k])
{
return k; //·μ»Ø°′¼ü±àÂë
}
}
}
}
else
{
return 0xff; //»òÕß·μ»Ø0xff
}
}
|
|