ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Четверг
18 июля
4815
nm5 (16.01.2004 17:28, просмотров: 1005)
Почему не запускается ШИМ Если портом PD0 останавлю Шим потом он не запускается Люди подскажите Чайнику Почему не запускается ШИМ Если портом PD0 останавлю Шим потом он не запускается Люди подскажите Чайнику Смотрю в Visual Micro Lab пишет PWM но таймер похоже не работает выход не переключается
//ICC-AVR application builder : 14.01.04 19:57:13
// Target : M8
// Crystal: 4.0000Mhz

#include 
#include 
#define MY_INPUT PD0
void port_init(void)
{
 PORTB = 0x00;
 DDRB  = 0xFF;
 PORTC = 0x7F; //m103 output only
 DDRC  = 0x00;
 PORTD = 0xFF;
 DDRD  = 0x00;
}

//TIMER2 initialisation - prescale:256
// WGM: PWM Fast
// desired value: 120Hz
// actual value: 61,035Hz (96,6%)
void timer2_init(void)
{
 TCCR2 = 0x00; //stop
 ASSR  = 0x00; //set async mode
 TCNT2 = 0x01; //setup
 OCR2  = 0xAF;
 TCCR2 = 0x7E; //start
}

#pragma interrupt_handler timer2_comp_isr:4
void timer2_comp_isr(void)
{
TCNT2=OCR2;

}

//call this routine to initialise all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();
 timer2_init();

 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x80; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialised
}

//
void main(void)
{
    init_devices();

    //insert your functional code here...
//    if (PORTD & PD0) // bit -

    while(1)
	{
	
        if (PIND & (1 << MY_INPUT))
       {
	
		TCCR2 = 0x7E; //start
        }
        else
       {  	

	    
   		 TCCR2 = 0x3E; //stop 
	 	}
	}
  
  
}