📄 freescale
字号:
#include "taximeter.h"
/************************************************************
State - Free
************************************************************/
/**
* Free: Idle state. It shows in the displayes the label
* "FREE" and constantly scans the value of the buttons.
*
* Parameters: none.
*
* Variables read: pushed_buttons.
*
* Variables modified: current_state.
*
* Subfunctions: DisplayMsg().
*
* Return: void
*/
void Free(void){
WaitForButtonsRelease();
DisplayMsg(FREE_STATE_MSG); // Display "FREE "
if (FLASH_PROGRAM != UNCORRUPT_FLASH) { // Verify if Flash is not corrupt
DisplayMsg(ERROR_MSG);
while(pushed_buttons != BUTTON5)
{;} // Empty Body
}
while(-1) { // Stay here until a button is pressed
switch(pushed_buttons) { // Change the state according to the button
case BUTTON1: current_state = SERVICE;
return;
case BUTTON2: current_state = EXTRAS;
return;
case BUTTON3: current_state = CLOCK;
return;
case BUTTON4: current_state = INFO;
return;
case BUTTON5: current_state = PROGRAM;
return;
}
}
}
/************************************************************
State - In Service
************************************************************/
/**
* Service: Starts charging.
* According to time and distance, it increments
* the value of the total amount to pay by the
* costumer and displays it.
*
* Parameters: none.
*
* Variables read: pushed_buttons.
* accumulator_extras.
* ini_ch_active.
*
* Variables modified: accumulator_trip.
* flag_charge.
* current_state.
*
* Subfunctions: CleanUp().
* DisplayMsg().
* DisplayNum().
* Delay().
*
* Return: void
*/
void Service(void) {
char *_ptrMsg;
CleanUp();
_ptrMsg = &FARE_MESSAGE_TABLE[(fare_type * 5)];
DisplayMsg(_ptrMsg); // Display the selected fare for one second
WaitForButtonsRelease();
Delay(1000, BUTTON1); // Wait one second
accumulator_trip = accumulator_extras + ini_ch_active;
WaitForButtonsRelease();
flag_charge = CHARGE; // Start charging
while (pushed_buttons != BUTTON1) { // Keep refreshig the amount to pay so far until the user
DisplayNum(accumulator_trip); // pushed button 1. The accumulator_trip is incremented // timer y en el IRQ.
} // in the interrupt service routines.
current_state = PAY; // Go to PAY state.
DisplayMsg(PAY_STATE_MSG); // Display message "PAY"
return;
}
/************************************************************
State - Pay
************************************************************/
/**
* Pay: Stops charging.
* Displays (toggling) the label " PAY " and the total
* amount to pay.
*
* Parameters: none.
*
* Variables read: pushed_buttons.
* accumulator_trip.
*
* Variables modified: flag_charge.
* current_state.
*
* Subfunctions: DisplayMsg().
* DisplayNum().
* Delay().
*
* Return: void
*/
void Pay(void) {
flag_charge = NO_CHARGE; // Stop charging
WaitForButtonsRelease();
while (pushed_buttons != BUTTON1) { // Toggle the message "PAY" and the total amount
DisplayMsg(PAY_STATE_MSG); // to pay until the user presses button 1
Delay(2000, BUTTON1);
DisplayNum(accumulator_trip);
Delay(2000, BUTTON1);
}
current_state = FREE; // Go to FREE state.
CleanUp(); // Reinitialize accumulators.
return;
}
/************************************************************
State - Extras
************************************************************/
/**
* Extras: Adds one or more extra charges to the extras'
* accumulator. It can also clear this accumulator.
*
* Parameters: none.
*
* Variables read: pushed_buttons.
*
* Variables modified: accumulator_extras.
* arr_display[5]
* current_state.
*
* Subfunctions: DisplayMsg().
* Delay().
*
* Return: void
*/
void Extras(void) {
Byte _extra_ch_temp = 1; // The extra charges go from 1 to 9
DisplayMsg(EXTRA_STATE_MSG1); // Display "PLUS" leyend for one second
WaitForButtonsRelease();
Delay(1000, BUTTON2&BUTTON3);
DisplayMsg(EXTRA_STATE_MSG2); // For default start in extra charge #1
WaitForButtonsRelease();
while (-1) {
Delay(10000, BUTTON2&BUTTON3&BUTTON5); // If in 10 seconds the user doesn't do
// anything, then go back to FREE state
if (pushed_buttons != NO_BUTTON) { // If the user pressed the button number ...
if (pushed_buttons == BUTTON2) { // 2 -> Go to FARES state
current_state = FARES;
return;
}
if (pushed_buttons == BUTTON5) { // 5 -> Handle the accumulator_extras
if (_extra_ch_temp == 0) {
accumulator_extras = 0; // Erase accumulator_extras
} else {
accumulator_extras += EXTRA_TABLE[_extra_ch_temp-1]; // Add an extra
}
current_state = FREE; // Go to FREE state.
return;
}
if (pushed_buttons == BUTTON3) { // 3 -> Go to the next extra charge
_extra_ch_temp++;
if (_extra_ch_temp > EXTRAS_NUMBER) {
_extra_ch_temp = 0;
}
if (_extra_ch_temp == 0) {
DisplayMsg(EXTRA_STATE_MSG_ERASE);
} else {
DisplayMsg(EXTRA_STATE_MSG2);
arr_display[5] = TRANSLATE_NUMBER[_extra_ch_temp];
}
WaitForButtonsRelease();
}
} else { // 10 seconds went by and no buttons were pressed
current_state = FREE; // Go to FREE state
return;
}
}
}
/************************************************************
State - Fares
************************************************************/
/**
* Fares: Selects the fare type to use as well as the
* initial charge corresponding to that fare.
*
* Parameters: none.
*
* Variables read: pushed_buttons.
*
* Variables modified: fare_active.
* ini_ch_active.
* current_state.
* arr_display[0].
* fare_type.
*
* Subfunctions: DisplayMsg().
* Delay().
*
* Return: void
*/
void Fares(void) {
Byte *_tarMsg;
_tarMsg = &FARE_MESSAGE_TABLE[(fare_type * 5)];
DisplayMsg(FARE_STATE_MSG); // Display "FARE " for 1 second
WaitForButtonsRelease();
Delay(500, BUTTON2&BUTTON3); // Wait one second
DisplayMsg(_tarMsg); // Display the active-fare message
WaitForButtonsRelease();
while (-1) {
Delay(10000, BUTTON2&BUTTON3&BUTTON5); // If in 10 seconds the user doesn't do
// anything, then go back to FREE state
if (pushed_buttons != NO_BUTTON) { // If the user presses the button number ...
if (pushed_buttons == BUTTON2) { // 2 -> Go to FREE state
current_state = FREE;
return;
}
if (pushed_buttons == BUTTON5) { // 5 -> Change the active fare
fare_active = FARE_TABLE[fare_type];
ini_ch_active = INI_CH_TABLE[fare_type];
arr_display[0] = TRANSLATE_NUMBER[fare_type+1];
current_state = FREE; // Go to FREE state
return;
}
if (pushed_buttons == BUTTON3) { // 3 -> Go to the next fare
fare_type++;
if (fare_type >= FARES_NUMBER) {
fare_type = 0;
}
_tarMsg = &FARE_MESSAGE_TABLE[(fare_type * 5)];
DisplayMsg(_tarMsg);
WaitForButtonsRelease();
}
} else { // 10 seconds went by and no buttons were pressed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -