#include <reg51.H>
sbit P3_5 =P3^5
unsigned char code dispcode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0x00}
unsigned char second
unsigned char keycnt
unsigned int tcnt
void main(void)
{
unsigned char i,j
TMOD=0x02
ET0=1
EA=1
second=0
P1=dispcode[second/10]
P2=dispcode[second%10]
while(1)
{
if(P3_5==0)
{
for(i=20i>0i--)
for(j=248j>0j--)
if(P3_5==0)
{
keycnt++
switch(keycnt)
{
case 1:
TH0=0x06
TL0=0x06
TR0=1
break
case 2:
TR0=0
break
case 3:
keycnt=0
second=0
P1=dispcode[second/10]
P2=dispcode[second%10]
break
}
while(P3_5==0)
}
}
}
}
void t0(void) interrupt 1 using 0
{
tcnt++
if(tcnt==4000)
{
tcnt=0
second++
if(second==100)
{
second=0
}
P1=dispcode[second/10]
P2=dispcode[second%10]
}
}
#include#define
uchar
unsigned
char
uchar
distab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}
uchar
times,num
void
t0isr()
interrupt
1
{
TH0=(65536-50000)/256
//重置初值
TL0=(65536-50000)%256
times++
if(times>=20)
//1秒是否到
{
times=0
num--
//1秒到后,计数值减1
P0=distab[num]
//显示
if(num==0)num=9
//到0后再赋值为9
}
}
main()
{
TMOD=0x01
//定时器0为16为定时
TH0=(65536-50000)/256
//50毫米中断一次
TL0=(65536-50000)%256
ET0=1
EA=1
num=9
times=0
TR0=1
while(1)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)