|
300黑幣
這個(gè)圖如何使得出租車停止行駛時(shí),保存已行駛的里程和費(fèi)用并顯示。對(duì)應(yīng)程序怎么改?
11111.png (105.62 KB, 下載次數(shù): 46)
下載附件
2022-3-3 17:37 上傳
#include<reg51.h>#define uchar unsigned char
#define uint unsigned int
sbit RESET = P3^7;
int Price = 100, Mile = 0;
uchar count = 0;
uchar code tab_d[10] = {0x3F, 0X06, 0X5B, 0X4F, 0X66, 0X6D, 0X7D, 0X07, 0X7F, 0X6F};
uchar code tab_wei[8] = {0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe};
void delay(uint t)
{
uchar i=0;
while(t--)
for (i; i<120;i++);
}
void display(uchar d,uchar x,uchar w)
{
P2 = 0XFF;
P2 = tab_wei[w];
P0 = 0;
P0 = tab_d[d] | x;
delay (100);
}
void refresh()
{
display(0,0,0);
display(Mile%10,0,1);
display(Mile/10%10,0x80,2);
if (Mile>= 100)
display(Mile/100%10,0,3);
if (Mile >= 1000)
display(Mile/1000%10,0,4);
display(Price%10,0,5);
display(Price/10%10,0x80,6);
if (Price>= 100)
display(Price/100%10,0,7);
if (Price>=1000)
display(Price/1000%10,0,8);
}
void timer1 () interrupt 1
{
count++;
Mile += 1;
if( count==10)
{
count=0;
if (Mile>=30&&Mile<160)
Price +=16;
if (Mile>=160)
Price +=18;
}
}
void init()
{
P0 = 0;
P2 = 0XFF;
TMOD = 0X0E;
IT0 = 1;
TH0 = 255;
TL0 = 255;
TR0 = 1;
IE = 0X82;
}
void judgeReset()
{
if(RESET == 0)
{
Price = 100;
Mile = 0;
}
}
void main()
{
init ();
while (1)
{
judgeReset ();
refresh ();
}
} |
最佳答案
查看完整內(nèi)容
如果你的脈沖是根據(jù)從出租車獲取的脈沖數(shù),比如說輪子轉(zhuǎn)一圈,給一個(gè)脈沖這樣的話,程序沒有什么問題,在出租車停下來的時(shí)候,沒有脈沖信號(hào),顯示也就停在那了,如果你要在proteus中這么做的話,需要在脈沖和單片機(jī)之間加一個(gè)按鍵
|