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

📄 main.c

📁 本文件用于智能云台电机控制和图像处理
💻 C
📖 第 1 页 / 共 3 页
字号:
/*---------------------------------
记住调整ID时键盘发的码和PELCO有点相同,程序要加识别处理的

-----------------------------------*/
/*-----------------------------------------------

   明景的键盘PELCO-P球机ID为实际球机ID少1,程序要进行处理
   PELCO-D上下两代码颠倒了,UP为000     DOWN 为00108 与公布的相反
------------------------------------------------*/
#include <general.h>      //定义外部的函数
volatile unsigned char idata programFlyOff;
volatile unsigned char flagTxd;
volatile unsigned int comTxd;
volatile unsigned char countTxd;
unsigned char idata sKeyCode[5]={""}; //目前只用一组来表示,并且为0值	接收键盘码用
volatile unsigned char idata cKeyCodeReceiveState;	//初值处于无串口码接收到状态有值用1表示
volatile unsigned char idata cKeyCodeReceive;
volatile unsigned char idata  *pKeyCode;
volatile unsigned char cameraType;

 unsigned char code SONYCLEAR[]={0x88,1,0,1,0xff};
 unsigned char code SONYADDRSET[]={0x88,0x30,1,0xff};
 unsigned char code SONYPOWERON[]={0x81,1,4,0,2,0xff};
 unsigned char code SONYPOWEROFF[]={0x81,1,4,0,3,0xff};
 unsigned char code SONYZOOMTELE[]={0x81,1,4,7,25,0xff};
 unsigned char code SONYZOOMWIDE[]={0x81,1,4,7,35,0xff};
 unsigned char code SONYZOOMSTOP[]={0x81,1,4,7,0,0xff};
 unsigned char code SONYFOCUSFAR[]={0x81,1,4,8,25,0xff};
 unsigned char code SONYFOCUSNEAR[]={0x81,1,4,8,35,0xff};
 unsigned char code SONYFOCUSSTOP[]={0x81,1,4,8,0,0xff};
 unsigned char code SONYIRISRESET[]={0x81,1,4,0xb,0,0xff};
 unsigned char code SONYIRISUP[]={0x81,1,4,0xb,2,0xff};
 unsigned char code SONYIRISDOUWN[]={0x81,1,4,0xb,3,0xff};
 unsigned char code SONYPICTUREFLIPON[]={0x81,1,4,0x66,2,0xff};
 unsigned char code SONYPICTUREFLIPOFF[]={0x81,1,4,0x66,3,0xff};
 unsigned long code	SIN16[]={0x43ffe,0x4307e,0x4207e,0x4707e,
 0x47ffe,0x47fc0,0x45f80,0x45fc0,0x45ffe,0x4507e,0x4007e,
  0x4107e,0x41ffe,0x41fc0,0x41f80,0x43fc0} ;
 unsigned long code	SIN16_[]={0x43ffe,0x43fc0,0x41f80, 0x41fc0,
 0x41ffe,0x4107e, 0x4007e,0x4507e,0x45ffe, 0x45fc0,0x45f80,
 0x47fc0 ,0x47ffe, 0x4707e,0x4207e,0x4307e } ;
 unsigned long code	SIN4[]={0x043ffe,0x047ffe,0x045ffe,0x041ffe};
 unsigned int code DECTABLE[]={-4400,-4500,-4700,-4800,
 -4900,-5000,-6000,-7000,
 -8000,-9000,-10000,-20000,  
 -30000,-40000,-50000,-60000};
unsigned int code ACCTABLE[]={-60000,-50000,-40000,-30000,
 -20000,-10000,-9000,-8000,
 -7000,-6000,-5000,-4900,
 -4800,-4700,-4500,-4400};

 volatile unsigned char vOrientFlag;
 volatile unsigned char vStopFlag;
 volatile unsigned int vAbsolutionPosition;
 volatile unsigned int vPresetPosition1 ;
 volatile unsigned int vPresetPosition2 ;
 volatile unsigned int vPresetPosition ;
 volatile unsigned int vAbsolutionPosition;
 volatile unsigned char	vRotationManner;
 volatile unsigned char vaccDecFlag;
 volatile unsigned int vPauseTime;
 volatile unsigned int xdata VMulPoint[]={0,200,400,600,800};
 volatile unsigned char xdata vMulPointCount;
 volatile unsigned char vSoftTimer0;


 volatile unsigned char hOrientFlag;
 volatile unsigned char hStopFlag;
 volatile unsigned int hAbsolutionPosition;
 volatile unsigned int hPresetPosition1 ;
 volatile unsigned int hPresetPosition2 ;
  volatile unsigned int hPresetPosition ;
 volatile unsigned char	hRotationManner;
 volatile unsigned char haccDecFlag;
 volatile unsigned int hPauseTime;
 volatile unsigned int xdata HMulPoint[]={0,200,400,600,800};
 volatile unsigned char xdata hMulPointCount;
// volatile unsigned char  hPointMotionFlag;
 /*
 void GeneralHRotation(char v)
 {
 hRotationManner=GENERALROTATION;
 hOrientFlag=(v>=0)?1:-1;
 v=(v>=0)?-v:v;
 v=10*v; //作速度变换
 RCAP2L=(unsigned char)v;
 RCAP2H=(unsigned char)(v>>8);
 }
 void GeneralVRotation(char v)
 {
 vRotationManner=GENERALROTATION;
 vOrientFlag=(v>=0)?1:-1;
 v=(v>=0)?v:-v;
vConst=	10*v ;	 //因T0时间基数太小要在中断里作一个软计时处理
 }
  void PresetHRotation(char dot)
  {		   //返绝对坐标
 hRotationManner=PRESETROTATION;
 RCAP2L=(unsigned char)100;		//以最快速度运行
 RCAP2H=(unsigned char)(100>>8);
 }
 void PresetVRotation(char dot)
 {					 //返绝对坐标
 vRotationManner=PRESETROTATION;
 vConst=	10*10 ;	 //因T0时间基数太小要在中断里作一个软计时处理
 }
 void RoutinHRotation(char v)
 {
 hRotationManner=ROUTINROTATION;
 
 RCAP2L=(unsigned char)v;
 RCAP2H=(unsigned char)(v>>8);
 }
 void RoutinVRotation(char v)
 {
 vRotationManner=ROUTINROTATION;
 
  vConst=	10*10 ;
 }
 void HStop(void)
 {
   hRotationManner=STOPROTATION;
   }
 void VStop(void)
 {
   vRotationManner=STOPROTATION;
   }
   */
 void main()
{	

volatile    unsigned int x;
volatile    unsigned char count,y;
ERRor:	  
	WdtCls();
	GlobalSet();
	IntDisable();
	T0Stop();
	T1Stop();
	T2Stop();
	TimerSet();
	SciSet();
	flagTxd=0xee;	//初始化发送器状态变量
	countTxd=0;
 
/*
P0_1=P0_2=P0_0=0;
while(1)
	WdtCls();
*/

CharOut(VIDEORAMCLS);
WdtCls();
CharOut(DISPCONTROL+DISPON+BLINKOFF);
//CharOut(0x22);
WdtCls();
CharOut(BACKGROUNDCONTROL+BACKGROUNDno);
WdtCls();
CharOut(EXTERNALVIDEO);
WdtCls();
CharOut(PAL);
WdtCls();
CharOut(ORIGIN+(0ORIGINPROW)+1);
WdtCls();
CharOut(POSITION+(0POSITIONy)+1);
WdtCls();
CharOut(OUT1VPP);
WdtCls();
for(x=0;x<0xc;x++)
{
CharOut(CHARACTERSIZE+CHARACTERSIZE0+x);
}
WdtCls();
BeginCharOut();
for(x=0;x<0x7f;x++)
{
SecCharOut(x);
WdtCls();
}
EndCharOut();
//CharOut(DISPCONTROL+DISPOFF+BLINKOFF);
while(1)
WdtCls();
 /*
	IntSet();
	IntEnable();
	TxdBaud9600();
	T1Start();
	SBUF=9;
	Delay();
	Delay();
	Delay();
	SBUF=9;
	while(1)
	WdtCls();

*/	
	/*------------------- 接收相机类型初始程序
	if(!programFlyOff)
	{
	IntSet();
	IntEnable();
	TxdBaud9600();
	T1Start();
	x=0;
		while(1)
			 {	
				 WdtCls();
				 	
 			if(!cKeyCodeReceiveState)  	continue;
		
			if(0xff!=cKeyCodeReceive)
			{
				 cKeyCodeReceiveState=0;
				 continue;					//首码错则结束  进  入  循  环
				 }
		
			   cKeyCodeReceiveState=0; 
				while(!cKeyCodeReceiveState)  //读码等待
								 {
									WdtCls();
								 }
								 
								 x=cKeyCodeReceive;
								 cKeyCodeReceiveState=0; 
								 cameraType=(unsigned char )x;
							
 				 while(!cKeyCodeReceiveState)  //读码等待
								 {
									WdtCls();
								 }
								 x+=(cKeyCodeReceive<<8);
								 cKeyCodeReceiveState=0; //取走键盘码
								 
				switch(x)
				{
				case  0: TxdBaud2400();break;
				case  CAMERAMODEL+SONY: TxdBaud9600();break;
				case  2: TxdBaud4800();break;
				case  3: TxdBaud19200();break;
				default: break;
				}
				break;
         	}

	 }			  //判断是否程度跑飞进行串口初始波特接着进行有关初始定位工作,直到定位完成将跑飞标志置位
-----------------------*/
/*---------------------------水平位检测部分-----------------

if(!programFlyOff)
{
IntDisable();
HIntSet();
HMotorOut(A3279INITATE) ;
//HMotorOut(SIN16[0]) ;

//HVolecity(-4000);
IntEnable();
//hRotationManner=STOPROTATION ;
//hRotationManner= SINGLEMOTION;
//hRotationManner=FREEMOTION;
//hRotationManner= DOUBLEMOTION ;
 hRotationManner= MULMOTION ;
//		hOrientFlag=-1;
		haccDecFlag=ACCELERATION ;
//hRotationManner=TWOROTATION;
hPresetPosition1=0;
hPresetPosition2=1999;
hPresetPosition=hPresetPosition1;
hAbsolutionPosition=hPresetPosition2 ;

T2Start();

 
}
while(1)
	WdtCls();


------------------------------------*/
/*---------------------------垂直位检测部分-----------------

if(!programFlyOff)
{
IntDisable();
VIntSet();
VMotorOut(A3279INITATE) ;
//HMotorOut(SIN16[0]) ;

//HVolecity(-4000);
IntEnable();
//hRotationManner=STOPROTATION ;
//hRotationManner= SINGLEMOTION;
//vRotationManner=FREEMOTION;
// vRotationManner= DOUBLEMOTION ;
vRotationManner= MULMOTION ;
//		vOrientFlag=-1;
	vaccDecFlag=ACCELERATION ;
	//	vaccDecFlag=NORMALMOTION ;
//hRotationManner=TWOROTATION;
vPresetPosition1=0;
vPresetPosition2=1999;
vPresetPosition=hPresetPosition1;
vAbsolutionPosition=hPresetPosition2 ;

T0Start();

 
}
while(1)
	WdtCls();
	------------------------------------*/
/*
if(!programFlyOff)
{
IntDisable();
HIntSet();
HMotorOut(A3279INITATE) ;	 //试验运动方向及停止
//GeneralHRotation(100) ;
HVolecity(-2000);
IntEnable();
T2Start();
}

Delay();
//vStopFlag=1;
T0Stop();
while(1)
	WdtCls();

*/
/*---------------------------垂直位检测部分---------------
if(!programFlyOff)
{
IntDisable();
VIntSet();
VMotorOut(A3279INITATE) ;

VVolecity(-200);
IntEnable();
T0Start();
}
	while(1)
	WdtCls();

 ----------------------------------------------------------*/

HMotorOut(A3279INITATE) ;
HMotorOut(A3279INITATE) ;


while(1)
//for(y=0;y<50;++y)
	{ 
	 for(count=0;count<4;count++)
{
for(x=0;x<10;x++)
WdtCls();
HMotorOut(SIN4[count]) ;
}
} 
while(1)
	WdtCls();
/*---------------------------步距角部分---------------
----------------------------------------------------------*/


	programFlyOff=1;//进入正常设置
	IntSet();  
	cKeyCodeReceiveState=0;		  //复位接收状态
	pKeyCode=sKeyCode;				 //接收码清零程序
				 for(x=0;x<5;x++)					 //预设20个字符
				 {
					 *pKeyCode =0;
				     ++pKeyCode ;
				 }
				 pKeyCode=sKeyCode;	   //重新指向代码
		while(1)
	WdtCls();
	switch(cameraType)  				 //与说明手册上控制位一致
	
	{
	 default:  goto ERRor;

 case 0:	//SONY   
  		while(1)
			 {	
		
			 	 WdtCls();	
 			if(0!=cameraType)   // 利用协议出错处理
			 goto ERRor;
			if(!cKeyCodeReceiveState)  	continue;
		
			if(0xff!=cKeyCodeReceive)
			{
				 cKeyCodeReceiveState=0;
				 continue;					//首码错则结束  进  入  循  环
				 }
		
			   cKeyCodeReceiveState=0; 
				while(!cKeyCodeReceiveState)  //读码等待
								 {
									 _nop_();
								 }
								 x=0;
								 x=cKeyCodeReceive;

 				 while(!cKeyCodeReceiveState)  //读码等待
								 {
									 _nop_();
								 }
								 x+=(cKeyCodeReceive<<8);
								 cKeyCodeReceiveState=0; //取走键盘码		 
							 
						WdtCls();
				  	   	switch(x)
								{
								case	0x0200:		  //光圈开
								TxdString(IRISOPEN);
								break;
								case	0x0400:		  //光圈关
								TxdString(IRISCLOSE);
								break;	
								case	0x0100:		  //焦距拉近
								TxdString(FOCUSNEAR);
								break;
								case	0x0080:		  //焦距拉远
								TxdString(FOCUSFAR);
								break;
								case	0x0040:		  //视角宽
								TxdString(ZOOMWIDE);
								break;
								case	0x0020:		  //视角窄
								TxdString(ZOOMTELE);
								break;
								case	0x0008:		  //向上	
								TxdString(UP);
								break;
								case	0x0010:		  //向下	   
								TxdString(DOWN);
								break;
								case	0x0004:		  //向左	
								TxdString(LEFT);
								break;
								case	0x0002:		  //向右
								TxdString(RIGHT);
								break;	
								case	0:		  //结束所有运动   标准的
								TxdString(STOP);
								break;
								default :break;
								}			
		
				}	 				//end case while rotate
			break; //finish case 

	 


	}   //switch cProtocol end

}   //end main			 
				 
  	
								
	
  
	
		
		void receive_send(void) interrupt 	SIO_VECTOR
		{	
		   
			switch((char)RI)
			{
			case 1:
				
				RI=0;
				cKeyCodeReceiveState=1; //有接收时就置位	然后在主程序中清除
				cKeyCodeReceive=SBUF;
				break;	
							
			case 0:
				TI=0;
				if(flagTxd==0xff)
				{
				 SBUF=(unsigned char)(comTxd>>countTxd);
				 countTxd+=8;
				 if(countTxd==16)
				  flagTxd=0xee;
				  }
				  break;				
			}	
		}
	
		   	
		void UpLim(void) interrupt IE0_VECTOR 			//上下方向
		{
		 ET0=0;
		}
		
		void DownLim(void) interrupt IE1_VECTOR
			
		{
    	ET0=1;
		}
	
		void HorizonalOrigin(void) interrupt IE2_VECTOR			//水平方向
		{
		 T2Stop();
		 hAbsolutionPosition=0;
		}				
		
		

