sbit alarm=P3^6; //声音报警 alarm=0不发出声音,alarm=1; 发声音报警
unsigned char code table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //定义0到F 16个数码管显示代码;
void Delay(unsigned int tc) //延时程序
{
while( tc != 0 )
{unsigned int i;
for(i=0; i <100; i++);
tc--;}
}
void LED() //LED显示接收到的数据
{
shiwei=0; //十位显示控制
P2= table[dat/16];
Delay(8);
shiwei=1;
gewei=0; //个位显示控制
P2= table[dat%16];
Delay(5);
gewei=1;
}
void Init_Com(void)//功能:串口初始化,波特率9600,方式1
{
TMOD = 0x20;
PCON = 0x00;
SCON = 0x50;
TH1 = 0xFd;
TL1 = 0xFd;
TR1 = 1;
}
void main()//主程序功能:实现接收数据并把接收到的数据原样发送回去///////
{
Init_Com();//串口初始化
P1=0;
alarm=0;
while(1)
{
if ( RI ) //扫描判断是否接收到数据,
{
dat = SBUF-0x30; //接收数据SBUF赋与dat
RI=0; //RI清零。
SBUF = dat; //在原样把数据发送回去
}
LED(); //显示接收到的数据
}
}
此主题相关图片如下:
此主题相关图片如下: