资源描述:
《出租车计价器程序.docx》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#defineucharunsignedcharsbitACC_0=ACC^0;sbitACC_7=ACC^7;//位寻址寄存器定义sbitSCLK=p1^1;//DS1302时钟信号7脚sbitDIO=P1^0;//DS1302数据信号6脚sbitRST=P1^2;//DS1302片选5脚sbitStart=P1^5;sbitClear=P1^6;sbitSwitch=P1^7;sbitkey4=P3^2;ucharshi1,shi2,fen1,fen2
2、,miao1,miao2,tt0;ucharnum,PR11,PR12,PR13,PR14,DIS1,DIS2,DIS3,DIS4;uchartt=0;uchartt0,signal;ucharSwitch_a=1;ucharSwitch_b=1;floatPrice;uintnum1,num2,tt1;ucharcodetable[]={0x3f,0x30,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};//共阴数码管“0-9”,“灭”,“-”编码ucharcodewei
3、[]={0x00,0x01,0x02,0x03,0x04,0x05.0x06,0x07};//位选编码/*********************************计费部分***********************************///延时ms子程序voiddelay(uinti){uintj;for(i;j>0;i--);for(j=110;j>0;j--);}voidPrice_DistanRST_dispaly(){switch(num)//数码管显示{case1:{P2=0x00;P0=table[P
4、R11];delay(1);}break;case2:{P2=0x01;P0=table[PR12];dealy(2);}break;case3:{P2=0x02;P0=table[PR13]+0x80;delay(1);}break;case4:{P2=0x03;P0=table[PR14];dealy(1);}break;case5:{P2=0x04;P0=table[DIS1];delay(1);}break;case6:{P2=0x05;P0=table[DIS2];delay(1);}break;case7:{P2=
5、0x06;P0=table[DIS3]+0x80;dealy(1);}break;case8:{P2=0x07;P0=table[DIS4];delay(1);}break;}}voidzhuanhuan()//数据转换{DIS1=num1/1000;DIS2=num1%1000/100;DIS3=num1%1000%100/10;DIS4=num1%10;PRI1=num2/1000;PRI2=num2%1000/100;PRI3=num2%1000%100/10;PRI4=num2%10;}voidint1()interr
6、upt()//速度采集//外部中断(INTO){if(key4==0){delay(20);if(key4==0){num1++;while(!key4);}if(Switch_b==1){Price=2;//白天元/公里}if(Switch_b==2){Price=3;//晚上元/公里}if(num1!=0){if(num1<21){num2=70;}else{num2+=Price;//两公里内元,超过两公里按每公里/3元计费}}}}voidtime0()interrupt1{TH0=(65536-5000)/256;TL
7、0=(65536-5000)%256;tt0++;if(tt0==20){tt0=0;miao1++;if(miao1==10){miao1=0;miao2++;if(miao2==6){miao2=0;fen1++;if(fen1==10){fen1=0;fen2++;if(fen2==6){fen2=0;shi++;if(shi==10){shi1=0;shi2++;}}}}}}}voidtime1()interrupt3//定时/计数器(T1){TH1=(65536-2000)/256;TL1=(65536-2000)%
8、256;tt++;if(tt==2)//20ms*2{tt=0;num++;if(num==9)//限制num范围在0-9{num=1;}if(Switch_a==1){zhuanhuan();//数据转换Price_DistanRET_display();}if(Switc