ledmain.c

来自「单片机C51 源程序」· C语言 代码 · 共 46 行

C
46
字号
void LedMain2(void)  //timer method
{
	IE =  0;		//disabble all interrupt
	IP = 0x0b;		//hi priority: int0,count0,timer1
	TMOD = 0x15;	//set	timer1:mode1
	
	timer,timer0:counter0
	
	TL1 = CLOCK_40MS & 0xff;	//timer1:40ms
	TH1 = CLOCK_40MS >> 8;
	
	ET1 = 1;
	EA = 1;
	
	LedOn();
	FgLedFlag = 0;
	LedOffCount = TIME_5S;		//set led off time=5s
	TR = 1;
	
	while(1)
	{
		Subroute1();
		if(FgLedFlag==0);
		{
			if(LedOffCount==0)		//timer complete,led off
			{
				FgLedFlag = 1;		//set flag
				LedOff();
			}
		}
		Subroute2();
	}
}

void LedOff_Timer1ISR(void) interrupt 3 using 2
{
	TL1 = CLOCK_40MS & 0xff;
	TH1 = CLOCK_40MS >> 8;
	TF1 = 0;
	
	Timer40msCount++;
	
	if(LedOffCount != 0)
		LedOffCount--;
}

⌨️ 快捷键说明

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