Presentation is loading. Please wait.

Presentation is loading. Please wait.

Example 15 Interrupt-Driven Controller

Similar presentations


Presentation on theme: "Example 15 Interrupt-Driven Controller"— Presentation transcript:

1 Example 15 Interrupt-Driven Controller
Lecture L6.2

2

3 Connecting an LED to a Port P pin

4 // Example 15a Traffic Lights
#include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" int dtime; // delay time int ix; // index into states const int numstates = 6; const char PortH[] = { // --RYGRYG 0x0C, // 0x14, // 0x24, // 0x21, // 0x22, // 0x24, // }; const int delay[] = { 488, // 5 sec delay 98, // 1 sec delay 98, // 1 sec delay 488, // 5 sec delay

5 void interrupt 7 handler(){
dtime--; if(dtime == 0){ PTH = PortH[ix]; // turn on next lights dtime = delay[ix]; // get next delay time ix++; // increment index if(ix == numstates){ // after going through all states ix = 0; // reset index to 0 } clear_RTI_flag();

6 void main(void) { PLL_init(); // set system clock frequency to 24 MHz DDRH = 0xFF; // all bits of Port H are outputs RTI_init(); // initialize RTI to ms interrupts ix = 0; // reset index into states dtime = 1; // start traffic light right away while(1) { // do nothing while traffic light goes }

7 Interrupt-Driven Blinking SOS
International Morse Code

8 // Example 15b: Interrupt-Driven Controller: SOS
#include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" unsigned short dtime; // delay time int ix; // index into states const int numstates = 18; const char seg7[] = { 0x6D, 0x00, 0x6D, 0x00, 0x6D, 0x00, // S 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, // O }; const char delay[] = { 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x18, // dots 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, // dashes 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x30, // dots

9 void interrupt 7 handler(){
dtime--; if(dtime == 0){ seg7_on(seg7[ix]); // turn on next display dtime = delay[ix]; // get next delay time ix++; // increment index if(ix == numstates){ // after going through all states ix = 0; // reset index to 0 } clear_RTI_flag();

10 void main(void) { PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); RTI_init(); ix = 0; // reset index into states dtime = 1; // start display right away while(1) { // do nothing while display goes }


Download ppt "Example 15 Interrupt-Driven Controller"

Similar presentations


Ads by Google