⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freescale

📁 Freescale 系列单片机常用模块与综合系统设计
💻
字号:
#include "taximeter.h"
 
/************************************************************
                        API - Initialize
************************************************************/
/**
 * Initialize: set all global variables, set up timers and
 *             irq, configure system.
 *
 * Parameters:         none.
 *
 * Variables read:     none.
 *
 * Variables modified: none
 *
 * Subfunctions:       none.
 *
 * Return: void
 */
void System_Initialize (void) {

    current_state = FREE;          // Start in FREE state (Idle State)
/* Displays related variables */    
    PTAD = 0x00;                    // Display enabler (none enabled)
    PTADD = 0xFF;                   // Port A as output    
    PTBD = DISPLAY_OFF;             // Displays off
    PTBDD = 0xFF;                   // Port B as output

    read_buttons_time = 0;         // Counter that indicates when to read buttons
    arr_display_index = 0;         // Display 0 selected; pointer to arr_diplay[]
    display_en = 0x01;             // Enable display 0
    pushed_buttons = NO_BUTTON;    // Button(s) pushed
    
/* Fares related variables */
    fare_type = DAY;                             // Default fare = DAY
    fare_active = FARE_TABLE[FARE_DAY];          // Active fare (according to FARE_TABLE)
    arr_display[0] = TRANSLATE_NUMBER[DAY+1];    // Active fares goes to Display 0
    ini_ch_active = INI_CH_TABLE[INI_CH_DAY];    // Initial charge (according to INI_CH_TABLE)

/* Counters & Accumulators */
    counter_ms = 0;                   // Reset counters
    counter_pulses = 0;            
    accumulator_pulses = 0;        // Reset accumulators
    accumulator_time = 0;    
    accumulator_trip = 0;
    accumulator_inc = 0;
    accumulator_distance_traveled = 0;
    accumulator_extras = 0;
    clock_ms = 0;    
    clock_minutes = 0;       
    clock_hours = 12;                 // Start at 12:00
    
/* Incremental-charge related variables */    
    flag_charge = NO_CHARGE;
    inc_time = 5000;   // Default time for incrementing accumulator_trip = 30 segs
    inc_distance = 45; // Default distance for incrementing accumulator_trip = 100 mts    
       
    return;
}

/************************************************************
                        API - CleanUp
*************************************************************/
/**
 * CleanUp: Reset variables needed to return to idle state
 *
 * Parameters:         none.
 *
 * Variables read:     none.
 *
 * Variables modified: accumulator_extras.
 *                     accumulator_trip.
 *                     accumulator_pulses.
 *                     accumulator_time.
 *                     accumulator_distance_traveled.
 *                     accumulator_inc.
 *
 * Subfunctions:       none.
 *
 * Return: void
 */
void CleanUp(void) { 

    accumulator_extras = 0;
    accumulator_trip = 0;    
    accumulator_pulses = 0;
    accumulator_time = 0;    
    accumulator_distance_traveled = 0;     
    accumulator_inc = 0;
    return;
}

/************************************************************
                        API - Delay
************************************************************/
/**
 * Delay: Waits _ms milliseconds or until one of 
 *        _cancel_buttons is pressed.
 *
 * Parameters: _ms             - number of milliseconds to
 *                               wait before ending function.
 *             _cancel_buttons - buttons that might cause
 *                               the function to end even if
 *                               time has not finished.
 *
 * Variables read:     pushed_buttons.
 *
 * Variables modified: counter_ms.
 *
 * Subfunctions:       none.
 *
 * Return: void
 */
void Delay(Word _ms, Byte _cancel_buttons) {
    counter_ms = 0;
    while ( (counter_ms <= _ms) && ((pushed_buttons | _cancel_buttons) == NO_BUTTON) )
        {;} // Empty Body
    return; 
}

/************************************************************
                 API - WaitForButtonsRelease
************************************************************/
/**
 * WaitForButtonsRelease: Waits until all buttons have been
 *        released.
 *
 * Parameters:         none.
 *
 * Variables read:     pushed_buttons.
 *
 * Variables modified: none.
 *
 * Subfunctions:       none.
 *
 * Return: void
 */
void WaitForButtonsRelease() {
    while (pushed_buttons != NO_BUTTON)     // Wait until the user releases any pushed button(s)
        {;} // Empty Body 
    return; 
}

/************************************************************
                      API - DisplayMsg
************************************************************/
/**
 * DisplayMsg: Sends to the displays the string pointed by _str.
 *             The string must be all upper case characters.
 *
 * Parameters: *_str - pointer to the string to be displayed.
 *                     Only the first five characters of *_str
 *                     will be displayed.
 *
 * Variables read:     none.
 *
 * Variables modified: arr_display[1-5].
 *
 * Subfunctions:       none.
 *
 * Return: void
 */
 void DisplayMsg(const Byte *_str) {
    Byte _i;
    Byte _temp;
    Byte _selector_display;

    for(_i = 0, _selector_display = 1 ; _i<5 ; _i++, _selector_display++) {
        _temp = *(_str + _i);
        arr_display[_selector_display]=TRANSLATE_LETTER[(_temp - 32)]; 
    }
    return;
}

/************************************************************
                      API - DisplayNum
************************************************************/
/**
 * DisplayNum: Sends to the displays the number _num
 *
 * Parameters:         _num - number to be displayed.
 *                          It must be a 5 digit number, where the
 *                          last 2 digits represent decimal values. 
 *                          For example:
 *                          if _num = 12345, the number displayed
 *                          will be 123.45
 *                          If the number is larger than 5 digits
 *                          long, it might not be displayed
 *                          correctly
 *
 * Variables read:     none.
 *
 * Variables modified: arr_display[1-5].
 *
 * Subfunctions:       none.
 *
 * Return: void
 */
 void DisplayNum(ulong _num) {
    Byte _i;                             // general purpose counter
    Word _short_num;                     // the coefficient of _num/10
                                         //    if _num > 6 digits long
                                         //    _short_num is overflowed
    ulong _temp;   
    
    for (_i = 5; _i > 0; _i--) {         // Display 5 numbers.
            _temp = (ulong)(_num / 10);
            _short_num = _temp;          // backup the coefficient
            _temp *= 10;                 // get number without last digit
            _temp = _num - _temp;        // get less significant digit
            _num = _short_num;           // restart process with coefficient
            arr_display[_i] = TRANSLATE_NUMBER[(Byte)_temp];
            if (_i == 3) {
                arr_display[_i] &= SEG_P;// turn on P segment
            }
    }
    return;
}

/* End of tax_API.c */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -