📄 shixu.c
字号:
/*
**********************************************************************
函数:void hand_ctrl(void)
功能:综合板上报最新手动控制相位信息
说明:单键模式,组合模式,直接传给驱动控制
**********************************************************************
*/
void hand_ctrl(void)
{
rx_zonghe = 0;//clear symbol
if(zonghe_buff[1] == 0x2B)
{
goto aut_bk;
}
else if((zonghe_buff[1] == 0x29)||(zonghe_buff[1] == 0x2A))
{
goto cmb;
}
if((zonghe_buff[0]&0x0F) != 9)
{
cmb:
event[1] = t_rd;/*记录最新进入手动时间*/
eve_r = 1;
if((zonghe_buff[0]&0x80) == 0x80) info.ctrl = IN_RF;
else info.ctrl = IN_KEY;
in_hand = 1;
sbuff_CAN[0] = QUDONG;
sbuff_CAN[1] = LANE_CTRL;
sbuff_CAN[2] = 2;
sbuff_CAN[3] = zonghe_buff[0]&0x1F;
sbuff_CAN[4] = zonghe_buff[1];
tx_CAN(1);
}
else
{
aut_bk:
event[2] = t_rd;/*记录最新返回自动时间*/
eve_r = 1;
info.ctrl = IN_AUTO;
in_hand = 0;
}
}
/*
**********************************************************************
函数:void io_output(void)
功能:io输出
说明:
**********************************************************************
*/
void io_output(void)
{
sbuff_CAN[0] = out_unit+3;
if(out_value == 1)
{
sbuff_CAN[1] = IO_PULSE;
}
else
{
sbuff_CAN[1] = IO_STAND;
}
sbuff_CAN[2] = 1;
sbuff_CAN[3] = out_value;
tx_CAN(0);
out_ON = 0;
}
/*
**********************************************************************
函数:void read_io(void)
功能:读取通讯单元1,2状态
说明:
**********************************************************************
*/
void read_io(void)
{
iotx_EN = 0;
sbuff_CAN[0] = TONGX1;
sbuff_CAN[1] = IO_STATE;
sbuff_CAN[2] = 0;
// transmit_CAN();
tx_CAN(0);
sbuff_CAN[0] = TONGX2;
sbuff_CAN[1] = IO_STATE;
sbuff_CAN[2] = 0;
// transmit_CAN();
tx_CAN(0);
}
/*
**********************************************************************
函数:void read_loop(void)
功能:读取检测单元状态
说明:
**********************************************************************
*/
void read_loop(void)
{
loop_EN = 0;
sbuff_CAN[0] = JIANCE;
sbuff_CAN[1] = LOOP_STATE;
sbuff_CAN[2] = 2;
sbuff_CAN[3] = wait_time;
sbuff_CAN[4] = intev_time;
// transmit_CAN();
tx_CAN(0);
}
/*
**********************************************************************
函数:void read_door(void)
功能:读取灯态
说明:
**********************************************************************
*/
void read_lamp(void)
{
lamp_EN = 0;
sbuff_CAN[0] = QUDONG;
sbuff_CAN[1] = LAMP_STATE;
sbuff_CAN[2] = 0;
// transmit_CAN();
tx_CAN(0);
}
/*
**********************************************************************
函数:void read_door(void)
功能:读取灯态
说明:
**********************************************************************
*/
void read_door(void)
{
unsigned char data i,temp;
temp = info.volt;
if (!VOLTH) info.volt = 1;
else if(!VOLTL) info.volt = 2;
else info.volt = 0;
if(info.volt != temp)
{
eve_r = 1;
if (info.volt == 0) i = 3;
else if(info.volt == 1) i = 4;
else i = 5;
event[i] = t_rd;
}
temp = door_state;
door_state = DOOR;
if((door_state&0x01) != (temp&0x01))
{
eve_r = 1;
if(door1) i = 6;
else i = 7;
event[i] = t_rd;
}
if((door_state&0x02) != (temp&0x02))
{
eve_r = 1;
if(door2) i = 8;
else i = 9;
event[i] = t_rd;
}
if((door_state&0x04) != (temp&0x04))
{
eve_r = 1;
if(door3) i = 10;
else i = 11;
event[i] = t_rd;
}
info.door1 = door1;
info.door2 = door2;
info.door3 = door3;
}
/*
**********************************************************************
函数:void time_clock(void)
功能:时钟(修正)
**********************************************************************
*/
void time_clock(void)
{
clock_EN = 0;
rep_time();
if(!read_time())
{
t_rd = runtime;
t_wr = runtime;
set_normaltime();
}
}
/*
**********************************************************************
函数:void power_on(void)
功能:开机通讯检测
说明:查询系统节点是否存在
**********************************************************************
*/
void power_on(void)
{
sbuff_CAN[0] = QUDONG;
sbuff_CAN[1] = POWERON;
sbuff_CAN[2] = 2;
sbuff_CAN[3] = trns_freq;
sbuff_CAN[4] = flsh_times;
tx_CAN(1);
}
/*
**********************************************************************
函数:void begin(void)
功能:所有变量参数初始化赋值
说明:
**********************************************************************
*/
void begin(void)
{
unsigned char data i;
set_alarmtime(0,0);
for(i = 0; i < 5; i++)
{
bus[i] = OFF;
err[i] = 0;
}
rx_UART0 = 0;
rx232_len0 = 0;
rx_UART1 = 0;
rx232_len1 = 0;
clock_EN = 1;
info.ctrl = IN_AUTO;
err_unit = 0;
led_now = 0xFF;
IE = 0xD7;//open interrupt
}
/*
**********************************************************************
函数: void UART_Init(void)
功能: 初始化CPU,定时器、串口
说明:
**********************************************************************
*/
void CPU_Init(void)
{
IP = 0x00;
IE = 0x00;
TMOD = 0x21;
SCON1 = 0x50;
SCON0 = 0x50;
TH1 = 0xFD;
TCON = 0x50;
PCON = 0x80;
// CKCON = 0x04;
WDCON = 0x80;
TH0 = 0x4C;
TL0 = 0x00;
}
/*
**********************************************************************
函数:void main(void)
功能:主程序
说明:
**********************************************************************
*/
void main(void)
{
watchdog();
CPU_Init();
DS887_Init();
while(SJA1000_Init());
begin();
power_on();
while(1)
{
if(dog_feed) watchdog();
if(sja_check) check_sja();
if(rx_UART0) deal_UART0();
if(rx_UART1) deal_UART1();
if(clock_EN) time_clock();
if(lamp_EN) read_lamp();
if(iotx_EN) read_io();
if(loop_EN) read_loop();
if(door_EN) read_door();
if(out_ON) io_output();
if(rx_zonghe)
{
hand_ctrl();
}
else if((!in_hand)&(in_uart))
{
uart_ctrl();
}
else if(symb_out)
{
output_symb();
}
else if(slf_tst)
{
test_lamp();
}
}
}
/*
**********************************************************************
函数:void timer0(void)
功能:定时器0中断服务,50ms定时
说明:
**********************************************************************
*/
void timer0(void) interrupt 1 //using 1
{
TH0 = 0x4C;
TL0 = 0x16;
dog_feed = 1;
t0_count++;
millisecond++;
if(t0_count % 5 == 0) lamp_EN = 1;
// if(t0_count % 7 == 0) iotx_EN = 1;
if(t0_count % 3 == 0) loop_EN = 1;
if(t0_count % 17 == 0) door_EN = 1;
if(t0_count % 20 == 0)
{
t0_count = 0;
clock_EN = 1;
sja_check = 1;
if(info.ctrl != IN_AUTO) led_now &= ~OUT_AUTO;
else led_now |= OUT_AUTO;
LED = led_now;
}
}
/*
-----------------文件信息---------------------------------------------
文 件 名: shixu.c
版 本: V1.0
创 建 人: 张荣贤
最后修改日期: 2005-9-16
描 述: OK!
----------------------------------------------------------------------
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -