__INLINE static void Delay (uint32_t dlyTicks) { uint32_t curTicks; curTicks = msTicks; while ((msTicks - curTicks) < dlyTicks); } |
volatile int timer; volatile int flag; [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][B]SysTick_Handler[/B]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]) [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Interrupt handler[/COLOR][/SIZE][/COLOR][/SIZE] [LEFT][SIZE=2]{[/SIZE] [SIZE=2]timer++; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[U]inc[/U] counter[/COLOR][/SIZE][/COLOR][/SIZE] [LEFT][SIZE=2][SIZE=2]if (timer >= 100)[/SIZE][/SIZE] [SIZE=2]{[/SIZE] [SIZE=2]flag =1; //set flag[/SIZE] [SIZE=2]timer =0;[/SIZE] [SIZE=2]}[/SIZE] [SIZE=2]}[/SIZE][/LEFT] [/LEFT] |
if (SysTick_Config(SystemCoreClock / 1000)) { /* Setup SysTick Timer for 1 msec interrupts */ while (1); /* Capture error */ } |
void SysTick_Handler(void) { msTicks++; /* increment counter necessary in Delay() */ } |
void initOC1() {// init ISR TCCR1A = 0; TCCR1B = 0b00001010; OCR1A = 1250 << 4; TIMSK = TIMSK | 0x10; } ISR (SIG_OUTPUT_COMPARE1A) { // do something } int main(void) { initOC1(); SREG |= 0x80; // now ISR (SIG_OUTPUT_COMPARE1A) will run automatically } |