Serwo porusza orczykiem jak chce.
Dodam że wysyłam kod PPM droga radiową do odbiornika i BEZ ATTINY syg. na wyjściu ''data'' jest poprawny, kiedy dodam Attiny2313 syg jest przeróżny.
Układ nadawczy i odbiorczy sa na oddzielnym zasilaniu.
Kod: Zaznacz cały
#include <avr/io.h>
#include <avr/interrupt.h>
#define SER1 PD0
#define SER2 PD1
#define PPM PD3
#define PPM2 PD2
#define led PD4
volatile uint8_t b;
volatile int i;
volatile uint8_t cnt;
volatile int a;
int main(void)
{
DDRD |= (1<<PD5);
PORTD |= (1<<PD5);
DDRD |= (1<<PD6);
PORTD |= (1<<PD6);
DDRD |= (1<<SER1); //wyjście
DDRD |= (1<<SER2); //wyjście
DDRD |= (1<<led);
DDRB = 0xFF;
PORTB = 0xFF;
DDRA = 0xFF;
PORTA = 0xFF;
GIMSK |= (1<<INT1)|(1<<INT0);
MCUCR |= (1<<ISC11)|(1<<ISC00)|(1<<ISC01);
sei
(); // wl.przerwan
while(1)
{
if (b==1)
{
a++;
{
if (a>50)
{ i++;
a=0;
PORTD ^= (1<<PD4);
}
if (i>50)
{
b=0;
}
}
}}
}
ISR (INT0_vect)
{
static uint8_t cntn;
cntn++;
switch (cntn)
{
case(1):
b=1;
MCUCR &=~(1<<ISC00);
break;
case(2):
if (i>45)
{
cnt = 0;
}
i=0;
b=0;
MCUCR |= (1<<ISC00);
cntn=0;
break;
}
}
ISR (INT1_vect)
{
cnt++;
switch(cnt)
{
case(1):
PORTD |= (1<<PD0);
break;
case(2):
PORTD &=~ (1<<PD0);
PORTD |= (1<<PD1);
break;
case(3):
PORTD &=~ (1<<PD1);
break;
}
if(cnt>2)
cnt=0;
}