void verticalmotor(void) interrupt TF0_VECTOR
{
	static 	unsigned char currentCount=0;
	static 	unsigned char accDecCount=0;
	TL0=-250;

//	if(!vSoftTimer0++)
	{	
		switch(vRotationManner)
		{
		default:break;
		case FREEMOTION:
			{
				switch(vOrientFlag)
				{
				default:break;
				case 1:
					{
						switch(vaccDecFlag)
						{
						default :break;
						case ACCELERATION:
							if(currentCount==15)
								currentCount=0;
							else
								++currentCount;
							VMotorOut(SIN16[currentCount]) ;
							++vAbsolutionPosition;
							if(accDecCount==15)
							{
								vSoftTimer0=ACCTABLE[accDecCount]/250;
								accDecCount=0;
								vaccDecFlag=NORMALMOTION;
							}
							else
							{
							vSoftTimer0=ACCTABLE[accDecCount]/250;
								++accDecCount;
							}				
							break;
						case NORMALMOTION:
							if(currentCount==15)
								currentCount=0;
							else
								++currentCount;
							VMotorOut(SIN16[currentCount]) ;
							++vAbsolutionPosition;
							vSoftTimer0=-5;
							
							break;
							
						} 			
						break;
					}
				case -1:
					{
						switch(vaccDecFlag)
						{
						default :break;
						case ACCELERATION:
							if(currentCount==0)
								currentCount=15;
							else
								--currentCount;
							VMotorOut(SIN16[currentCount]) ;
							--vAbsolutionPosition;
							if(accDecCount==15)
							{
								vSoftTimer0=ACCTABLE[accDecCount]/250;
								accDecCount=0;
								vaccDecFlag=NORMALMOTION;
							}
							else
							{
								vSoftTimer0=ACCTABLE[accDecCount]/250;
								++accDecCount; 				
							}
							
							break;
						case NORMALMOTION:
							if(currentCount==0)
								currentCount=15;
							else
								--currentCount;
							VMotorOut(SIN16[currentCount]) ;
							--vAbsolutionPosition;
							vSoftTimer0=-5;
						
							break;
							
						} 			
						break;
					}
				}
				break;
			}
			
		case DOUBLEMOTION  :
			if(!vOrientFlag)
			{
				if(vPresetPosition>vAbsolutionPosition)
					vOrientFlag=1;
				//	else	if(vPresetPosition==vAbsolutionPosition)  TR2=0;
				else 
					vOrientFlag=-1;
			}
			//
			switch(vOrientFlag)
			{
			default:break;
				
			case 1:
				{
					switch(vaccDecFlag)
					{
					default :break;
					case PAUSE:
						if(!(vPauseTime--))
						{
							vaccDecFlag=ACCELERATION;
							if(vAbsolutionPosition==vPresetPosition1)
								vPresetPosition=vPresetPosition2;
							else
								vPresetPosition=vPresetPosition1;
							vOrientFlag=0;
						}
						break;
					case DECELERATION:
						if(currentCount==15)
							currentCount=0;
						else
							++currentCount;
						VMotorOut(SIN16[currentCount]) ;
						
						++vAbsolutionPosition;
						if(accDecCount==15)
						{
							vSoftTimer0=DECTABLE[accDecCount]/250;
							accDecCount=0;
							vaccDecFlag=PAUSE;
							vPauseTime=200;
							VMotorOut(SIN16[currentCount]) ;
							
						}
						else
						{
							vSoftTimer0=DECTABLE[accDecCount]/250;
							++accDecCount;				
						}
						
						//	VMotorOut(SIN16[currentCount-1]) ;				
						break;
					case ACCELERATION:
						if(currentCount==15)
							currentCount=0;
						else
							++currentCount;
						VMotorOut(SIN16[currentCount]) ;
						
						++vAbsolutionPosition;
						if(accDecCount==15)
						{
							vSoftTimer0=ACCTABLE[accDecCount]/250;

⌨️ 快捷键说明

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