双通道--电条和线圈测速_第1页
双通道--电条和线圈测速_第2页
双通道--电条和线圈测速_第3页
双通道--电条和线圈测速_第4页
双通道--电条和线圈测速_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论