📄 main._c
字号:
//ICC-AVR application builder : 2006-10-11 上午 11:30:40
// Target : M8
// Crystal: 6.0000Mhz
#include <iom8v.h>
#include <macros.h>
unsigned char flag =0;
void port_init(void)
{
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//Watchdog initialize
// prescale: 16K
void watchdog_init(void)
{
WDR(); //this prevents a timout on enabling
WDTCR = 0x08; //WATCHDOG ENABLED - dont forget to issue WDRs
}
//TIMER1 initialize - prescale:1
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 320Hz
// actual value: 320.000Hz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xB6; //setup
TCNT1L = 0xC2;
OCR1AH = 0x49;
OCR1AL = 0x3E;
OCR1BH = 0x49;
OCR1BL = 0x3E;
ICR1H = 0x49;
ICR1L = 0x3E;
TCCR1A = 0x00;
TCCR1B = 0x01; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
//TIMER1 has overflowed
TCNT1H = 0xB6; //reload counter high value
TCNT1L = 0xC2; //reload counter low value
if(flag ==0)
{
PORTD |= 0x04;
flag =1;
}else
{
PORTD &= ~(0x04);
flag =0;
}
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
watchdog_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();
DDRD |= 0x04;
PORTD |= 0x04;
flag =1;
while(1)
{
WDR();
}
}
//************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -