您的位置 首页 IC

51单片机的出租车计价器C51程序

已通过模拟测试includereg52h>unsignedcharcir_num,pwm_mach,temp,distance,wait_time,price,distance;unsigned

已经过模仿测验

#includeunsigned char cir_num,pwm_mach,temp,distance,wait_time,price,distance;unsigned int a,t;sbit pwm_mach=P1^0;sbit key_clean=P3^0;//界说按键方位sbit key_stop=P3^1;sbit key_cheak=P3^2;sbit key_oneway=P3^3;sbit key_doubleway=P3^4;unsigned char code led_buf[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};unsigned char code seg[]={0,1,2,3,4,5,6,7};//别离对应相应的数码管点亮/************初始化守时器0******************/void init_timer0(){TMOD=0x01;TH0=0x3C;TL0=0xAF;//守时50MSEA=1;ET0=1;TR0=1;}/************初始化守时器1******************/void init_timer1(){TMOD=0x10;TH0=0x00;TL0=0x00;EA=1;                     ET1=1;                  TR1=1;}/************初始化守时器2******************/void init_timer2(){RCAP2H = (65536-50000)/256;// 50ms 主动重载RCAP2L = (65536-50000)%256;ET2=1;EA=1;TR2=1;}/************守时器0中止******************/void Timer0_isr(void) interrupt 1 using 1{TH0=0x3C;               TL0=0xAF;if(a==20)//守时1s{a=0;if( cir_num<5)//检测1S内圈数是否小于5{t++;if(t==300)//等待时间累加满5分钟路程加1temp=1;}}else cir_num++;}/************守时器1中止******************/void Timer1_isr(void) interrupt 3 using 1{TH1=0x00;                /* Init value */TL1=0x00;distance=cir_num*28+temp;//路程cir_num++;//测速}/************守时器2中止******************/void Timer2_isr(void) interrupt 5 using 1//守时器2中止{TF2=0;while(1){pwm_mach=0;delay(200);pwm_mach=~pwm_mach;delay(400);}}/**************延时函数**************************/void delay(unsigned int cnt){while(--cnt);}/*********主函数******************/void main(){init_time0();init_time1();init_time2();while(1){key_order();dsp_data();}}/**********按键操控****************/void key_order(){if(!key_clean){distance=0;cir_num=0;t=0;}if(!key_stop){ET0=0;ET1=0;TR0=0;TR1=0;ET2=0;TR2=0;}if(!key_oneway){flag=0;//去履行单程计价程序}if(!key_doubleway){flag=1;//去履行往复计价程序}if(!key_cheak){wait_time=1;//显现等待时间//dis_time();//等待时间显现函数}}/*********数据处理程序*****************/void dsp_data(){switch(flag){case 0:price=(cir_num-10714)*20;break;case 1:price=(cir_num-10714)*15;break;default:price=8;    break;}switch(wait_time){case 0:distance=cir_num*28+temp;//路程price_display();//价格显现函数break;case 1:time_display();break;}}/*********价格显现函数***********/void price_display(){led_buf[4]=price/1000;led_buf[5]=price%1000/100;led_buf[6]=price%100/10;led_buf[7]=price%10;led_buf[6]=0x80;}/*********路程显现函数***********/void distance_display(){led_buf[0]=distance/1000;led_buf[1]=distance%1000/100;led_buf[2]=distance%100/10;led_buf[3]=distance%10;led_buf[2]=0x80;}void time_display(){led_buf[0]=t/1000;led_buf[1]=t%1000/100;led_buf[2]=t%100/10;led_buf[3]=t%10;led_buf[4]=0x6d;}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/bandaoti/318495.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部