?? main.c
字號:
/*---------------------------------
記住調(diào)整ID時鍵盤發(fā)的碼和PELCO有點相同,程序要加識別處理的
-----------------------------------*/
/*-----------------------------------------------
明景的鍵盤PELCO-P球機ID為實際球機ID少1,程序要進行處理
PELCO-D上下兩代碼顛倒了,UP為000 DOWN 為00108 與公布的相反
------------------------------------------------*/
#include <general.h> //定義外部的函數(shù)
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; //初值處于無串口碼接收到狀態(tài)有值用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時間基數(shù)太小要在中斷里作一個軟計時處理
}
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時間基數(shù)太小要在中斷里作一個軟計時處理
}
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; //初始化發(fā)送器狀態(tài)變量
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; //首碼錯則結(jié)束 進 入 循 環(huán)
}
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;
}
} //判斷是否程度跑飛進行串口初始波特接著進行有關(guān)初始定位工作,直到定位完成將跑飛標志置位
-----------------------*/
/*---------------------------水平位檢測部分-----------------
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;//進入正常設(shè)置
IntSet();
cKeyCodeReceiveState=0; //復(fù)位接收狀態(tài)
pKeyCode=sKeyCode; //接收碼清零程序
for(x=0;x<5;x++) //預(yù)設(shè)20個字符
{
*pKeyCode =0;
++pKeyCode ;
}
pKeyCode=sKeyCode; //重新指向代碼
while(1)
WdtCls();
switch(cameraType) //與說明手冊上控制位一致
{
default: goto ERRor;
case 0: //SONY
while(1)
{
WdtCls();
if(0!=cameraType) // 利用協(xié)議出錯處理
goto ERRor;
if(!cKeyCodeReceiveState) continue;
if(0xff!=cKeyCodeReceive)
{
cKeyCodeReceiveState=0;
continue; //首碼錯則結(jié)束 進 入 循 環(huán)
}
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: //光圈關(guān)
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: //結(jié)束所有運動 標準的
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;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -