?? intex2.c
字號:
// Program 2 from the Using Interrupts example.
// Assumes the startup code has configured Timer0
// for a 25mSec interrupt.
// Use crti_2.s90
// Remember the 32 or so pushes required by the
// <interrupt> qualifier.
// Ron Kreymborg
#include <avrstdio.h>
#define CLOCK 158
void main(void);
void CheckInt(void);
interrupt CTimer0(void);
char IntFlag;
main(void) {
int n;
outp(DDRB, 0xff); // all outputs
outp(PORTB, 0xff); // all high
n = 0; // zero counter
while (1) { // do forever
CheckInt(); // wait for interrupt
if (++n == 40) { // if 40 have occurred
cbip(PORTB, 6); // bit 7 of PORTB low
CheckInt(); // keep low for 25mSec
sbip(PORTB, 6); // bit 7 high again
n = 0; // ready for next cycle
}
}
}
void CheckInt(void) {
while (IntFlag == 0) // wait 25mSecs
;
IntFlag = 0; // must reset flag
}
interrupt CTimer0() {
outp(TCNT0, CLOCK); // reset the timer
IntFlag = 1; // flag 25mSecs done
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -