?? secondccc
字號:
#include <second.h>
/*****************************************************************************************************/
// 讀時間
/*****************************************************************************************************/
void read_time() {
now_day = XBYTE[0XC006]; /*星期*/
now_year= XBYTE[0XC009]; /*年份*/
now_month=XBYTE[0XC008]; /*月份*/
now_date= XBYTE[0XC007]; /*日子*/
now_hour= XBYTE[0XC004]; /*小時*/
now_min = XBYTE[0XC002]; /*分鐘*/
now_sec = XBYTE[0XC000]; /*秒*/
now_time=now_hour*60+now_min;
if(end_time<begin_time)
{
if((now_time>=begin_time) || (now_time<end_time))
work_time=1;
else
work_time=0;
}
else if(end_time>begin_time)
{
if((now_time>=begin_time) && (now_time<end_time))
work_time=1;
else
work_time=0;
}
else
work_time=0;
}
/*------------求最大值-----------------------*/
//max(array_time)
//uchar array_time[16];
//{
// uchar max_value,k;
// max_value=array_time[0];
// for(k=1;k<16;k++)
// {
// if(array_time[k]>max_value)
// max_value=array_time[k];
// }
// return(max_value);
//}
/*------------------------------------------*/
uchar search_step_time() using 1 //計算感應控制階段時間=最小綠燈+紅燈+黃燈
{
uchar i,max_time,max_temp;
uint j;
uint offset;
max_time=0;
ensensor_flag = 1;
sensor_car_flag= 0;
sensor_counter = 0; //感應控制階段開始設為0
for(i=0; i<16; i++) //此循環用于查找當前階段用到的相位
{
j = 18*i;
offset= 0x0001;
offset= offset<<i;
now_phase_temp = offset&inuse_phase[step_counter]; ////inuse_phase:階段用到的相位step_counter:階段號
now_phase_tempn = offset&inuse_phasen[step_counter];
if(now_phase_temp!=0)
{
/* if(((XBYTE[baseaddr_now_phasesch+j+2]&0x04)==0x04) && (now_phase_tempn==0)) //行人
{
max_time=XBYTE[baseaddr_now_phasesch+j+12]+XBYTE[baseaddr_now_phasesch+j+16];
//max_time:=最小綠燈+紅燈
} */
if(((XBYTE[baseaddr_now_phasesch+j+2]&0x04)!=0x04) && (now_phase_tempn==0))
{
no_vehicle_step[step_counter]=1;//該階段有無機動車標志
sensor_distance=XBYTE[baseaddr_now_phasesch+j+11];
min_greentime = XBYTE[baseaddr_now_phasesch+j+12]-XBYTE[baseaddr_now_phasesch+j+17]-sensor_distance;
// min_greentime =最小綠燈-綠閃-單位步長
max_greentime = XBYTE[baseaddr_now_phasesch+j+13]-XBYTE[baseaddr_now_phasesch+j+17];
//green_flash[i]= XBYTE[baseaddr_now_phasesch+j+17];//綠閃時間
//min_greentime = sensor_distance;//XBYTE[baseaddr_now_phasesch+j+12]-XBYTE[baseaddr_now_phasesch+j+17]-sensor_distance;
// max_greentime = XBYTE[baseaddr_now_phasesch+j+13];//;-XBYTE[baseaddr_now_phasesch+j+17];
// add_greentime = min_greentime;
//time[i] = XBYTE[baseaddr_now_phasesch+j+12]+XBYTE[baseaddr_now_phasesch+j+15]+XBYTE[baseaddr_now_phasesch+j+16];
//time:=最小綠燈+黃燈+紅燈
max_temp=XBYTE[baseaddr_now_phasesch+j+12]+XBYTE[baseaddr_now_phasesch+j+15]+XBYTE[baseaddr_now_phasesch+j+16];
if(max_temp>max_time)
max_time=max_temp;
//max_green_flash=XBYTE[baseaddr_now_phasesch+j+17];
}
}
}
//max_time=max(time);
//max_green_flash=max(green_flash);
return (max_time);
}
/*-----------------------------------**/
void max_clear_time() using 1
{
uchar now_phase_temp,i,now_phase_tempn;
uint toto;
uint phasek;
max_yellow=0;
max_red_clear=0;
max_green_flash=0;
for(i=0; i<16; i++)
{
toto = 0x0001;
toto = toto<<i;
phasek = 18*i;
now_phase_temp = toto&inuse_phase[step_counter]; //當前階段是否包含該相位
now_phase_tempn = toto&inuse_phasen[step_counter];
if((now_phase_temp!=0)&& (now_phase_tempn==0))
// if(now_phase_temp!=0)
{
if(step_counter==1)
step_counter=1;
if(max_yellow<XBYTE[baseaddr_now_phasesch+phasek+15])
max_yellow=XBYTE[baseaddr_now_phasesch+phasek+15];
if(max_red_clear<XBYTE[baseaddr_now_phasesch+phasek+16])
max_red_clear=XBYTE[baseaddr_now_phasesch+phasek+16];
if(max_green_flash<XBYTE[baseaddr_now_phasesch+phasek+17])
max_green_flash=XBYTE[baseaddr_now_phasesch+phasek+17];
}
}
}
/************計算個階段的各相位的清空時間***在每階段的開始時執行一次****************/
void cal_clear_time()
{
uchar i;
uint phasek;
for(i=0; i<16; i++)
{
phasek = 18*i;
red_clear[i] = XBYTE[baseaddr_now_phasesch+phasek+16]; //紅燈清空時間
//red_yellow_clear[i] = red_clear[i]+XBYTE[baseaddr_now_phasesch+phasek+15]; //黃燈清空時間
red_yellow_clear[i] = red_clear[i]+ max_yellow;
red_yellow_green_clear[i] = red_yellow_clear[i]+XBYTE[baseaddr_now_phasesch+phasek+17]; //行人清空時間
}
}
/*****************************************************************************************************/
// 查找燈色
/*****************************************************************************************************/
void search_color() using 1
{
uchar data i;
uint data toto,toto1,j;
for(i=0; i<16; i++)
{
toto = 0x0001;
toto = toto<<i;
if((use_lamp&toto)==toto) lamp_state[i]=4; /*使用的燈組置成紅色先*/
else lamp_state[i]=7; /*不用的燈組滅掉*/
}
cal_clear_time();//計算個階段的清空時間
if(sensor_step[step_counter]==0) //階段為固定配時
{
for(i=0; i<16; i++) //此循環用于查找當前階段用到的相位
{
j = 18*i;
toto= 0x0001;
toto1= toto<<i;
now_phase_temp = toto1&inuse_phase[step_counter]; ////inuse_phase:階段用到的相位step_counter:階段號
now_phase_tempn = toto1&inuse_phasen[step_counter];
if(now_phase_temp!=0)
{
if(((XBYTE[baseaddr_now_phasesch+j+2]&0x04)!=0x04) && (now_phase_tempn==0))
{
no_vehicle_step[step_counter]=1;//該階段有無機動車標志
}
}
}
if(re_control==1||force_flag==1) //遙控 強制
{
/* //手動***************************************
if(step_counter==hand_step-1&&hand_step_flag==1)//正在執行手動相位
{
hand_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash+1;
now_step_key=1;
}
else if((hand_state==1||hand_state==4)&&hand_step_flag==1) //尚未執行手動相位
{
hand_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash;
now_step_key=1;
}
else if(hand_state==2&&hand_step_flag==1) //尚未執行遙控相位,繼續走完本階段
{
now_uncount =max_red_clear+max_yellow+max_green_flash-now_step_key;
}
*/
//遙控****************************************
if(reph_number==3){
reph_number=3;
}
if(step_counter==reph_number-1)//正在執行遙控相位
{
remote_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash+1;
now_step_key=1;
}
else if(remote_state==1||remote_state==4) //尚未執行遙控相位
{
remote_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash;
now_step_key=1;
}
else if(remote_state==2) //尚未執行遙控相位,繼續走完本階段
{
if(no_vehicle_step[step_counter]==0)//該階段有無機動車標志
now_uncount =3-now_step_key;
else
now_uncount =max_red_clear+max_yellow+max_green_flash-now_step_key;
}
//remote_state=1:按下遙控按鍵
//remote_state=2:按下遙控按鍵后,尚未執行遙控相位,繼續走本階段時間
// 或正在執行遙控相位
//remote_state=3:按下遙控解除按鍵
//remote_state=4:按下遙控解除按鍵 繼續走完遙控階段時間
//else if(remote_state==3) //解除遙控,
// now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;
//***************強制****************************************//
else if(step_counter==force_number-1)//正在執行強制相位
{
force_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash+1;
now_step_key=1;
}
else if(force_state==1||force_state==4) //尚未執行強制相位
{
force_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash;
now_step_key=1;
}
else if(force_state==2) //尚未執行強制相位,繼續走完本階段
{
now_uncount =max_red_clear+max_yellow+max_green_flash-now_step_key;
}
//remote_state=1:按下遙控按鍵
//remote_state=2:按下遙控按鍵后,尚未執行遙控相位,繼續走本階段時間
//remote_state=3:按下遙控解除按鍵
//remote_state=4:按下遙控解除按鍵 繼續走完遙控階段時間
//else if(remote_state==3) //解除遙控,
// now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;
}
else
{
if(remote_state==3) //解除遙控
{
now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;
remote_state=4;
if(reph_number>step_num&&reph_number!=12)
remote_state=0;
}
else if(force_state==3) //解除強制
{
now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;
force_state=4;
if(force_number>step_num&&force_number!=0)
force_state=0;
}
else
now_uncount = XBYTE[baseaddr_now_schemesch+8+step_counter]-now_step_key; //查表的階段時間與當前歷時的倒計時
}
for(i=0; i<16; i++) //此循環用于查找當前階段用到的相位
{
toto = 0x0001;
toto = toto<<i;
now_phase_temp = toto&inuse_phase[step_counter]; //當前階段用到的相位
if(re_control==1&&step_counter!=reph_number-1) //遙控響應尚未開始執行
now_phase_tempn = toto&inuse_phasen[reph_number-1]; //下一階段放行的相位
else if(force_flag==1&&step_counter!=force_number-1) //強制響應尚未開始執行
now_phase_tempn = toto&inuse_phasen[force_number-1];
else
now_phase_tempn = toto&inuse_phasen[step_counter]; //下一階段放行的相位
if(now_phase_temp!=0) //當前階段放行的相位不為空
{
now_lamp_temp = XBYTE[baseaddr_now_phasesch+18*i];
now_lamp_temp = now_lamp_temp<<8;
now_lamp = now_lamp_temp|XBYTE[baseaddr_now_phasesch+18*i+1]; //當前階段放行的相位
if(now_uncount>red_yellow_green_clear[i]) //////////當前倒計時處于綠燈時間范圍內
// step_uncount[4][16]:當前階段的剩余時間累計,全紅時間,黃燈時間,綠閃時間,綠燈時間
{
now_phase_status = now_phase_status|now_phase_temp;
// if((XBYTE[baseaddr_now_phasesch+18*i+2]&0x04)!=0x04) //判斷相位的基本屬性,
// {
now_step_uncount = now_uncount-red_yellow_clear[i]; //非行人相位 不是行人相位
// }
//當前綠燈的倒計時
for(j=0; j<16; j++) //此循環用于查找當前相位用到的燈組
{
toto1 = 0x0001;
toto1 = toto1<<j;
inuse_lamp_temp = toto1&now_lamp;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -