⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intex2.c

📁 startup code has configured Timer0
💻 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 + -