您好,欢迎访问三七文档
/*十三、出租车计费系统设计设计内容:1、用一个独立按键控制汽车前进档位变化,根据按下次数不同,分别是1档→2档→3档→4档→1档…..,档位不同体现在直流电机的转速变化,档位值显示数显管;(40分)2、根据档位值,以及运行时期,实时将里程数显示在数显管上;(30分)3、有暂定功能;当暂停按钮按下,直流电机停转,里程数静止不变;(20分)4、具有里程清零功能;清零时,里程表显示为0;(10分)*/#include<reg52.h>sbitKEY1=P3^2;sbitKEY2=P3^3;sbitKEY3=P3^4;sbitPWM=P1^0;unsignedcharCYCLE;//定义周期该数字X基准定时时间如果是10则周期是10x0.1msunsignedcharPWM_ON;//定义高电平时间unsignedchartable[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};unsignedchartab_P2[8]={0,1,2,3,4,5,6,7};unsignedchartab_P0[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};unsignedcharii=0,jj=0;unsignedintsum=0;voiddelay(unsignedintcnt){while(--cnt);}main(){unsignedcharPWM_TEP,temp,PWM_Num;//定义档位TMOD|=0x01;//定时器设置1msin12McrystalTH0=(65536-1000)/256;TL0=(65536-1000)%256;//定时1mSTH1=(65536-5000)/256;TL1=(65536-5000)%256;IE=0x8a;//打开中断TR0=1;TR1=1;CYCLE=10;//时间可以调整这个是10步调整周期10ms8位PWM就是256步while(1){if(KEY1==0||KEY2==0||KEY3==0){delay(50);if(KEY1==0||KEY2==0||KEY3==0){if(KEY1==0){PWM_Num++;if(PWM_Num==4)PWM_Num=0;switch(PWM_Num){case0:tab_P0[0]=0x06;PWM_ON=2;break;//高电平时长:10-PWM_ONcase1:tab_P0[0]=0x5B;PWM_ON=4;break;case2:tab_P0[0]=0x4F;PWM_ON=6;break;case3:tab_P0[0]=0x66;PWM_ON=8;break;default:break;}}elseif(KEY2==0){sum=0;}elseif(KEY3==0){if(PWM_ON==10){tab_P0[0]=temp;PWM_ON=PWM_TEP;}else{temp=tab_P0[0];tab_P0[0]=0x09;PWM_TEP=PWM_ON;PWM_ON=10;}}}}delay(5000);}}/********************************//*定时中断*//********************************/voidtim(void)interrupt1using1{staticunsignedcharcount;staticunsignedintcountsum;//TH0=(65536-1000)/256;TL0=(65536-1000)%256;//定时1mSif(count==PWM_ON){PWM=1;//电机转动}count++;if(count==CYCLE){count=0;if(PWM_ON!=0)//如果左右时间是0保持原来状态PWM=0;//电机不转}if(countsum==1000){countsum=0;sum=sum+(10-PWM_ON)/2;}elsecountsum++;}voidtime1(void)interrupt3using3{unsignedintge,shi,bai,qian,wan;TH1=(65536-5000)/256;TL1=(65536-5000)%256;ge=sum%10;shi=sum/10%10;bai=sum/100%10;qian=sum/1000%10;wan=sum/10000%10;tab_P0[7]=table[ge];tab_P0[6]=table[shi];tab_P0[5]=table[bai];tab_P0[4]=table[qian];tab_P0[3]=table[wan];P0=tab_P0[ii];//i值的个位数P2=tab_P2[jj];//点亮第一位数码管jj++;ii++;if(jj==8)//利用j值的变化,来控制数码管数值变化间隔的时间{jj=0;ii=0;}}
本文标题:出租车计费
链接地址:https://www.777doc.com/doc-5594191 .html