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

📄 led.c

📁 AVRM16 学习板例程 LED 控制
💻 C
字号:
//ICC-AVR application builder : 2006-11-28 21:10:05
// Target : M16
// Crystal: 6.0000Mhz

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

unsigned char LED_data=1;
void port_init(void)
{
 PORTA = 0xFF;//PA,PB,PC,PD口全部做输出,默认值1
 DDRA  = 0xFF;//
 PORTB = 0xFF;//
 DDRB  = 0xFF;//
 PORTC = 0xFF; //m103 output only
 DDRC  = 0xFF;//
 PORTD = 0xFF;//
 DDRD  = 0xFF;//
}

//TIMER1 initialisation - prescale:1024
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1Hz
// actual value:  1.000Hz (0.0%)
void timer1_init(void)
{
 TCCR1B = 0x00; //stop
 TCNT1H = 0xE9; //setup
 TCNT1L = 0x1D;
 OCR1AH = 0x16;
 OCR1AL = 0xE3;
 OCR1BH = 0x16;
 OCR1BL = 0xE3;
 ICR1H  = 0x16;
 ICR1L  = 0xE3;
 TCCR1A = 0x00;
 TCCR1B = 0x05; //start Timer
}

#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
 //TIMER1 has overflowed
 TCNT1H = 0xE9; //reload counter high value
 TCNT1L = 0x1D; //reload counter low value
 LED_data<<=1;
 if(LED_data ==0)
 LED_data = 1;
 PORTA=LED_data;
 
 
}

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

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

//
void main(void)
{
 init_devices();
 
 //insert your functional code here...
}

⌨️ 快捷键说明

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