test1.c

来自「本人学习51单片机时写的一些程序」· C语言 代码 · 共 58 行

C
58
字号

#include<reg52.h>

sbit USOut=P1^0;
int Byturns=1,T0times=0,T1times=0;

void main()
{
	
	EA=1;
	IT0=1;
	ET0=1;
	ET1=1;
	EX1=1;
	TMOD=0x11;
	TH1=0x3C;
	TL1=0xB0;
	TH0=0xFF;//13us
	TL0=0xF3;
	USOut=1;
	//USIn=1;
	TR1=1;
	TR0=1;
	for(;;);
}

void timer0(void) interrupt 1 //using 1
{
	TH0=0xFF;
	TL0=0xF3;
	USOut=!USOut;
	Byturns=!Byturns;
	T0times++;
	if(T0times>=10)
		{
			//T0times=0;
			TR0=0;//关闭定时器0	
			ET0=0;
			//USOut=!USOut;
		}
}

void timer1(void) interrupt 3 //using 2
{
	TH1=0x3C;
	TL1=0xB0;
	T1times++;
	if(T1times>=20)
	{
		T0times=0;
		T1times=0;
		
		TR0=1;
		ET0=1;
		
	}
}

⌨️ 快捷键说明

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