📄 gunza.c
字号:
/**********************************************************************/
/*Title:辊闸驱动板 */
/*author:guoyahui */
/*Date:9/22-2006 */
/*Version:1.0 */
/**************************
初始化
初始化端口
自检,提示
工作到初始位
{
4开关量处理
通行处理流程
计时功能
通讯功能
显示功能
}
****************************/
//#include <REG52.H>
//#include<absacc.h>
#include<gunza.h>
#define KTIME 2
#define WTIME 20
#define ASKTIME 20
#define MTIME2 3
#define _UserType 0
//#define MTIME 6
#define B38400 1
#define B19200 2
#define B9600 3
#define B4800 4
#define B2400 5
unsigned char ErrFlag,WaitFlag,OpenFlag;
unsigned char MTIME=6;
unsigned char PassCount1,PassCount2,K3Count;
unsigned char LedCount,LedTime,TimeCount;
unsigned int AllCome1,AllCome2,WaitTime,TestTime;
bit K1State,K2State,K3State,K4State,K9State,K10State;
bit K11State,K12State,K13State,K14State;
bit K1StateOld,K2StateOld,K3StateOld,K4StateOld,K9StateOld,K10StateOld;
unsigned char RxdCount,TxdCount,TxdLen,RxdFlag;
unsigned char RxdBuffer[10];
unsigned char TxdBuffer[10];
uchar code ver_data[]={"2006.10.13;Ver:1.0.0"};
/***********************************************************************
波特率选择*/
void fosc(uchar i)
{
T2CON=0x34;
if(i==B38400)
{
RCAP2H=0xFF; //38400
RCAP2L=0xee;
TH2=0xFF;
TL2=0xee;
}
else if(i==B19200)
{
RCAP2H=0xFF; //19200;
RCAP2L=0xDC;
TH2=0xFF;
TL2=0xDC;
}
else if(i==B9600)
{
RCAP2H=0xff; //9600
RCAP2L=0xb9;
TH2=0xff;
TL2=0xb9;
}
else if(i==B4800)
{
RCAP2H=0xff; //4800
RCAP2L=0x73;
TH2=0xff;
TL2=0x73;
}
}
void iniport() /*初始化端口*/
{
TR2=0; /*禁止T2中断*/
SCON=0x50; //
fosc(B9600); /*设置串口波特率9600*/
TMOD=0x11; /*定时器1模式2,定时器0模式1*/
TL0=0x00; /*定时器T0定时为25ms*/
TH0=0x4C;
PS=1; /*串行口中断申明为高优先级中断*/
EA=1; /*允许CPU开放所有中断*/
ES=1; /*允许串行口中断*/
ET0=1; /*允许定时/计数器T0中断*/
ET1=1; /*允许定时/计数器T1中断*/
TR0=0; /*禁止T0中断*/
TR1=0;
TR2=1; /*开T2中断,启动定时器T2*/
IT1=0; /*IT1设置为边沿触发*/
EX1=1; /*允许外中断1中断*/
PX1=1; /*申明外中断1为高优先级中断*/
AllCome1=0; //
AllCome2=0; //
}
void iniio(void) /*初始化各IO口*/
{
SET1=1;
SET2=1;
SET3=1;
SET4=1;
PW1=0;
PW2=0;
K9=1;
K10=1;
KIN1=1;
KIN2=1;
KIN3=1;
KIN4=1;
KJ5=1;
KJ6=1;
KJ5=1;
KJ6=1;
LED1=0;
LED2=0;
LED3=0;
LED4=0;
REALY1=1;
REALY2=1;
DOGWATCH=1;
}
/*
void time(uchar x)
{
uint y;
y=(uint)x*10;
while((y--)!=0);
}*/
void wait_time(uchar bb)
{
TimeCount=bb;
while(TimeCount!=0){
DOGWATCH=~DOGWATCH;
}
}
unsigned char open_inM(void)
{
if((KJ5==0)&&(KJ6==1))
{
SET4=1;
SET3=1;
PW2=0;
}
else
{
SET3=0;
SET4=1;
PW2=1;
TimeCount=MTIME;
while(TimeCount!=0){
if(TimeCount==5)
SET3=0;
else if(TimeCount==4)
SET3=0;
else if(TimeCount==1)
SET3=0;
else
SET3=1;
}
PW2=0;
SET3=1;
}
if((KJ5!=0)||(KJ6!=1))
ErrFlag=ErrFlag|0x10;
}
unsigned char close_inM(void)
{
if((KJ5==1)&&(KJ6==0))
{
SET3=1;
SET4=1;
PW2=0;
}
else
{
SET4=1;
SET3=1;
PW2=1;
TimeCount=MTIME;
while(TimeCount!=0){
if(TimeCount==5)
SET4=0;
else if(TimeCount==4)
SET4=0;
else if(TimeCount==1)
SET4=0;
else
SET4=1;
}
PW2=0;
SET4=1;
}
if((KJ5!=1)||(KJ6!=0))
ErrFlag=ErrFlag|0x10;
}
unsigned char open_outM(void)
{
if((KJ7==0)&&(KJ8==1))
{
SET1=1;
SET2=1;
PW1=0;
}
else
{
SET2=1;
SET1=1;
PW1=1;
TimeCount=MTIME;
while(TimeCount!=0){
if(TimeCount==5)
SET2=0;
else if(TimeCount==4)
SET2=0;
else if(TimeCount==1)
SET2=0;
else
SET2=1;
}
PW1=0;
SET2=1;
SET1=1;
}
if((KJ7!=0)||(KJ8!=1))
ErrFlag=ErrFlag|0x20;
}
unsigned char close_outM(void)
{
if((KJ7==1)&&(KJ8==0))
{
SET1=1;
SET2=1;
PW1=0;
}
else
{
SET1=1;
SET2=1;
PW1=1;
TimeCount=MTIME;
while(TimeCount!=0){
if(TimeCount==5)
SET1=0;
else if(TimeCount==4)
SET1=0;
else if(TimeCount==1)
SET1=0;
else
SET1=1;
}
PW1=0;
SET1=1;
SET2=1;
}
if((KJ7!=1)||(KJ8!=0))
ErrFlag=ErrFlag|0x20;
}
void checkme(void)
{
ErrFlag=0;
// if(P0!=0xff)
// ErrFlag=ErrFlag|0x01;
//if(P1!=0xff)
// ErrFlag=ErrFlag|0x02;
//((KIN1==0)||(KIN2==0)||(KIN3==0)||(KIN4==1))
// ErrFlag=ErrFlag|0x04;
if((KJ6==0)&&(KJ5==0))
ErrFlag=ErrFlag|0x10;
if((KJ6==1)&&(KJ5==1))
ErrFlag=ErrFlag|0x10;
if((KJ8==0)&&(KJ7==0))
ErrFlag=ErrFlag|0x20;
if((KJ8==1)&&(KJ7==1))
ErrFlag=ErrFlag|0x20;
if(WaitFlag==0)
{
close_inM();
close_outM();
}
else if(WaitFlag==1)
{
open_inM();
close_outM();
}
else if(WaitFlag==2)
{
close_inM();
open_outM();
}
else if(WaitFlag==3)
{
open_inM();
close_outM();
}
else if(WaitFlag==4)
{
close_inM();
open_outM();
}
else if(WaitFlag==5)
{
open_inM();
open_outM();
}
}
void AskCome1(void)
{
REALY1=0;
wait_time(ASKTIME);
REALY1=1;
}
void AskCome2(void)
{
REALY2=0;
wait_time(ASKTIME);
REALY2=1;
}
void send_useri(void)
{
uchar i;
}
void send_ver()
{
uchar i,xx,l;
}
/**************中断函数******************/
void timer1(void)interrupt 3 using 3 {
/*T1中断服务程序入口*/
uchar i,l;
TH1=100;
TL1=100;
}
void timer0(void)interrupt 1 using 1 /*T0中断服务程序入口*/
{
TL0=0x00; /*定时器T0定时为3ms*/
TH0=0xb8;//0xB8;
if(TimeCount>0)
TimeCount--;
if(WaitTime<2000)
WaitTime++;
if(LedTime<200)
LedTime++;
}
void serial(void) interrupt 4 using 2 /*串口中断*/
{
unsigned char i;
if(RI!=0)//接收中断
{
RI=0;
i=SBUF;
if(i==0x0d)
{
RxdFlag=1;
RxdCount=0;
}
else
{
if((RxdFlag==0))
{
if(RxdCount<20)
{
RxdBuffer[RxdCount]=i;
RxdCount++;
}
else
{
RxdCount=0;
}
}
}
}
else
{
if(TI!=0) /*发送中断*/
{
TI=0;
if(TxdCount<TxdLen)
{
TxdCount++;
SBUF=TxdBuffer[TxdCount];
}
else
{
RxdCount=0;
TxdCount=0;
}
}
}
}
void key_main(void)
{
if(K1State==0)//in入口操作
{
if(KIN1==0)
{
wait_time(KTIME);
if(KIN1==0)
{
PassCount1++;
K1State=1;
}
}
}
else
{
if(KIN1==1)
{
wait_time(KTIME);
if(KIN1==1)
{
K1State=0;
}
}
}
if(K2State==0)//out出口操作
{
if(KIN2==0)
{
wait_time(KTIME);
if(KIN2==0)
{
PassCount2++;
K2State=1;
}
}
}
else
{
if(KIN2==1)
{
wait_time(KTIME);
if(KIN2==1)
{
K2State=0;
}
}
}
if(K3State==0)//in-out自由出入操作
{
if(KIN3==0)
{
wait_time(KTIME);
if(KIN3==0)
{
if(K3Count<3)
K3Count++;
else
K3Count=0;
K3State=1;
}
}
}
else
{
if(KIN3==1)
{
wait_time(KTIME);
if(KIN3==1)
{
K3State=0;
}
}
}
if(K4State==1)//back
{
if(KIN4==1)
{
wait_time(KTIME);
if(KIN4==1)
{
K4State=0;
}
}
}
else
{
if(KIN4==0)
{
wait_time(KTIME);
if(KIN4==0)
{
OpenFlag=1;
K4State=1;
}
}
}
if(K9State==0)//come
{
if(K9==0)
{
wait_time(KTIME);
if(K9==0)
{
MTIME--;
K9State=1;
}
}
}
else
{
if(K9==1)
{
wait_time(KTIME);
if(K9==1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -