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

📄 main.c

📁 一个关于AVR单片机的例程
💻 C
字号:
//ICC-AVR application builder : 2007-1-31 21:10:52
// Target : M16
// Crystal: 7.3728Mhz

#include <iom16v.h>
#include <macros.h>

void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0x00;
 PORTB = 0x00;
 DDRB  = 0x08;
 PORTC = 0x00; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
}

#pragma interrupt_handler timer0_comp_isr:20
void timer0_comp_isr(void)
{
 //compare occured TCNT0=OCR0
}

//TIMER0 initialize - prescale:64
// WGM: CTC
// desired value: 1KHz
// actual value:  0.993KHz (-0.7%)
void timer0_init(void)
{
 TCCR0 = 0x00; //stop
 TCNT0 = 0x8D; //set count
 OCR0  = 0x73;  //set compare
 TCCR0 = 0x0B; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{
 TCNT0 = 0x8D; //reload counter value
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();
 timer0_init();

 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x01; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

void main()
{
 init_devices();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -