国产免费AV|泡泡玛特欧洲总部将设在伦敦|中文天堂网www新版资源在线|一本久道综合在线中文|国精产品一二三产区的使用方法|香蕉鱼在线观看|www.27eee
ELEOK
標題:
51單片機出租車計費系統Proteus仿真和C源代碼
[打印本頁]
作者:
eng
時間:
2021-6-24 00:33
標題:
51單片機出租車計費系統Proteus仿真和C源代碼
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
1.gif
(88.21 KB)
下載附件
2021-6-24 00:31 上傳
部分源碼:完整源碼見附件
/**************************************
計價規則:
用時間模擬路程,前三秒以內8.00元,若超出3秒
每增加一秒,價格增加1元。用數碼管顯示價錢和
時間(用一個按鍵控制顯示時間或價錢)。
**************************************/
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit p00=P0^0 ;
sbit p01=P0^1 ;
sbit p02=P0^2 ;
sbit p37=P3^7 ;
uint i,j;
uint code Seg[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;//鍵盤緩存,上次有按鍵按下標志位,按鍵已處理標志位
uint count_10ms=0,second=0;
float cost; //價錢
void delay(uint tt) //延時函數
{
uint i;
for(;tt>0;tt--)
for(i=0;i<200;i++);
}
void LED(uint d1,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=8.0;
else if(second>3) cost=8.0+1.0*(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();
}
}
復制代碼
完整c源碼和proteus仿真:
出租車.rar
(48.35 KB, 售價: 3 E幣)
2021-6-24 00:32 上傳
點擊文件名下載附件
售價: 3 E幣
[記錄]
[
購買
]
歡迎光臨 ELEOK (http://www.afoofa.cn/)
Powered by Discuz! X5.0