资源描述:
《Car_cyan_Timer》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、基于单片机的出租车自动计费器仿真电路:proteus7.4仿真效果良好程序清单:#include#defineuintunsignedint#defineucharunsignedchar#defineWAIT1/*等待状态*/#defineRUN2/*通行状态*/#defineSTOP0/*禁止状态*/sbitCar_S0=P1^0;sbitCar_S1=P1^1;sbitLED_R=P2^0;sbitLED_Y=P2^1;sbitLED_G=P2^2;voidCar_Process(void);uintdisnum;//disn
2、um通道数码值uintcount;ucharCar_State;//汽车运行状态ucharcodetable0[]=//共阳数码管代码{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};ucharcodetable1[]=//共阴数码管代码{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};/********延时子函数******
3、****/voiddelay(ucharx){uchara,b;for(a=x;a>0;a--)for(b=25;b>0;b--);}/**********定时器初始化********/voidTime0_Init(){EA=1;//中断使能ET0=1;ET1=1;TMOD=0X51;//T1计数T0定时TH0=(65536-55536)/256;//12M晶振TL0=(65536-55536)%256;TR0=0;TR1=0;}voidtime0()interrupt1{TH0=(65536-55536)/256;//12M晶振TL0=(65536
4、-55536)%256;if(count<60)count++;//0.1分钟步进值else{disnum=disnum+15;count=0;}//1.5/min0.15/0.1min}voidT1_counter(void){EA=0;disnum=disnum+8*(TL1+(TH1<<8));//1m模拟型步进计数EA=1;TL1=0;//80.00/Km0.08/mTH1=0;}/*********数码管显示********/voiddisplay(void){if(disnum>9999)disnum=9999;P0=table1[dis
5、num/1000];P3=0xfe;delay(2);P3=0Xff;P0=table1[disnum%1000/100]
6、0x80;P3=0xfd;delay(2);P3=0Xff;P0=table1[disnum%100/10];P3=0xfb;delay(2);P3=0Xff;P0=table1[disnum%10];P3=0xf7;delay(2);P3=0Xff;}/*********交通灯运作进程********/voidCar_Process(void){switch(Car_State){caseRUN:T1_counter();LE
7、D_R=0;LED_Y=0;LED_G=1;break;caseWAIT:LED_R=0;LED_Y=1;LED_G=0;break;caseSTOP:LED_R=1;LED_Y=0;LED_G=0;break;}}/********初始数据初始化**********/voidData_Init(void){disnum=0;Car_State=STOP;count=0;LED_R=1;LED_Y=0;LED_G=0;}main(){Time0_Init();Data_Init();delay(20);while(Car_S0==1){display
8、();Car_Process();}disnum=800;Car_State=WAIT;TR0=1;//定时器开启while(Car_S1==1){display();Car_Process();}Car_State=RUN;TR0=0;TR1=1;while(1){display();Car_Process();}}