freescale
来自「Freescale 系列单片机常用模块与综合系统设计」· 代码 · 共 129 行
TXT
129 行
/** ###################################################################
** Filename : Events.C
** Project : taxi_meter
** Processor : MC9S08JM60CLHE
** Component : Events
** Version : Driver 01.02
** Compiler : CodeWarrior HCS08 C Compiler
** Date/Time : 2010-1-5, 19:04
** Abstract :
** This is user's event module.
** Put your event handler code here.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/* MODULE Events */
#include "Cpu.h"
#include "Events.h"
#include "taximeter.h"
/* User includes (#include below this line is not maintained by Processor Expert) */
/*
** ===================================================================
** Event : Timer (module Events)
**
** Component : Timer_1ms [TimerInt]
** Description :
** When a timer interrupt occurs this event is called (only
** when the component is enabled - <Enable> and the events are
** enabled - <EnableEvent>). This event is enabled only if a
** <interrupt service/event> is enabled.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void Timer(void)
{
/* Write your code here ... */
PTBD = DISPLAY_OFF; // Turn off the display currently on
arr_display_index++; // Select the next display
display_en = (display_en << 1); // Enable the next display
if(arr_display_index >= 6) {
read_buttons_time++;
if(read_buttons_time == 5) { // Read buttons every 30 ms (6 displays * 5 read_buttons_time)
read_buttons_time = 0;
PTASE = 0x3F; // Enable internal pull-up resistors in port A
PTADD = 0x00; // Configure port A as input
pushed_buttons = PTAD;
pushed_buttons &= 0x1F;
PTADD = 0xFF; // Configure port A as outputs (pull-up resistors are automatically disabled)
}
arr_display_index = 0; // Turn on display 0
display_en = 0x01;
}
PTAD = display_en;
PTBD = arr_display[arr_display_index];
if (flag_charge == CHARGE) { // Compare the time elapsed so far with the max.
accumulator_time++; // time before an increment to the total charge
if (accumulator_time >= inc_time) {
accumulator_time = 0;
accumulator_pulses = 0;
accumulator_trip += fare_active;
accumulator_inc++; // There has been an increment
}
}
counter_ms++; // General purpuose time counter
clock_ms ++; // Clock counter updates
if (clock_ms == 60000) { // 60,000 ms = 1 min.
clock_ms = 0;
clock_minutes++;
if (clock_minutes == 60) {
clock_minutes = 0;
clock_hours++;
if (clock_hours == 24) {
clock_hours = 0;
}
}
}
}
/*
** ===================================================================
** Event : IRQ_OnInterrupt (module Events)
**
** Component : IRQ [ExtInt]
** Description :
** This event is called when an active signal edge/level has
** occurred.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void IRQ_OnInterrupt(void)
{
/* place your IRQ interrupt procedure body here*/
if (flag_charge == CHARGE) { // If it's in service...
accumulator_pulses++;
if (accumulator_pulses >= inc_distance) { // Compare the distance traveled so far with the max.
accumulator_pulses = 0; // distance before an increment to the total charge
accumulator_time = 0; // Reset accumulators
accumulator_trip += fare_active; // Update the amount to charge
accumulator_inc++; // There has been an increment.
}
}
accumulator_distance_traveled++;
counter_pulses++; // General purpose pulse counter
}
/* END Events */
/*
** ###################################################################
**
** This file was created by Processor Expert 3.07 [04.34]
** for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?