Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <hidef.h> /* common defines and macros */
- #include <mc9s12dg256.h> /* derivative information */
- #pragma LINK_INFO DERIVATIVE "mc9s12dg256b"
- #include "main_asm.h" /* interface to the assembly module */
- #define oneSecond 97
- #define twoSeconds 194
- #define halfSecond 48
- #define taskOne 1
- #define taskTwo 2
- #define taskThree 3
- #define taskFour 4
- #define loopTask 5
- #define reset 0
- #define forever 1
- #define LEDOn 1
- #define toggle 0x01
- #define shortDelay 25
- unsigned short ticks = reset ;
- int task = taskOne;
- /*
- Ticks is how we are setting the ON/OFF duration
- Each tick, we increment and wait until a value
- Corresponding with the length of time we want is reached
- Then we XOR the port and reset the ticks
- */
- void interrupt 7 handler() {
- ticks++;
- if(task == taskOne){
- if(ticks >= halfSecond){
- PORTB = PORTB^toggle;
- ticks = reset;
- }
- clear_RTI_flag();
- }
- if(task == taskTwo){
- if(ticks == oneSecond){
- PORTB = PORTB^toggle;
- ticks = reset;
- }
- clear_RTI_flag();
- }
- if(task == taskThree){
- if(ticks == twoSeconds){
- PORTB = PORTB^toggle;
- ticks = reset;
- }
- clear_RTI_flag();
- }
- }
- /*
- When a button is pressed, we move to the next task
- The tasks are cycled in order (one,two,three,four)
- And when the last task is completed, the next task
- Will be taskOne again (one, two, three, four, one,..)
- Special Case: If taskFour, disable IRQ and turn off LED
- */
- void interrupt 6 handler1() {
- task++;
- if(task == loopTask){
- task = taskOne;
- RTI_enable();
- PORTB = LEDOn;
- }
- if(task == taskFour){
- RTI_disable();
- PORTB = reset;
- }
- /*
- Debounce
- */
- ms_delay(shortDelay);
- while(SW5_down()) {
- };
- ms_delay(shortDelay);
- }
- /*
- In our main, we are simply allowing our interupts and configuring the LED
- of interest for output
- */
- void main(void)
- {
- PLL_init(); // set system clock frequency to 24 MHz
- seg7_disable();
- led_enable();
- _asm(cli); //enable interrupts
- RTI_init();
- IRQ_enable();
- while(forever) {
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement