定时器与数码管的静态显示

设置一个1s的定时器,使数码管显示从1-f的十六进制数。定时器与数码管的静态显示_第1张图片

定时器与数码管的静态显示_第2张图片

#include 

sbit ADDR0 = P2^4;
sbit ADDR1 = P2^5;
sbit ADDR2 = P2^6;
sbit ENDLINE = P2^7;

unsigned char code LedChar[]={
	0xc0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
	0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E
	};

void main()
{	
	unsigned int sec = 0;
	unsigned int cnt = 0;
	ADDR0 = 0;
	ADDR1 = 0;
	ADDR2 = 0;
	ENDLINE = 0;
	
	TMOD = 0x01;
	TH0 = 0xB8;
	TL0 = 0x00;
	TR0 = 1;
	while(1)
	{
		if(TF0 == 1)
		{
			TF0 = 0;
			TH0 = 0xB8;
			TL0 = 0x00;
			cnt++;
			if(cnt >= 50)
			{
				cnt = 0;
				P0 = LedChar[sec];
				sec++;
				if(sec >= 16)
				{
					sec = 0;
				}
			}
		}
	}
}

你可能感兴趣的:(定时器与数码管的静态显示)