?? second_bark.c
字號(hào):
//遙控****************************************
if(step_counter==reph_number-1)//正在執(zhí)行遙控相位
{
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) //尚未執(zhí)行遙控相位
{
remote_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash;
now_step_key=1;
}
else if(remote_state==2) //尚未執(zhí)行遙控相位,繼續(xù)走完本階段
{
if(no_vehicle_step[step_counter]==0)//該階段有無(wú)機(jī)動(dòng)車標(biāo)志
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:按下遙控按鍵后,尚未執(zhí)行遙控相位,繼續(xù)走本階段時(shí)間
// 或正在執(zhí)行遙控相位
//remote_state=3:按下遙控解除按鍵
//remote_state=4:按下遙控解除按鍵 繼續(xù)走完遙控階段時(shí)間
//else if(remote_state==3) //解除遙控,
// now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;
//***************強(qiáng)制****************************************//
else if(step_counter==force_number-1)//正在執(zhí)行強(qiáng)制相位
{
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) //尚未執(zhí)行強(qiáng)制相位
{
force_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash;
now_step_key=1;
}
else if(force_state==2) //尚未執(zhí)行強(qiáng)制相位,繼續(xù)走完本階段
{
now_uncount =max_red_clear+max_yellow+max_green_flash-now_step_key;
}
//remote_state=1:按下遙控按鍵
//remote_state=2:按下遙控按鍵后,尚未執(zhí)行遙控相位,繼續(xù)走本階段時(shí)間
//remote_state=3:按下遙控解除按鍵
//remote_state=4:按下遙控解除按鍵 繼續(xù)走完遙控階段時(shí)間
//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) //解除強(qiáng)制
{
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; //查表的階段時(shí)間與當(dāng)前歷時(shí)的倒計(jì)時(shí)
}
#include <second.h>
/*****************************************************************************************************/
// 讀時(shí)間
/*****************************************************************************************************/
void read_time() {
now_day = XBYTE[0XC006]; /*星期*/
now_year= XBYTE[0XC009]; /*年份*/
now_month=XBYTE[0XC008]; /*月份*/
now_date= XBYTE[0XC007]; /*日子*/
now_hour= XBYTE[0XC004]; /*小時(shí)*/
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 //計(jì)算感應(yīng)控制階段時(shí)間=最小綠燈+紅燈+黃燈
{
uchar i,max_time;
uint j;
uint offset;
//uchar time[16];
//uchar green_flash[16];
ensensor_flag = 1;
sensor_car_flag= 0;
sensor_counter = 0; //感應(yīng)控制階段開始設(shè)為0
for(i=0; i<16; i++) //此循環(huán)用于查找當(dāng)前階段用到的相位
{
j = 18*i;
offset= 0x0001;
offset= offset<<i;
now_phase_temp = offset&inuse_phase[step_counter]; ////inuse_phase:階段用到的相位step_counter:階段號(hào)
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))
{
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 =最小綠燈-綠閃-單位步長(zhǎng)
max_greentime = XBYTE[baseaddr_now_phasesch+j+13]-XBYTE[baseaddr_now_phasesch+j+17];
//green_flash[i]= XBYTE[baseaddr_now_phasesch+j+17];//綠閃時(shí)間
//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_time=XBYTE[baseaddr_now_phasesch+j+12]+XBYTE[baseaddr_now_phasesch+j+15]+XBYTE[baseaddr_now_phasesch+j+16];
//max_green_flash=XBYTE[baseaddr_now_phasesch+j+17];
}
}
/* else
{
time[i]=0;
green_flash[i]=0;
} */
}
//max_time=max(time);
//max_green_flash=max(green_flash);
return (max_time);
}
/*-----------------------------------**/
void max_clear_time() using 1
{
uchar now_phase_temp,i ;
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;
// if(step_counter==3)
// g_error1=55;
now_phase_temp = toto&inuse_phase[step_counter]; //當(dāng)前階段是否包含該相位
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 search_color() using 1
{
uchar data i,j;
uint data toto,toto1;
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; /*不用的燈組滅掉*/
}
if(sensor_step[step_counter]==0) //階段為固定配時(shí)
{
if(re_control==1||force_flag==1||hand_step_flag==1) //遙控 強(qiáng)制
{
if(hand_step_flag==1)
reph_number=hand_step+1;
//遙控****************************************
if(step_counter==reph_number-1)//正在執(zhí)行遙控相位
{
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) //尚未執(zhí)行遙控相位
{
remote_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash;
now_step_key=1;
}
else if(remote_state==2) //尚未執(zhí)行遙控相位,繼續(xù)走完本階段
{
now_uncount =max_red_clear+max_yellow+max_green_flash-now_step_key;
}
//remote_state=1:按下遙控按鍵
//remote_state=2:按下遙控按鍵后,尚未執(zhí)行遙控相位,繼續(xù)走本階段時(shí)間
// 或正在執(zhí)行遙控相位
//remote_state=3:按下遙控解除按鍵
//remote_state=4:按下遙控解除按鍵 繼續(xù)走完遙控階段時(shí)間
//else if(remote_state==3) //解除遙控,
// now_step_key=XBYTE[baseaddr_now_schemesch+8+step_counter]-now_uncount;
//***************強(qiáng)制****************************************//
else if(step_counter==force_number-1)//正在執(zhí)行強(qiáng)制相位
{
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) //尚未執(zhí)行強(qiáng)制相位
{
force_state=2;
now_uncount =max_red_clear+max_yellow+max_green_flash;
now_step_key=1;
}
else if(force_state==2) //尚未執(zhí)行強(qiáng)制相位,繼續(xù)走完本階段
{
now_uncount =max_red_clear+max_yellow+max_green_flash-now_step_key;
}
//remote_state=1:按下遙控按鍵
//remote_state=2:按下遙控按鍵后,尚未執(zhí)行遙控相位,繼續(xù)走本階段時(shí)間
//remote_state=3:按下遙控解除按鍵
//remote_state=4:按下遙控解除按鍵 繼續(xù)走完遙控階段時(shí)間
//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) //解除強(qiáng)制
{
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; //查表的階段時(shí)間與當(dāng)前歷時(shí)的倒計(jì)時(shí)
}
for(i=0; i<16; i++) //此循環(huán)用于查找當(dāng)前階段用到的相位
{
toto = 0x0001;
toto = toto<<i;
now_phase_temp = toto&inuse_phase[step_counter];
if(re_control==1&&step_counter!=reph_number-1)//遙控響應(yīng)尚未開始執(zhí)行
now_phase_tempn = toto&inuse_phasen[reph_number-1];
else if(force_flag==1&&step_counter!=force_number-1)//遙控響應(yīng)尚未開始執(zhí)行
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]) //當(dāng)前倒計(jì)時(shí)處于綠燈時(shí)間范圍內(nèi)
// step_uncount[4][16]:當(dāng)前階段的剩余時(shí)間累計(jì),全紅時(shí)間,黃燈時(shí)間,綠閃時(shí)間,綠燈時(shí)間
{
now_phase_status = now_phase_status|now_phase_temp;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -