抄了“基于proteus和校企對接的單片機實驗與綜合設計實例”上的“出租車計費系統”的程序,想要的下。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.png (26.49 KB, 下載次數: 67)
下載附件
2021-5-9 16:18 上傳
單片機源程序如下:
- #include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit RESET = P3^7;
- int Price = 80, Mileage = 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};
- //延時函數ms
- void delay(uint t)
- {
- uchar i = 0;
- while(t--)
- for (i; i<120; i++);
- }
- //數碼管顯示函數
- /*
- 參數說明:
- d : 表示要顯示的值
- x : 表示是否要顯示點(0x80 顯示 0不顯
- w :顯示第幾位
- */
- void disp(uchar d, uchar x, uchar w)
- {
- P2 = 0XFF;
- P2 = tab_wei[w];
- P0 = 0;
- P0 = tab_d[d] | x;
- delay (100);
- }
- //刷新函數
- void refresh()
- {
- disp(Mileage%10, 0, 0);//公里
- disp(Mileage/10%10, 0x80, 1);
- if (Mileage >= 100)
- disp(Mileage/100%10, 0, 2);
- if (Mileage >= 1000)
- disp(Mileage/1000%10, 0, 3);
- disp(Price%10, 0, 4);
- disp(Price/10%10, 0x80, 5);
- if (Price >= 100)
- disp(Price/100%10, 0, 6);
- if (Price >= 1000)
- disp(Price/1000%10, 0, 7);
- }
- void timer1 () interrupt 1
- {
- count++;
- Mileage += 1;
- if( count == 5)
- {
- count = 0;
- if (Mileage > 30)
- Price +=10;
- }
- }
- //系統初始化
- void init()
- {
- P0 = 0;
- P2 = 0XFF;
- TMOD = 0X0E; //設置計數器模式
- IT0 = 1; //電平觸發
- TH0 = 255; //1個脈沖延時
- TL0 = 255;
- TR0 = 1;
- IE = 0X82;
- }
- void judgeReset()
- {
- if(RESET == 0)
- {
- Price = 80;
- Mileage = 0;
- }
- }
- void main()
- {
- init (); //系統初始化
- while (1)
- {
- judgeReset ();
- refresh ();
- }
- }
復制代碼
51hei.png (8.17 KB, 下載次數: 69)
下載附件
2021-5-9 16:19 上傳
所有資料51hei提供下載:
出租車計費系統.rar
(40.57 KB, 下載次數: 42)
2021-5-8 20:37 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|