




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、/*/File Name: CJ510F_4.c/Description: 雙通道-電條和線圈測速/Author: JunZhi, Du/Verson: 3.0/Date: 2005-5-24/Note: / /*/#include <AT89X52.H> #include "USER.H" #define MaxVehRate 160 #define OLEN 32 idata INT8U outbufOLEN; INT8U idata *outlast=outbuf; INT8U idata *putlast=outbuf; #define ILEN 12
2、idata INT8U inbufILEN; INT8U idata *inlast=inbuf; INT8U idata *getlast=inbuf; bit outbuflast; bit outbufsign; bit inbufsign; bit inbufful; float f_average_speed,f_wheelbase; INT16U PASS_time1=0; INT16U PASS_time2=0; INT16U idata T0_counter=0;INT16U idata T2_counter=0;INT16U idata int_start_time=0;st
3、atic INT8U M11,M12,M21,M22,MI,MF ;bool init_finished=0;bool impower=0;bool nopower30s=0;bool dectect_enable=0;bool dectect_started=0; bool calcul_enable_a=0; bool calcul_enable_b=0;bool passed=0;bool Loop_A_1=0; bool Loop_A_2=0; bool Loop_A_3=0; bool chanpe0=0; bool chanpe1=0; bool chanpe2=0; bool d
4、oor_sign=0;bool alarm_sign=0;bool car_in_area=0;bool led_1ab=0;INT8U channel=0;INT8U axle_sum3=0,0,0;INT8U aver_speed_Int3; INT8U aver_speed_Frc3; INT8U wheelbase_Int3; INT8U wheelbase_Frc3; INT8U ve_type3;INT8U axle_sum_a;INT8U axle_sum_b;/*typedef struct updata INT8U command; INT8U way_number; INT
5、8U average_speed_Int; INT8U average_speed_Frc; INT8U vehicle_type; INT8U check_sum; UPDATA; UPDATA up_data;/*void copy_updata(UPDATA * p_data ,INT8U channel,INT8U test_bit)INT8U i,chec_sum= 0;INT8U* j;p_data->command = 0x6f;if (!test_bit)p_data->way_number=channel+1 ;else p_data->way_number
6、=channel;p_data->average_speed_Int=aver_speed_Intchannel ;p_data->average_speed_Frc=aver_speed_Frcchannel ;p_data->vehicle_type=ve_typechannel ;j=(INT8U *)&up_data; for(i=0;i<5;i+) chec_sum += *(j+i) ;p_data->check_sum=chec_sum ;/*/定時器struct u_timer /INT16U enable_time; INT16U sta
7、rt_time; INT16U all_time; INT8U Time_out;struct u_timer ut7=0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1;void start_utimer(INT8U num ,INT16U time) utnum.start_time= T0_counter; utnum.all_time= time;utnum.Time_out=0;bool get_utimer(INT8U num)if(T0_counter- utnum.start_time)=utnum.all_time)&&(!ut
8、num.Time_out) /time oututnum.Time_out=1;return 1; else return 0; void close_all_utimer(void) /close all timerINT8U i;for(i=0;i<7;i+)uti.Time_out=1;void clear_sign(void) impower=0;close_all_utimer();start_utimer(1,u1time);/start_utimer(4,200);aver_speed_Intchannel=0x0; aver_speed_Frcchannel=0x0;wh
9、eelbase_Intchannel=0x0; wheelbase_Frcchannel=0x0;dectect_enable=1;channel=0; car_in_area=0; axle_sum_a=0;axle_sum_b=0; PASS_time1=0; PASS_time2=0;calcul_enable_a=0;calcul_enable_b=0; dectect_started=0; Loop_A_1=0; Loop_A_2=0;Loop_A_3=0; chanpe0=0; chanpe1=0; chanpe2=0; led_1ab=0; passed=0; void putb
10、yte(INT8U c) /INT8S i,j;ES=0; /if (outlast=putlast)while ( (outlast-putlast)=2) && (outlast > putlast ) | (outlast < putlast) && (OLEN-(putlast-outlast)=2) ES=1; c+;c-;ES=0;/i=(0-TH1);/doi-;j=39; do j-;while(j!=0); while(i!=0); /i=39clr_wdt; *putlast=c; putlast+; outbufsign=1;
11、if (putlast=outbuf+OLEN) putlast=outbuf; if (!outbuflast) outbuflast=1;TI=1; ES=1; clr_wdt; void putbytes(INT8U *outplace,INT8U j) INT8U i;for(i=0;i<j;i+)putbyte(*outplace); outplace+;INT8U getbyte (void) INT8U idata c ; while (!inbufsign) clr_wdt; ES=0; c= *getlast; getlast+; inbufful=0; if (get
12、last=inbuf+ILEN) getlast=inbuf; if (getlast=inlast) inbufsign=0; ES=1; return (c); void getbytes (INT8U idata *line, INT8U n) INT8U cnt = 0; INT8S c;do c = getbyte (); *line = c;/putbyte (*line = c); line+; cnt+; clr_wdt; while (cnt < n); /*line = 0; void serial_init (void) SCON = 0x50; / serail
13、mode 1, 8-bit UART, enable receiver(REN = 1;)*/TMOD |= 0x20; / timer 1 mode 2: 8-Bit reload */PCON |= 0x80; / double baud rate bit =1, the baud rate is doubledTH1 = 0xfa; / reload value, 9600 baud rate, fosc=11.0592MHzTR1 = 1; / timer 1 run */ES = 1; void timer_exint_init()/- timer0 initialization T
14、MOD |=0x01; /th0 1X16 TH0=0X01; / ee00H-5MS TL0=0X00; ET0=1; TR0=1; /- external interrupt 0 EX0=1;IT0=1; /- external interrupt 1 EX1=1;IT1=1;/- interrupt priority level/- enable for all interrupt/* EA = 1; P1=0x00; void shut(void)INT8U i,j,k;/- impower=0; nopower30s=0; start_utimer(1,u1time); /-shut
15、ter_on; for(k=4;k>0;k-)for(i=200;i>0;i-) for(j=248;j>0;j-)clr_wdt; shutter_off;void main(void)INT16U aa,bb,cc,dd,ee;INT8S ch; INT8U idata verify_sum;INT8U idata indata20;INT8U *p_d;serial_init(); timer_exint_init(); putbyte(0x2c);start_utimer(0,u0time);/3s 一發while(1)if(!init_finished)if(get
16、_utimer(0) putbyte(0x2c);start_utimer(0,u0time); if(inbufsign)switch(ch=getbyte () case 0xde: getbytes(indata,7); verify_sum =0xde +indata0+indata1+indata2+indata3+indata4+indata5; if (verify_sum=indata6) /M11=indata0; M12=indata1; /M21=indata2; M22=indata3; MI=indata4; MF=indata5; indata6 =0x06 +in
17、data0+indata1+indata2+indata3+indata4+indata5; putbyte(0x06); putbytes(indata,7); if(!init_finished)init_finished=1;impower=0; nopower30s=0; /clear impower start_utimer(1,u1time); dectect_enable=1; break; case 0xaa: if(init_finished) shut(); /void shut(void) aver_speed_Int0=0; aver_speed_Frc0=0; ve_
18、type0=0; copy_updata(&up_data ,0,1);p_d=(INT8U *)&up_data;putbytes(p_d,6);break; case 0x55: if(init_finished) impower=1; dectect_enable=1; nopower30s=0; close_all_utimer(); LED_sys_inline=0; break; case 0x77: impower=0; nopower30s=0; start_utimer(1,u1time); break; case 0xe2: LED_filetransfer
19、=1; break; case 0xe3: LED_filetransfer=0; break; case 0xe4: CDMApower_on; break; case 0xe5: CDMApower_off; /turn on the CDMA moden's power break; case 0x07: impower=0; nopower30s=0; camerapower_off; /cut off the camera's power for(cc=15;cc>0;cc-)for(dd=200;dd>0;dd-)for(ee=248;ee>0;e
20、e-)clr_wdt; /delay 7.35s camerapower_on; for(cc=15;cc>0;cc-)for(dd=200;dd>0;dd-)for(ee=248;ee>0;ee-)clr_wdt; /delay 7.35s putbyte(0x17); start_utimer(1,u1time); break; /= if(door_open_key&&!door_sign) /door open for(dd=20;dd>0;dd-) for(ee=248;ee>0;ee-)clr_wdt; /delay 10ms for
21、filtering if(door_open_key) / door open alarm putbyte(0xe6); door_sign=1; alarm_sign=0; LCDpower_on; else if(!door_open_key&&door_sign) putbyte(0xe9); door_sign=0; LCDpower_off; if(!no_alarm_key&&!alarm_sign) /press the no_alarm key for(dd=20;dd>0;dd-)for(ee=248;ee>0;ee-)clr_wd
22、t; if(!no_alarm_key) putbyte(0xe7); alarm_sign=1; if(!test_key&&init_finished) /press the test key for(dd=20;dd>0;dd-)for(ee=248;ee>0;ee-)clr_wdt; if(test_key)shut(); /void shut(void) aver_speed_Int0=0; aver_speed_Frc0=0; ve_type0=0; copy_updata(&up_data ,0,1);p_d=(INT8U *)&up_
23、data;putbytes(p_d,6); if(!impower&&init_finished) if(!nopower30s&&(get_utimer(1) nopower30s=1; LED_sys_inline=1; putbyte(0x66); /transmit the 0x66 start_utimer(1,u1time/10); else if(nopower30s&&(get_utimer(1) putbyte(0x66); /transmit the 0x66 per 3sstart_utimer(1,u1time/10);
24、/= if(car_in_area)if(get_utimer(2)|get_utimer(3) clear_sign(); if(Loop_A_1&&(!loop1A)&&(!loop1B) /the car pass the detect areaif(calcul_enable_a&&calcul_enable_b) /&&(axle_sum_b>=2)&&(axle_sum_b<=7) /it has a holdif(axle_sum_a<=6&&axle_sum_b=a
25、xle_sum_a)Loop_A_1=0;car_in_area=0;passed=1;close_all_utimer(); else if(ut3.Time_out)start_utimer(3,u3time); else if(Loop_A_2&&(!loop2A)&&(!loop2B) if(calcul_enable_a&&calcul_enable_b) if(axle_sum_a<=6&&axle_sum_b=axle_sum_a) Loop_A_2=0;car_in_area=0;passed=1;close
26、_all_utimer(); else if(ut3.Time_out)start_utimer(3,u3time); /= if (calcul_enable_a&&calcul_enable_b&&impower&&passed) aa=0;bb=0;do f_wheelbase=(float)PASS_time2*(float)0x3)/(float)PASS_time1); aa+;while(_chkfloat_(f_wheelbase)&&(aa<=2); do f_average_speed=(float)21
27、600)/(float)PASS_time1); bb+; while(_chkfloat_(f_average_speed)&&(bb<=2); if(aa<=2)&&(bb<=2)aver_speed_Intchannel=(INT8U)f_average_speed; aver_speed_Frcchannel=(INT8U)(f_average_speed-(float)aver_speed_Intchannel)*(float)100);wheelbase_Intchannel=(INT8U)f_wheelbase; wheelbas
28、e_Frcchannel=(INT8U)(f_wheelbase-(float)wheelbase_Intchannel)*(float)100); if(aver_speed_Intchannel<=MaxVehRate)if(wheelbase_Intchannel>MI) if(aver_speed_Intchannel>M22) shut();/void shut(void)ve_typechannel=0x02;copy_updata( &up_data ,channel,0);p_d=(INT8U *)&up_data;putbytes(p_d,6
29、);else if(aver_speed_Intchannel=M22)&&aver_speed_Frcchannel)shut();/void shut(void)ve_typechannel=0x02;copy_updata( &up_data ,channel,0);p_d=(INT8U *)&up_data;putbytes(p_d,6); else if(wheelbase_Intchannel=MI)&&(wheelbase_Frcchannel>=MF) /big vehicle if(aver_speed_Intchanne
30、l>M22) shut();/void shut(void)ve_typechannel=0x02;copy_updata( &up_data ,channel,0);p_d=(INT8U *)&up_data;putbytes(p_d,6);else if(aver_speed_Intchannel=M22)&&aver_speed_Frcchannel) /. shut();/void shut(void)ve_typechannel=0x02;copy_updata( &up_data ,channel,0);p_d=(INT8U *)&am
31、p;up_data;putbytes(p_d,6);else if(aver_speed_Intchannel>M12)shut();/void shut(void)ve_typechannel=0x01;copy_updata( &up_data ,channel,0);p_d=(INT8U *)&up_data;putbytes(p_d,6);else if(aver_speed_Intchannel=M12)&&aver_speed_Frcchannel)shut();/void shut(void)ve_typechannel=0x01;copy_
32、updata( &up_data ,channel,0);p_d=(INT8U *)&up_data;putbytes(p_d,6); clear_sign(); clr_wdt; void EXINT0_INT(void) interrupt 0if(impower&&car_in_area&&!passed)if(Loop_A_1) if(pe1A)axle_sum_a+=1;if(axle_sum_a=1)int_start_time= T0_counter;if(axle_sum_a=2)PASS_time2=(T0_counter- int_start_time); calcul_enable_a=1;if(pe1B) axle_sum_b+=1; if(axle_sum_b=1)PASS_time1=(T0_counter- int_start_time); /calcul_enable_b=1;if(axle_sum_b=
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 外專局外籍教師協議
- 電視廣告制作協議
- 離職手續完成證明及勞動關系終止書(6篇)
- 互聯網科技產業融資狀況表格
- 電力系統運行與維護專業試題
- 授權啤酒銷售合同
- 軟件著作權申請流程及實例解析
- 在職員工基本信息一覽表
- 地理學創新人才培養中的自主學習與終身教育機制
- 員工收入及獎金詳細證明(5篇)
- 北師大版二年級下冊數學計算題每日一練帶答案(共20天)
- 北師大版四年級下冊數學計算題每日一練帶答案(共30天)
- 中醫診所信息安全管理制度
- 公共危機管理(本)-第五次形成性考核-國開(BJ)-參考資料
- 基于SLM工藝的點陣結構優化設計的工藝要素研究
- 太陽能路燈施工方案
- 《商務數據分析》課件-缺失數據處理
- 《思想政治教育方法論》考研(第3版)鄭永廷配套考試題庫及答案【含名校真題、典型題】
- 【MOOC】機械原理-西北工業大學 中國大學慕課MOOC答案
- 彩票參數及公式
- 中華傳統文化進中小學課程教材指南
評論
0/150
提交評論