📄 yykk_006.c
字号:
//ICC-AVR application builder : 2006-11-25 0:15:12
// Target : M16
// Crystal: 7.3728Mhz
#include
#include
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
DDRB = 0x08; //PB3为PWM输出,非常重要,否则无法输出波形
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER0 initialize - prescale:64
// WGM: Normal
// desired value: 1KHz
// actual value: 1.002KHz (0.2%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x8D; //set count /*TCNT0*/
OCR0 = 0x73; //set compare /*OCR0*/
TCCR0 = 0x23; //start timer /*TCCR0*/
}
#pragma interrupt_handler timer0_comp_isr:20
void timer0_comp_isr(void)
{
//compare occured TCNT0=OCR0
}
#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{
TCNT0 = 0x8D; //reload counter value
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x03; //timer interrupt sources /*TIMSK*/
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void) /*加上这些,程序就可以运行了。*/
{
init_devices();
while(1)
;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -