#define uchar unsigned char
uchar code ledtab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}//共阳级数差早缓码管码表0-9
uchar time,scanled
uchar disdat[2]
bit flag=0
void dischg() //显示码转睁纯换
{
disdat[0]=s_dat/10//秒转换
disdat[1]=s_dat%10
}
void t0isr() interrupt 1 //秒计时
{
TH0=(65536-50000)/256
TL0=(65536-50000)%256
time++
if(time>=20)
{
time=0
s_dat++
flag=1
}
}
void t1isr() interrupt 3 //显示控制
{
TH1=(65536-4000)/256
TL1=(65536-4000)%256
duan=1
P0=0xff /虚模/消隐
duan=0
wei=1
P0=1<<scanled//位码
wei=0
duan=1
P0=disdat[scanled]
duan=0
scanled++
scanled%=2//共8位显示
}
main()
{
TMOD=0x21 //定时器0和1都为模式1
TH0=(65536-50000)/256//定时器0,50毫秒中断一次
TL0=(65536-50000)%256
TH1=0xfd
TL1=0xfd
SCON=0x40
TR1=1
TR0=0
ET0=1
EA=1
scanled=0
time=0
dischg()
while(1)
{
if(flag)
{
flag=0
SBUF=s_dat
while(TI==0)
TI=0
}
}
}
#include <reg52.H> //STC头文件#define uchar unsigned char
#define uint unsigned int
#define timewe 3
sbit we = P2^7
sbit du = P2^6
unsigned long temp
uint 埋困jsms=0
uchar code duan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}
uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}
void delay (uint a) // 1ms延时程序(12MHz 10倍于51单片机速度时)
{
uint i
while( --a != 0)
{
for(i = 0 如樱i < 600 i++)
}
}
uchar disbuf[6]
void display()
{ uchar 渣液丛code wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf}
static uchar a
if(a>=6)a=0
we=1
P0=0xff
we=0
du=1
P0=duan[disbuf[a]]
du=0
we=1
P0=wei[a]
we=0
a++
}
/**********************************************/
/* 主函数 */
/**********************************************/
void main(void)
{
temp=0
while(1)
{
if(++jsms>=1000){
if(++temp == 999999)
temp = 0
}
disbuf[0] = temp/100000
disbuf[1] = temp%100000/10000
disbuf[2] = temp%10000/1000
disbuf[3] = temp%1000/100
disbuf[4] = temp%100/10
disbuf[5] = temp%10
display()
delay(1)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)