unsigned char dat//用于存储单片机接收发送缓冲寄存器SBUF里面的内容
sbit gewei=P2^2//个位选通定义
sbit shiwei=P2^3//十位选通定义
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67,0x77,0x7c,0x39,0x5e,0x79,0x71}
//{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67,}// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
void Delay(unsigned int tc) //延时程序
{
while( tc != 0 )
{unsigned int i
for(i=0i<100i++)
tc--}
}
void LED() //LED显示接收到的数据
{
shiwei=0
P0=~table[dat/16]
Delay(8)
shiwei=1
gewei=0
P0=~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=0xf0
while(1)
{
if ( RI ) //扫描判断是否接收到数据,
{
dat = SBUF //接收数据SBUF赋与dat
RI=0 //RI清零。
SBUF = dat //在原样把数据发送回去
}
LED()//显示接收到的数据
}
}
#include"reg51.h"#define uint unsigned int
#define uchar unsigned char
void init()
void display(uchar,uchar,uchar,uchar,uchar,uchar)
sbit wela=P2^7
sbit dula=P2^6
sbit key0=P3^4
sbit key1=P3^5
sbit key2=P3^6
sbit key3=P3^7
uchar aa,bb,cc,bai,shi,ge
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71}
uchar temp1=0,temp2=0,temp3=0
void delay(uint z)
{
uint x,y
for(x=0x<zx++)
for(y=0y<110y++)
}
void main()
{
init()
while(1)
{
display(aa,bb,cc,bai,shi,ge)
if(key0!=1)
{
delay(5)
if(key0!=1)
{
while(!key0)
display(aa,bb,cc,bai,shi,ge)
temp3++
if(temp3==24)
temp3=0
}
}
if(key1!=1)
{
delay(5)
if(key1!=1)
{
while(!key1)
display(aa,bb,cc,bai,shi,ge)
temp2++
if(temp2==60)
temp2=0
}
}
if(key3!=1)
{
delay(5)
if(key3!=1)
{
temp1=0temp2=0temp3=0
}
}
if(key2!=1)
{
delay(5)
if(key2!=1)
{
temp1=0
}
}
}
}
void init()
{
TMOD=0x01
TH0=(65536-50000)/256
TL0=(65536-50000)%256
EA=1
ET0=1
TR0=1
}
void timer0() interrupt 1
{
uchar a
TH0=(65536-50000)/256
TL0=(65536-50000)%256
a++
if(a==19)
{
a=0
aa=temp3/10
bb=temp3%10
cc=temp2/10
bai=temp2%10
shi=temp1/10
ge=temp1%10
temp1++
if(temp1==60)
{
temp1=0
temp2++
if(temp2==60)
{
temp2=0
temp3++
if(temp3==24)
{
temp1=0temp2=0temp3=0
}
}
}
}
}
void display(uchar aa,uchar bb,uchar cc,uchar bai,uchar shi,uchar ge) //显示子函数
{
dula=1
P0=table[aa]
dula=0
P0=0xff
wela=1
P0=0xfe
wela=0
delay(1)
dula=1
P0=table[bb]
dula=0
P0=0xff
wela=1
P0=0xfd
wela=0
delay(1)
dula=1
P0=table[cc]
dula=0
P0=0xff
wela=1
P0=0xfb
wela=0
delay(1)
dula=1
P0=table[bai]
dula=0
P0=0xff
wela=1
P0=0xf7
wela=0
delay(1)
dula=1
P0=table[shi]
dula=0
P0=0xff
wela=1
P0=0xef
wela=0
delay(1)
dula=1
P0=table[ge]
dula=0
P0=0xff
wela=1
P0=0xdf
wela=0
delay(1)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)