⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c语言定时程序.txt

📁 基于89S52单片机的4位LED显示
💻 TXT
字号:
#include<reg51.h>
#include<absacc.h>
#include<stdio.h>

#define    uchar	unsigned char
#define    uint		unsigned int
#define    ulong	unsigned long

#define    LedDat   P0
#define    LedCnt   P2


static	uchar T0IntCnt	=20;
uchar  code  tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
static uchar string[]={0x01,0x09,0x09,0x09};

void delayms(uchar tt);
void display(void);
void IntInit(void);
void   main()
{
	IntInit();
	while(1)
	{
		display();
	}
}
void IntInit()
{
	TMOD=0x01;
	TH0=0x3c;
	TL0=0xb0;

	ET0=1;
	TR0=1;
	EA=1;
}
void T0IntService(void) interrupt 1 using 1
{
	uint tmp;
	T0IntCnt--;
	if( T0IntCnt == 0 )
	{
		T0IntCnt=20;
		tmp=string[3]*1000+string[2]*100+string[1]*10+string[0];
		tmp++;
		if(tmp == 10000) tmp=0;
		string[3]=tmp/1000;
		string[2]=tmp%1000/100;
		string[1]=tmp%100/10;
		string[0]=tmp%10;
	}
	TH0=0x3c;
	TL0=0xb0;	
}

void display()
{
	uchar i;
	uchar j=0xef;

	for(i=0;i<4;i++)
	{
		LedDat=tab[string[i]];
		LedCnt=j;
		j<<=1;
		delayms(50);
	}
}

void delayms(uchar tt)
{
	uchar i=200;
	while(tt--)
	{
		i--;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -