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

📄 pwm_gen.c

📁 蛇形机器人程序
💻 C
字号:
///////////////////////////////////////////////////
//pwm_gen
///////////////////////////////////////////////////
#include<FollowLine.h>
#include<intrins.h>
#include<reg52.h>

char iLeftCounter = 0; 	//Current high level Counter
char iRightCounter = 0;	 // the original value from xiao mao is l r 
char RightSpeed=0;		//High level precent of Cycle expected 
						//0 - 16 of 16
char LeftSpeed=0;		//the original value XM is LeftCounter
unsigned char time=0;
//what is uchar

// the duration is cycle(10) * (0x100 - 0x58)//(168)
// when LeftCounter/RightCounter of cycle flip

void PWM() interrupt 1
{
	TR0=0;	   	//turn on the counter
	
	//~~~~~~Left Motor~~~~~~~~~
	if(iLeftCounter == LeftSpeed)
	{
		DriveLeftMo1 = 0;	//LeftStop
		DriveLeftMo2 = 0;
	}
	if(iLeftCounter == Cycle)
	{
		if(DirectionLeft)
		{
			DriveLeftMo1 = 1;	//LeftRun
			DriveLeftMo2 = 0;
		}
		else
		{
			DriveLeftMo1 = 0;	//LeftBack
			DriveLeftMo2 = 1;
		}
		iLeftCounter = -1;	 
	} 
	//~~~~~Right Motor~~~~~~~~
	if(iRightCounter == RightSpeed)
	{
		DriveRightMo1 = 0;
		DriveRightMo2 = 0;	 // Stop
	}
	if(iRightCounter == Cycle)
	{
		if(DirectionRight)  //driection
		{
			DriveRightMo1 = 1;
			DriveRightMo2 = 0;					//RightRun
		}
		else 
		{
			DriveRightMo1 = 0;
			DriveRightMo2 = 1;					//RightBack
		}
		iRightCounter = -1;	 			// 
	}

	iLeftCounter++;
	iRightCounter++;

	TH0 = TIMER0H;
	TL0 = TIMER0L;
	TR0 = 1;
}


void timer() interrupt 3
{
   TR1=0;
   if(time==130)
   {
	Stop();
	ReleaseMotor = 0;		//release the blocker?

	Delay(10000);
	ReleaseMotor = 1;

	Stop();
	TouchSensor1=0;
	TouchSensor2=0;
	}
	else
	{
	time++;
	TH1=TIMER1H;
	TL1=TIMER1L;
	}
	TR1=1;
}

⌨️ 快捷键说明

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