L298N PWM调速

#include
sbit IN1=P1^0;
sbit IN2=P1^1;
#define uchar unsigned char 
#define  uint unsigned int 	

#define CRYSTAL_FREQ 11059200  //
#define INTERRUPT_PERIOD_0 100000//1/100000s=0.01ms
uint flag=100;//pin lv
uchar n=50;//zhan kong bi 
uchar time=0;
void Interrupt_Init()
{
  TMOD = 0x01;	
  TH0 = (65536 - CRYSTAL_FREQ / 12 / INTERRUPT_PERIOD_0) / 256;
  TL0 = (65536 - CRYSTAL_FREQ / 12 / INTERRUPT_PERIOD_0) % 256;
  ET0 = 1;
	TR0 = 1;
  EA  = 1;	
}


void main()
{
	Interrupt_Init();
	while(1)
	{
		
	}
}


 void Timer0() interrupt 1
{
	TR0=0;
  TH0 = (65536 - CRYSTAL_FREQ / 12 / INTERRUPT_PERIOD_0) / 256;
  TL0 = (65536 - CRYSTAL_FREQ / 12 / INTERRUPT_PERIOD_0) % 256;
	TR0=1;
	time++;
	if(time=flag)
		{
			time=0;			
		}
	if(time<=n)
	{
			IN1=1;
			IN2=0;//zhngzhuan	
	}
}

你可能感兴趣的:(51单片机,土壤检测)