Also im Simulator funktioniert es bei mir!
Code:
/*
* Servopuls.cpp
*
* Created: 06.09.2021 19:19:49
* Author : USER
*/
/********** ATtiny84A 8MHz ***************/
#include<avr/io.h>
#include<avr/interrupt.h>
#define F_CPU 8000000UL
uint16_t start_puls,end_puls,laenge_puls;
uint8_t steigend, fallend;
void init_timer_0 (void)
{
TCCR0A = 0x00;
TCCR0B = (1<<CS01) + (1<<CS00);
TIMSK0 = (1<<TOIE0) ;
TCNT0 =131;
}
void init_timer_1(void)
{
TCCR1A=0x00;
TCCR1B= (1<<CS11);
}
ISR (INT0_vect)
{
if (steigend == 1)
{
start_puls=TCNT1;
steigend=0;
MCUCR |= (1<<ISC01);
MCUCR &= ~(1<<ISC00);
}
else
{
end_puls=TCNT1;
laenge_puls=end_puls-start_puls;
steigend=1;
MCUCR |= (1<<ISC01);
MCUCR |= (1<<ISC00);
}
}
int main(void)
{
init_timer_1();
DDRA = 0xFF;
DDRB &= ~(1<<PORTB2);
MCUCR |= (1<<ISC01) | (1<<ISC00); // INT0 auf steigende Flanke
GIMSK |= (1<<INT0);
sei();
while(1)
{
if (laenge_puls<1300)
{
PORTA = 0b00000001;
}
if ((laenge_puls>1300)&&(laenge_puls<1700))
{
PORTA = 0b00000010;
}
if(laenge_puls>1700)
{
PORTA = 0b00000100;
}
}
}
Lesezeichen