一.系统概述
出租车计价器设计:
1. 计价规则:启动价设定按钮可调,初始值为8元;5公里内保持8元,超过5公里每公里2元。
2. 显示方式:数码管左侧显示公里数,右侧显示价格。
3. 操作按钮:按键调节公里数的增加速度,清零按钮可重设公里数。
4. 计价保存:通过EEPROM进行计价规则的保存。
二.仿真概述
1. 启动仿真在数码管上的显示区域分别对应显示里程、起步价以及总价。
2. 此时起步价是8元,里程是9公里,因为超过5公里每公里2元,所以总价是16。
3. 按下归零按键计费信息归零,此时里程和起步价就会清零。
4. 按下起步价切换按键就能切换到9元的起步价。
三.程序设计
#include <REGX52.H>
#include "Key.h"
#include "Timer0.h"
#include "Timer1.h"
#include "Nixie.h"
#include "delay.h"
sbit LEDG = P3^6;
sbit LEDR = P3^7;
unsigned char KeyNum,k = 8;
unsigned char distance1_flag,distance2_flag,money_flag,flag1,flag2; //din yi yi ge huan cun
unsigned char distance,money,starting_fare;
void main()
{
Timer0_Init();
Timer1_Init();
while(1)
{
KeyNum = Key();
if(KeyNum == 1)
{
flag1 = 1;
flag2 = 0;
LEDG = 0;
LEDR = 1;
starting_fare = k;
distance2_flag = 0;
distance1_flag =! distance1_flag;
}
if(KeyNum == 2)
{
flag1 = 0;
flag2 = 1;
LEDG = 1;
LEDR = 0;
starting_fare = k;
distance1_flag = 0;
distance2_flag =! distance2_flag;
}
if(KeyNum == 3)
{
flag1 = 0;
flag2 = 0;
LEDG = 1;
LEDR = 1;
distance = 0;
starting_fare = 0;
money = 0;
starting_fare = 0;
distance1_flag = 0;
distance2_flag = 0;
}
if(KeyNum == 4)
{
k++;
if(k == 10)
{
k = 8;
}
starting_fare = k;
}
if(distance <= 5)
{
money = starting_fare;
}
else
{
money = starting_fare + ((distance - 5)*2);
}
Nixie_SetBuf(1,distance / 10);
Nixie_SetBuf(2,distance % 10);
Nixie_SetBuf(3,11);
Nixie_SetBuf(4,starting_fare);
Nixie_SetBuf(5,11);
Nixie_SetBuf(6,money / 100);
Nixie_SetBuf(7,money % 100 / 10);
Nixie_SetBuf(8,money % 10);
}
}