文章目录[隐藏]
实现60S循环计时
#include "reg52.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit LSA = P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
u8 code smgduan[]={
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};
u8 numCount,ge,shi;
void delayus(u16 i)
{
while(i--);
}
void display()
{
LSC=0;LSB=0;LSA=0;
P0=0x00;
P0=smgduan[ge];
delayus(500);
LSC=0;LSB=0;LSA=1;
P0=0x00;
P0=smgduan[shi];
delayus(500);
}
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = 0x3C;
TL0 = 0xB0;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main()
{
InitTimer0();
while(1)
{
display();
}
}
void timer0() interrupt 1
{
static u8 num;
TH0 = 0x3C;
TL0 = 0xB0;
num++;
if(num==20)
{
num=0;
numCount++;
ge = numCount % 10;
shi = numCount /10;
if(numCount == 60)
numCount=0;
}
}
版权声明:本文为CSDN博主「acktomas」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/acktomas/article/details/104185375
暂无评论