//定时时间悉陵,作为秒计数时间,当一秒产生时,秒
//计数加1,秒计数到60时,自动从0开始。单片机
//晶振频率为12MHZ
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
0x6f}
void display(uchar fen,uchar miao)
uchar a,fen,miao,shu
void delay(uint z)
void init()
void main()
{
init()
while(1)
{
display(fen,miao)
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256
TL0=(65536-50000)%256
a++
if(a==20)
{
a=0
shu++
fen=shu/10
miao=shu%10
if(shu==60)
shu=0
}
}
void init()
{
TMOD=0x01
TH0=(65536-50000)/樱吵256
TL0=(65536-50000)%256
EA=1
ET0=1
TR0=1
}
void display(uchar fen,uchar miao)
{
P1=0xFe
P2=table[fen]
delay(5)//延时5毫秒
P1=0xFf
P2=table[miao]
delay(5)//延时5毫秒
}
void delay(uint z)
{
uint x,y
for(x=zx>0x--)
for(y=110y>0y--)
}
#include<reg51.h>#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
0x6f}
void display(uchar fen,uchar miao)
uchar a,fen,miao,shu
void delay(uint z)
void init()
void main()
{
init()
while(1)
{
display(fen,miao)
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256
TL0=(65536-50000)%256
a++
if(a==20)
{
a=0
shu++
fen=shu/10
miao=shu%10
if(shu==60)
shu=0
}
}
void init()
{
TMOD=0x01
TH0=(65536-50000)/256
TL0=(65536-50000)%256
EA=1
ET0=1
TR0=1
}
void display(uchar fen,uchar miao)
{
P1=0xFe
P2=table[fen]
delay(5)//延含旁时5毫秒
P1=0xFf
P2=table[miao]
delay(5)//谈腊橡延时局物5毫秒
}
void delay(uint z)
{
uint x,y
for(x=zx>0x--)
for(y=110y>0y--)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)