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

📄 lizi.c

📁 AVR16源代码 ICC编译器
💻 C
字号:
//ICC-AVR application builder : 2007-1-20 21:15:04
// Target : M16
// Crystal: 4.0000Mhz

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

void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0x00;
 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
}

//TIMER0 initialize - prescale:8
// WGM: Normal
// desired value: 4Hz
// actual value: Out of range
void timer0_init(void)
{
 TCCR0 = 0x00; //stop
 TCNT0 = 0x00 /*INVALID SETTING*/; //set count
 OCR0  = 0x00 /*INVALID SETTING*/;  //set compare
 TCCR0 = 0x12; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{
 TCNT0 = 0x00 /*INVALID SETTING*/; //reload counter value
}

//TIMER1 initialize - prescale:Stop
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1Hz
// actual value: Out of range
void timer1_init(void)
{
 TCCR1B = 0x00; //stop
 TCNT1H = 0x00 /*INVALID SETTING*/; //setup
 TCNT1L = 0x00 /*INVALID SETTING*/;
 OCR1AH = 0x00 /*INVALID SETTING*/;
 OCR1AL = 0x00 /*INVALID SETTING*/;
 OCR1BH = 0x00 /*INVALID SETTING*/;
 OCR1BL = 0x00 /*INVALID SETTING*/;
 OCR1CH = $OCR1CH$;
 OCR1CL = $OCR1CL$;
 ICR1H  = 0x00 /*INVALID SETTING*/;
 ICR1L  = 0x00 /*INVALID SETTING*/;
 TCCR1A = 0x00;
 TCCR1B = 0x00; //start Timer
}

#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
 //TIMER1 has overflowed
 TCNT1H = 0x00 /*INVALID SETTING*/; //reload counter high value
 TCNT1L = 0x00 /*INVALID SETTING*/; //reload counter low value
}

//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
 UCSRB = 0x00; //disable while setting baud rate
 UCSRA = 0x00;
 UCSRC = BIT(URSEL) | 0x06;
 UBRRL = 0x19; //set baud rate lo
 UBRRH = 0x00; //set baud rate hi
 UCSRB = 0x18;
}

#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
 //external interupt on INT0
}

//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();
 timer0_init();
 timer1_init();
 uart0_init();

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

⌨️ 快捷键说明

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