資源描述:
《出租車計(jì)價(jià)器程序》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、#include#defineucharunsignedchar#defineuintunsignedintucharqianwei,baiwei,shiwei,gewei;//顯示數(shù)據(jù)各個(gè)位置數(shù)字的臨時(shí)變量charled_seg_code[10]={0x3f,0x06,0x05b,0x04f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//段碼表示0-9//按鍵的定義,所有按鍵按下去為低電平sbitkey0=P1^0;//清零sbitkey1=P1^1;//切換路程與等待時(shí)間sbitkey2=P1^2;//單程還是往返設(shè)置sb
2、itkey3=P1^3;//暫停按鈕bitkey1_flag;//由于按鍵會自動復(fù)位,這個(gè)為標(biāo)志位bitkey2_flag;bitkey3_flag;bitflag;//初始化函數(shù)voidinitial_data(void){distance=0;cost=0;second=0;minute=0;way=0;key1_flag=1;//key2_flag=0;//單程or往返,接指示燈;key3_flag=1;//暫停,接指示燈;flag=0;pulse=0;dengdai=0;}//暫停程序voidzanting(void){if(key3_flag){EX0=
3、0;//關(guān)閉中斷定時(shí)器TR0=0;}key3_flag=!key3_flag;}//計(jì)算數(shù)據(jù)處理voidjisuan(){if(pulse<=210){distance=pulse/7+way/10000;cost=80;}danjia=10;//單程價(jià)格if(key2_flag)danjia=30;//往返價(jià)格if(pulse>180){distance=pulse/7+way/10000;cost=danjia*(distance-30)/10+80;}wait=minute*100+second;}//顯示的輔助程序,分離一個(gè)數(shù)的各個(gè)數(shù)字voidfenli(
4、uinttemp)//數(shù)據(jù)的分離處理{if(temp>9999)temp=9999;qianwei=temp/1000;baiwei=temp/100%10;shiwei=temp%100/10;gewei=temp%10;}voiddiplay_delay(void){uchari;for(i=0;i<240;i++);}//顯示程序;voidled_show(){if(key1_flag)fenli(distance);elsefenli(wait);P2=0xfe;P0=led_seg_code[gewei];diplay_delay();P2=0xfd;i
5、f(key1_flag)P0=led_seg_code[shiwei]
6、0x80;elseP0=led_seg_code[shiwei];diplay_delay();P2=0xfb;if(key1_flag)P0=led_seg_code[baiwei];elseP0=led_seg_code[baiwei]
7、0x80;diplay_delay();P2=0xfb7;P0=led_seg_code[qianwei];diplay_delay();//-----顯示價(jià)格----fenli(cost);P2=0xef;diplay_delay();P2=0xdf;d
8、iplay_delay();P2=0xbf;diplay_delay();P2=0x7f;diplay_delay();}//延時(shí)時(shí)基為1msvoiddelay(uintx){inti,j;for(i=x;i>0;i--)for(j=110;j>0;j--);}//鍵盤的掃描voidkeyscan(){if(key1==0)//按鍵消抖并判斷按下去的次數(shù)為基數(shù)還是偶數(shù){delay(2);if(key1==0)key1_flag=!key1_flag;}if(key0==0)//清零{delay(2);if(key0==0)initial_data();}if(ke
9、y3==0)//暫停{delay(2);if(key3==0)zanting();}if(key2==0)//單程還是往返{delay(2);if(key2==0)key2_flag=!key2_flag;}}//定時(shí)器初始化voidinitial_time(){TMOD=0x01;TH0=(65536-25000)/256;TL0=(65536-25000)%256;IE=0x83;IT0=1;//外部邊沿觸發(fā)方式TR0=1;}//中斷記錄脈沖數(shù)voidzd()interrupt0//中斷0{aa++;if()pulse++;//進(jìn)入中途等待計(jì)價(jià)}//*****
10、****定