Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
LED
/
Sources
:
main.c
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
#include <hidef.h> /* common defines and macros */ #include <mc9s12c32.h> /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12c32" /*************************************************************** * Function prototypes ****************************************************************/ __interrupt void RealTimeInterrupt(void); /**************************************************************** * Local data definitions ****************************************************************/ static volatile unsigned char rtiCnt; /* to count number of RTIs */ void main(void) { DDRB = 0x01; /* set portb pin 0 to output */ PORTB = 0x01; /* turn on LED connected to PB0 */ RTICTL = 0x50; /* 1/(4MHz/2^14) = 4.096 ms per RTI */ CRGINT |= 0x80; /* enable RTI interrupt */ rtiCnt = 0; /* RTI counter to 0 */ asm("cli"); /* enable global interrupts */ for (;;) { /* infinite loop */ if (rtiCnt == 122) { /* 500 ms passed? */ PORTB = ~PORTB; /* toggle LED on/off */ rtiCnt = 0; /* reset rti counter */ } } } /* end main() */ __interrupt void RealTimeInterrupt(void) { rtiCnt++; /* increment the counter */ CRGFLG = 0x80; /* clear rti flag */ } /*end RealTimeInterrupt() */