抄了“基于proteus和校企对接的单片机实验与综合设计实例”上的“出租车计费系统”的程序,想要的下。
仿真原理图如下
单片机源程序如下:
- #include
- #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 ();
- }
- }