📄
字号:
#define uchar unsigned char
#include "string.h"
#include "reg51.h"
sbit P1_0=P1^0;
sbit P2_7=P2^7;
sbit P2_5=P2^5;
sbit P1_7=P1^7;
sbit P1_1=P1^1;
void SendData(uchar Dat)
{ uchar i=0;
SBUF=Dat;
while(1 == 1){
if(TI == 1)
{
TI=0;
break;
}
}
}
void mDelay(unsigned int DelayTime)
{ unsigned char j=0;
for(;DelayTime>0;DelayTime--)
{
for(j=0;j<125;j++)
{;}
}
}
uchar Key()
{
uchar row,colum;
P2 = 0x0f;
if( P2 != 0x0f)
{
if(P2 == 0x07) row = 0;
if(P2 == 0x0b) row = 1;
if(P2 == 0x0d) row = 2;
if(P2 == 0x0e) row = 3;
P2 = 0xf0;
if(P2 != 0xf0)
{
if(P2 == 0x70) colum = 0;
if(P2 == 0xb0) colum = 1;
if(P2 == 0xd0) colum = 2;
if(P2 == 0xe0) colum = 3;
P2 = 0x0f;
while(P2 != 0x0f);
return (row*4+colum);
}
else
return (0xff);
}
return(0xff);
}
void main()
{
uchar KeyValue[4],pos,i,j;
uchar identify[4];
uchar send;
uchar Get;
P1=0x00; //关闭
TMOD=0x20; //确定定时器工作模式
TH1=0xe8;
TL1=0xe8; //定时初值
PCON&=0x80; //SMOD=1
TR1=1; //开启定时器 1
SCON=0x40; //串口工作方式 1
REN=1; //允许接收
RI = 0;
P2_7=0;
P2_5=1;
//工作循环
P2_7=0;
P2_5=0;
for(;;)
{
P1_7=1;
mDelay(0x01);
SendData(0x04);
mDelay(0x01);
P1_7=0;
mDelay(0xff);mDelay(0xff);
if(RI)
{
Get = SBUF;
SendData(Get);
P1_0=1;
P1_1=0;
RI = 0;
}
mDelay(0xff);mDelay(0xff);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -