因为都是学徒啊,没有高手啊,就我浅显的目光看,你的定时器0初始化好像就不正常。这个初始化你看满意不?- //ICC-AVR application builder : 2016-8-24 AM 10:53:33
- // Target : M16
- // Crystal: 8.0000Mhz
- #include <iom16v.h>
- #include <macros.h>
- //TIMER0 initialize - prescale:64
- // WGM: Normal
- // desired value: 625uSec
- // actual value: 624.000uSec (0.2%)
- void timer0_init(void)
- {
- TCCR0 = 0x00; //stop
- TCNT0 = 0xB2; //set count
- TCCR0 = 0x03; //start timer
- }
- #pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
- void timer0_ovf_isr(void)
- {
- TCNT0 = 0xB2; //reload counter value
- }
- //call this routine to initialize all peripherals
- void init_devices(void)
- {
- //stop errant interrupts until set up
- CLI(); //disable all interrupts
- timer0_init();
- MCUCR = 0x00;
- GICR = 0x00;
- TIMSK = 0x01; //timer interrupt sources
- SEI(); //re-enable interrupts
- //all peripherals are now initialized
- }
|