<meta name="keywords" content="必胜时时彩开户,keywords" /> 51单片机的出租车计价器C51法式模范 联系我们

51单片机的出租车计价器C51法式模范模范

曾经由历程模拟测试

#include<reg52.h>
unsigned 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;//准时50MS
        EA=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分钟里程加1
                                       
                                        temp=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;
}