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

📄 communicate.c

📁 51单片机控制产生4路标准舵机PWM(周期20ms
💻 C
字号:
/*********************************************
file communicate.c
by sixiangzhe 
copyright 2007/5/14-2007/5/15
note:
	please run init_UART() first; 

**************************************************/
#include <REG51F.H>
#include<communicate.h>
unsigned char command[8],commandready,framehead,revtemp,bytetoget,comnext,togetsure;
#define RESETCOM (0x00)
#define SURECOM	(0xff)

void Init_UART (void)
{
	T2CON   = 0x34;  /* Use Timer 2 For Baudrate */
	RCAP2H  = 0xFF;
	RCAP2L  = 0xdc;  /* 9600 Baud @ 11.0592MHz */
	SCON    = 0x50;  /* Enable UART */
	TI    = 0;
	ES=1;
	RI	=0;                  /* TI:   set TI to send first char of UART    */
	EA      = 1;     /* Enable Global Interrupts */
}


void intUART() interrupt 4
{
unsigned char i;

ES=0;
if(RI)
{
RI=0;
revtemp=SBUF;
/////////////////////////////////////////////////////////////
if(revtemp==RESETCOM)
{
  framehead=0;
  bytetoget=0;
  comnext=0;
  togetsure=0;
  

}
else
{
	if(togetsure)
	{
			if(revtemp==SURECOM)
			{ 	
			commandready=1;
			bytetoget=0;
			togetsure=0;
			}
	}
	else
	{
			if(bytetoget==0)  //this is framehead;
			{	  
				framehead=revtemp;
				bytetoget=(revtemp>>4);
				comnext=0;
		
			}
			else
			{
				bytetoget--;
				command[comnext]=revtemp;
				comnext++;
				if(bytetoget==0)//get all command
				{
			
				TI=0;
				
				SBUF=framehead;
				for(i=0;i<comnext;i++)
				{
				while(!TI);
				TI=0;
				SBUF=command[i];
				}
				framehead=0;
		  		bytetoget=0;
				comnext=0;
				togetsure=1;
				}
				
			}
	}
}
////////////////////////////////////////////////////////////////////////////

}
if(TI)
{
TI=0;

}
ES=1;

}

⌨️ 快捷键说明

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