📄 back.c
字号:
/*---------------------------------
记住调整ID时键盘发的码和PELCO有点相同,程序要加识别处理的
-----------------------------------*/
#include <general.h> //定义外部的函数
#define SUMSUNG 1
#define PELCOP 2
#define PELCOD 12
#define B01 8
#define YAAN 7
struct structSwitchStatus
{
unsigned char id;
unsigned char protocol;
unsigned char rxdBaud;
unsigned char cameraBaud;
unsigned char cameraType;
};
struct structSwitchStatus GetSwitchStatus()
{
struct structSwitchStatus statu;
unsigned char bdata bflag; //通用位变量
sbit bflag_0=bflag^0;
sbit bflag_1=bflag^1;
sbit bflag_2=bflag^2;
sbit bflag_3=bflag^3;
sbit bflag_4=bflag^4;
sbit bflag_5=bflag^5;
sbit bflag_6=bflag^6;
sbit bflag_7=bflag^7;
bflag=0;
ID0=ID1=ID3=ID4=ID05=ID6=1;
bflag_0=!ID0 ;bflag_1=!ID1 ;bflag_2=!ID2 ;bflag_3=!ID3 ;bflag_4=!ID4 ;
bflag_5=!ID5 ;bflag_6=!ID6 ;
status.id=bflag;
bflag=0;
PROTOCOL0=PROTOCOL1=PROTOCOL02=PROTOCOL03=1;
bflag_0=!PROTOCOL03 ;bflag_1=!PROTOCOL02 ;bflag_2=!PROTOCOL1;bflag_3=!PROTOCOL0 ;
status.protocol=bflag;
bflag=0;
BAUD0=BAUD1=1;
bflag_0=!BAUD1 ; bflag_1=!BAUD0 ;
status.rxdBaud=bflag;
bflag=0;
CAMBAUD0=CAMBAUD1=1;
bflag_0=!CAMBAUD1 ; bflag_1=!CAMBAUD0 ;
status.cameraBaud=bflag;
bflag=0;
CAMERA0=CAMERA1=1;
bflag_0=!CAMERA1 ; bflag_1=!CAMERA0 ;
status.cameraType=bflag;
return(statu);
}
volatile unsigned char bdata bflag1; //通用位变量
sbit bflag1_0=bflag1^0;
sbit bflag1_1=bflag1^1;
sbit bflag1_2=bflag1^2;
sbit bflag1_3=bflag1^3;
sbit bflag1_4=bflag1^4;
sbit bflag1_5=bflag1^5;
sbit bflag1_6=bflag1^6;
sbit bflag1_7=bflag1^7;
/*-----------------------------------------------
明景的键盘PELCO-P球机ID为实际球机ID少1,程序要进行处理
PELCO-D上下两代码颠倒了,UP为000 DOWN 为00108 与公布的相反
------------------------------------------------*/
volatile unsigned char cProtocol;
volatile unsigned char bdata id; //通用位变量
sbit id_0=id^0;
sbit id_1=id^1;
sbit id_2=id^2;
sbit id_3=id^3;
sbit id_4=id^4;
sbit id_5=id^5;
sbit id_6=id^6;
sbit id_7=id^7;
unsigned char idata sKeyCode[20]={""}; //目前只用一组来表示,并且为0值 接收键盘码用
volatile unsigned char idata cKeyCodeReceiveState; //初值处于无串口码接收到状态有值用1表示
volatile unsigned char idata cKeyCodeReceive;
unsigned char idata *pKeyCode;
unsigned char ProtocolSelect()
{ unsigned char x;
bflag1=0;
PROTOCOL0=PROTOCOL1=PROTOCOL2=PROTOCOL3=1; //写1
do
{
bflag1_0=!PROTOCOL3; //选择通讯协议 取反
bflag1_1=!PROTOCOL2;
bflag1_2=!PROTOCOL1;
bflag1_3=!PROTOCOL0;
x= bflag1;
bflag1_0=!PROTOCOL3; //选择通讯协议 取反
bflag1_1=!PROTOCOL2;
bflag1_2=!PROTOCOL1;
bflag1_3=!PROTOCOL0;
}while(bflag1!=x);
return(x);
}
void BaudSelect() //波特率选择 子程序
{
unsigned char x; //开关取反才是正确的
bflag1=0;
BAUD0 =1; //先给1
BAUD1 =1;
do
{
bflag1_0=!BAUD1; //选择波特率
bflag1_1=!BAUD0;
x=bflag1;
bflag1_0=!BAUD1; //选择波特率
bflag1_1=!BAUD0;
}while(bflag1!=x);
bflag1=x;
switch(bflag1) //与说明手册上控制位一致
{
case 0:
baud_2400();
break;
case 2:
baud_4800();
break;
case 1:
baud_9600();
break;
case 3:
baud_19200();
break;
}
}
void IdSelect() //球机ID选择子程序
{
unsigned char x;
x=0;
ID0=ID1=ID2=ID3=ID4=ID5=ID6=1; // 先给1 按从左到右的BCD方式
id=0;
do
{
id_0=!ID0; //10位拨码开关的右8 位按BCD排列
id_1=!ID1;
id_2=!ID2; //可选择256位
id_3=!ID3;
id_4=!ID4; //P0-6 P1-0两位可作它用 ,如果有相机选择可减少ID位数
id_5=!ID5;
id_6=!ID6;
x=id;
id_0=!ID0; //10位拨码开关的右8 位按BCD排列
id_1=!ID1;
id_2=!ID2; //可选择256位
id_3=!ID3;
id_4=!ID4; //P0-6 P1-0两位可作它用 ,如果有相机选择可减少ID位数
id_5=!ID5;
id_6=!ID6;
}while(id!=x);
id=x; // 正式有上面的,没有此项
}
/*
void CameraParameterSend()
{
//此程序通过串口发送消息告诉相机类型及波特率,如何编写要作安排
}
还有相机的种类及波特程序安排
void AlarmControl()
{
//此程序留作考虑
}
*/
void main()
{
unsigned int x;
unsigned long y;
ERRor: //修改出错地址
for(y=0;x<0xffffffff;y++)下作不易发出误码的
WDT_cls();
GlobalSet();
IntDisable();
T0Stop();
T1Stop();
T2Stop();
IntSet();
TimerSet();
SciSet();
IntEnable();
SciTxdBaudSet();
T1_start();
BaudSelect(); //波特选择 程序波特及ID可随时选
T2_start();
IdSelect(); //ID选择
cKeyCodeReceiveState=0; //复位接收状态
pKeyCode=sKeyCode; //接收码清零程序
for(x=0;x<20;x++) //预设20个字符
{
*pKeyCode =0;
++pKeyCode ;
}
pKeyCode=sKeyCode; //重新指向代码
cProtocol= ProtocolSelect();
/* while(1)
{
WDT_cls();
for(x=0;x<1000;x++);
SBUF=cProtocol;
}
*/
switch(cProtocol) //与说明手册上控制位一致
{
default: goto ERRor;
/*____________________999999999999999999______________________________
三星协议开始
_______________________9999999999999999_______________________________*/
case PELCOD:
while(1)
{
WDT_cls();
if(PELCOD!=cProtocol) // 利用协议出错处理
goto ERRor;
if(!cKeyCodeReceiveState) continue;
/*__________________________________________switch begin________________
以下是接收的串口数据程序员
__________________________________________________________*/
if(0xff!=cKeyCodeReceive)
{
cKeyCodeReceiveState=0;
continue; //首码错则结束 进 入 循 环
}
cKeyCodeReceiveState=0;
while(!cKeyCodeReceiveState)
{
WDT_cls();
}
if( cKeyCodeReceive!=id) //说明是正确的键盘码转入处理程序
{ //不是本球机的接收码ID不正确或者是一误码都必须会结束
cKeyCodeReceiveState=0;
continue; //处理并且清除接收标志
}
x=2;
pKeyCode=sKeyCode;
*pKeyCode=0xff; //起始同步码
++pKeyCode;
*pKeyCode=id; //ID码
cKeyCodeReceiveState=0;//已取走第2个码
do
{
// x=x+*pKeyCode ; //从第二个开始累加校验
while(!cKeyCodeReceiveState) //读码等待
{
_nop_();
}
++pKeyCode;
*pKeyCode=cKeyCodeReceive;
cKeyCodeReceiveState=0; //取走键盘码
++x;
}while(x!=7); //读码结束标志
/*__________________________________________switch end________________
以上是接收的串口数据程序员
__________________________________________________________*/
/*-----------------------------------------------------
下面是发送解码后处理程序 发送时按查询方式进行,修改串口中断程序
________________________________________________________*/
/*-----------------------------------------------------
if( sKeyCode[3]==0x55) continue;
y= (sKeyCode[2]<<24)+(sKeyCode[3]<<16)+(sKeyCode[4]<<8)+sKeyCode[5];
//构造一译码关键字
WDT_cls();
上面是发送解码后处理程序
________________________________________________________*/
} //end case while rotate
break; //finish case
/*____________________999999999999999999______________________________
PELCOD协议结束
_______________________9999999999999999_______________________________*/
case SUMSUNG: //三星协议
while(1)
{
WDT_cls();
if(SUMSUNG!=cProtocol) // 利用协议出错处理
goto ERRor;
if(!cKeyCodeReceiveState) continue;
/*__________________________________________switch begin________________
以下是接收的串口数据程序员
__________________________________________________________*/
if(0xa0!=cKeyCodeReceive)
{
cKeyCodeReceiveState=0;
continue; //首码错则结束 进 入 循 环
}
cKeyCodeReceiveState=0;
while(!cKeyCodeReceiveState)
{
WDT_cls();
}
cKeyCodeReceiveState=0;
while(!cKeyCodeReceiveState)
{
WDT_cls();
}
if( cKeyCodeReceive!=id) //说明是正确的键盘码转入处理程序
{ //不是本球机的接收码ID不正确或者是一误码都必须会结束
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -