📄 wave50%.c
字号:
//ICC-AVR application builder : 2007-9-8 下午 05:22:48
// Target : M16
// Crystal: 16.000Mhz
#include <iom16v.h>
#include <macros.h>
void port_init(void)
{
PORTA = 0xFF;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0xFF;
PORTC = 0xFF; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0xFF;
}
//TIMER0 initialisation - prescale:8
// WGM: Normal
// desired value: 15KHz
// actual value: 15.038KHz (0.3%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x7B; //set count
OCR0 = 0x85; //set compare
TCCR0 = 0x12; //start timer
}
//TIMER1 initialisation - prescale:1
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 125KHz
// actual value: 125.000KHz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFF; //setup
TCNT1L = 0x80;
OCR1AH = 0x00;
OCR1AL = 0x80;
OCR1BH = 0x00;
OCR1BL = 0x60;
OCR1CH = $OCR1CH$;
OCR1CL = $OCR1CL$;
ICR1H = 0x00;
ICR1L = 0x80;
TCCR1A = 0x50;
TCCR1B = 0x01; //start Timer
}
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialised
}
void main()
{
init_devices();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -