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

📄 freescale

📁 Freescale 系列单片机常用模块与综合系统设计
💻
📖 第 1 页 / 共 2 页
字号:
            current_state = FREE;         // Go to FREE state
            return;
        }
    }
}

/************************************************************
                        State - Clock
************************************************************/
/**
 * Clock: Display the time.
 *        The hour and minute counters are managed in the
 *        Timer ISR
 *
 * Parameters:         none.
 *
 * Variables read:     pushed_buttons.
 *                     clock_hours.
 *                     clock_minutes.
 *
 * Variables modified: clock_hours.
 *                     clock_minutes.
 *                     current_state.
 *
 * Subfunctions:       DisplayMsg().
 *                     DisplayNum().
 *                     Delay().
 *
 * Return: void
 */
void Clock(void) {
    unsigned long _time;    
    
    DisplayMsg(CLOCK_STATE_MSG);                  // Display "TIME " for 1 second
    WaitForButtonsRelease(); 
    Delay(1000, BUTTON3);
    while(pushed_buttons != BUTTON3) {            // Display the time until button 3 is pressed
        _time = (clock_hours * 100) + clock_minutes; 
        DisplayNum(_time);    
        if (pushed_buttons == BUTTON1) {          // Hours ++
            clock_hours++;
            if (clock_hours >= 24) { 
                clock_hours = 0;
            }
            WaitForButtonsRelease(); 
        }
        if (pushed_buttons == BUTTON2) {          // Minutes ++
            clock_minutes++;
            if (clock_minutes >= 60) {
                clock_minutes = 0;
            } 
            WaitForButtonsRelease(); 
        }
    }
    current_state = SPEEDOMETER;                  // Go to SPEEDOMETER state
}

/************************************************************
                    State - Speedometer
************************************************************/
/**
 * Speedometer: Shows the speed at which the car is traveling.
 *              The speed is calculated as following:
 *                     #of-wheel-turns / time
 *              It is assumed that the perimeter of the wheel
 *              is one meter.
 *              The speedometer has a resolution of 2.4 Km/h,
 *              this resolution can be improved by increasing
 *              the _time and re-calculate the _factor.
 *
 * Parameters:         none.
 *
 * Variables read:     pushed_buttons.
 *                     counter_ms.
 *                     counter_pulses.
 *
 * Variables modified: counter_ms.
 *                     counter_pulses.
 *                     current_state.
 *
 * Subfunctions:       DisplayMsg().
 *                     DisplayNum().
 *                     Delay().
 *
 * Return: void
 */
void Speedometer(void) {
    Byte _current = 0;                      // number of pulses in current time interval
    Byte _previous = 0;                     // number of pulses in previous time interval                    
    unsigned long _spd;                     // velocidad = 0
    const int _time = 1500;                 // time of each sample
    const int _factor = 240;                // to translate to Km/h
    
    DisplayMsg(SPEED_STATE_MSG);            // Display "SPEED" for 1 second
    WaitForButtonsRelease(); 
    Delay(1000, BUTTON3);
    counter_ms = 0;                         // resent general purpose counters
    counter_pulses = 0;                     //        for distance and time
    while(pushed_buttons != BUTTON3) {      // Display speed until button 3 is pressed
        _spd = (unsigned long) ((_current + _previous) / 2) * _factor; 
                                            // Speed = #pulses * 240; 240 is a factor to go
        DisplayNum(_spd);                   //        from (pulses/1.5secs) to (Km/h)
        if(counter_ms >= _time) {    
            _previous = _current;
            _current = (Byte) counter_pulses;
            counter_pulses = 0;            
            counter_ms = 0;                
        }
    }
    current_state = PULSES;                 // Go to PULSES state
}

/************************************************************
                        State - Pulses
************************************************************/
/**
 * Pulses: Verifies that the wheel-turn transductor is working
 *         properly. It counts the number of pulses caused
 *         by the turn of the wheels and it displays it. It 
 *         can also reset or freeze the counter.
 *
 * Parameters:         none.
 *
 * Variables read:     pushed_buttons.
 *                     counter_pulses.
 *
 * Variables modified: counter_pulses.
 *                     current_state.
 *
 * Subfunctions:       DisplayNum().
 *                     Delay().
 *
 * Return: void
 */
void Pulses(void) {

    DisplayMsg(PULSE_STATE_MSG);            // Display lenyed "PULSE" for 1 second
    WaitForButtonsRelease(); 
    Delay(1000,BUTTON3);                    // Wait 1 second
    WaitForButtonsRelease(); 
    counter_pulses = 0;
    while (pushed_buttons != BUTTON3) {     // Display the number of pulses it it 
        DisplayNum(counter_pulses);        //        receiving until the user press button 3
        if (pushed_buttons == BUTTON1) {
            counter_pulses = 0;             // Button 1 = reset
        }
        if (pushed_buttons == BUTTON2) {
            Delay(20000,BUTTON1);           // Button 2 = freeze
        }
    }
    current_state = FREE;                   // Go to FREE state
}

/************************************************************
                        State - Informaton
************************************************************/
/**
 * Info: Displays the desired information and the accumulators.
 *       The information to be displayed is stored in
 *       INFO_TABLE. It can display 3 messages (8 character
 *       long each message). It also displays the accumulators
 *       stored in flash. The accummulators are displayed in
 *       the following order:
 *              TOTAL_DISTANCE_TRAVELED
 *              TOTAL_DISTANCE_IN_SERVICE
 *              TOTAL_NUMBER_TRAVELS
 *              TOTAL_NUMBER_INCREMENTS
 *              TOTAL_INCOME
 *
 * Parameters:         none.
 *
 * Variables read:     pushed_buttons.
 *
 * Variables modified: current_state.
 *
 * Subfunctions:       DisplayMsg().
 *                     DisplayNum().
 *                     Delay().
 *
 * Return: void
 */
void Info(void) {
    Byte _char_offset=0;
    Byte _message_offset=0;
    ulong *_acc_table;   

    _acc_table = &TOTAL_DISTANCE_TRAVELED;   
    DisplayMsg(INFO_STATE_MSG);             // Display leyend "INFOR" for 1 second
    WaitForButtonsRelease();
    Delay(1000,BUTTON4);                    // Wait 1 second
    WaitForButtonsRelease(); 
    while (pushed_buttons != BUTTON4) {     // Show informaiton until the user
        if(_message_offset < 24){           //    presses button 4
            DisplayMsg(&INFO_TABLE[_message_offset + _char_offset]);
            _char_offset++;
            if (_char_offset > 3) {         // Since the messages are 8 char long
                _char_offset = 0;           //    it has to scroll 3 times.
            }
        } else {
            DisplayNum(*_acc_table + 1);    // Accumulators are initialized in -1
        } 
        Delay (800, BUTTON4&BUTTON3);    
        if (pushed_buttons == BUTTON3) {    // Button 3 -> Next message
            WaitForButtonsRelease();
            _message_offset += LENGTH_MESSAGE;
            _char_offset = 0;
            if (_message_offset > LENGTH_3_MESSAGES) {
                _acc_table++;               // Point to next accumulator
            }
            if (_message_offset == LENGTH_8_MESSAGES) {     // More than 7 messages 
                _message_offset = 0;
                _char_offset = 0;
                _acc_table = &TOTAL_DISTANCE_TRAVELED;
            }
        }
    }
    current_state = FREE;
}

/************************************************************
                        State - Off
************************************************************/
/**
 * Off: Add up to accumulators and store in flash the Km
 *      traveled since the last time it was stored.
 *      Turns displays off.
 *      Exit this state with any button pushed.
 *
 * Parameters:         none.
 *
 * Variables read:     pushed_buttons.
 *
 * Variables modified: current_state.
 *
 * Subfunctions:       DisplayMsg().
 *
 * Return: void
 */
void Off(void) { 
    DisplayMsg(EMPTY_MSG);
    arr_display[0] = 0xFF;
    WaitForButtonsRelease();
    while ((pushed_buttons == NO_BUTTON) || pushed_buttons == BUTTON5)  // Turn on displays with any button press
        {;} // Empty Body
    arr_display[0] = TRANSLATE_NUMBER[fare_type+1];    
    current_state = FREE;
}

⌨️ 快捷键说明

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