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]
}
}
C语言#include
#define
uint
unsigned
int
#define
uchar
unsigned
char
sbit
p27=P2^7//数码管位选端定义
uchar
c,i
//数码管译码表
unsigned
char
code
NumDecode[]
=
{
0XC0,//0
0XF9,//1
0XA4,//2
0XB0,//3
0X99,//4
0X92,//5
0X82,//6
0XF8,//7
0X80,//8
0X90,//9
}
void
main()
{
i=0//10秒计时设置
c=0//中断次数计数
p27=1//数码管位选端关闭
TMOD=1//设置定时器0为工作方式1
TH0=(65536-46080)/256//定时50ms高8位求模
TL0=(65536-46080)%256//定时50ms低8位求余
EA=1//开总中断
ET0=1//定时器0中断
TR0=1//启动定时器0
while(1)
{
if(c==20)//50ms中断20次
{
c=0
i++//倒计时总数每秒减1
}
if(i<10)
{
p27=0//数码管位选选通
P0=NumDecode[i]//显示数据
}
else
//循环计时设置
{
i=0
}
}
}
void
timer0()
interrupt
1//定时器0中断入口
{
TH0=(65536-46080)/256//定时器重新赋初值
TL0=(65536-46080)%256
c++//中断次数
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)