【源码目录】12527238_XWD├── 123.doc
├── 出租车计价器.DSN
├── 出租车计价器.PWI
└── 出租车计价器.c
0 directories, 4 files
#include<reg52.h>#define ucharunsigned char#define uint unsigned intsbit p00=P0^0 ;sbit p01=P0^1 ;sbit p02=P0^2 ;sbit p37=P3^7 ;uint i,j;uint codeSeg[19]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x80};//数码管译码表: { 0 , 1 , 2 , 3 , 4 ,5 6 7 8 9 0 . } P}uchar jps,ks,key_do;//键盘缓存,上次有按键按下标志位,按键已处理标志位uintcount_10ms=0,second=0; float cost; //价钱void delay(uinttt) //延时函数{ uint i; for(;tt>0;tt--) for(i=0;i<200;i ); }
void LED(uintd1,uint d2) { if(d1==1) P0=(P0|0xf0)&0x1f; if(d1==2) P0=(P0|0xf0)&0x2f; if(d1==3) P0=(P0|0xf0)&0x4f; if(d1==4) P0=(P0|0xf0)&0x8f; P0=P0|0x0f; P1=Seg[d2];}int keyscan() //键盘扫描函数{ int t=0; if(p00==0) { t=1; jps=1;} if(p01==0) { t=1; jps=2;} if(p02==0) { t=1; jps=3;} return(t); }void money() //价钱计算{ count_10ms ; if(count_10ms==100) {count_10ms=0;second ;} if(second<=3) cost=5.0; else if(second>3)cost=5.0 0.7*(second-3);}void ledshow(){ while(j%2==0) // 价钱显示 { LED(1,(int) (cost/10) ); delay(5); LED(2,(int) cost%10 ); delay(5); LED(3,(int) (cost*10)%10 ); delay(5); LED(4,(int) (cost*100)%10 ); delay(5); LED(2,11); delay(5); } while(j%2==1) // 时间显示 { LED(1,second/10); delay(5); LED(2,second%10); delay(5); LED(3,count_10ms/10); delay(5); LED(4,count_10ms%10); delay(5); LED(2,11); delay(5); } }void Time_fun()interrupt 1 //10ms中断函数{ uint k; if(k==15) { k=0; p37=1; } else k ; TH0=(0xffff-10000)/256; //10ms TL0=(0xffff-10000)%256; //10ms if(i%2==1) money(); // 暂停/播放 if((ks==1)&&(keyscan()==1)&&(key_do==0)) { k=0; p37=0; //按键提示音 key_do=1; if(jps==1)i ; // 暂停/播放键 if(jps==2)j ; // 时间价钱显示转换 if(jps==3) // 清零键 { count_10ms=0; second=0; cost=0; } } ks=keyscan(); if(ks==0) key_do=0;
}
main(){ TMOD=0x01; //Time0为16计数器 TH0=(0xffff-10000)/256; TL0=(0xffff-10000)%256; TR0=1; //打开定时器 IE=0x82; //EA=1 ET0=1 打开中断
while(1) { ledshow();
}};
评论