📄 test._c
字号:
//ICC-AVR application builder : 2007-8-2 13:09:26
// Target : M16
// Crystal: 8.0000Mhz
#include <iom16v.h>
#include <macros.h>
unsigned char data = 0x1;
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER1 initialize - prescale:64
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 200mSec
// actual value: 200.000mSec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xeE; //setup
TCNT1L = 0x58;
OCR1AH = 0x61;
OCR1AL = 0xA8;
OCR1BH = 0x61;
OCR1BL = 0xA8;
ICR1H = 0x61;
ICR1L = 0xA8;
TCCR1A = 0x00;
TCCR1B = 0x03; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
//TIMER1 has overflowed
TCNT1H = 0xef; //reload counter high value
TCNT1L = 0x58; //reload counter low value
if(data == 0x01)
data = 0;
else
data = 1;
PORTB = data;
}
//call this routine to initialize 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 initialized
}
//
void main(void)
{
init_devices();
//insert your functional code here...
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -