#include <avr/io.h>
#include <avr/interrupt.h>
unsigned int zx=0,zy=0;
void motorxR(unsigned int schr);
void motorxL(unsigned int schr);
int main()
{
DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB3)|(1<<PB4)| (1<<PB5); // PIN0-5 als Ausgang für die Motoren definieren // PortB als Ausgang definieren
DDRC = 0; //PORTC als Eingang für PCINT MASK 1 definieren
TCCR1A = (1<<COM1A0) | (0<<WGM11);
TCCR1B = (0<<WGM13) | (1<<WGM12) | (1<<CS10);
OCR1A=18432;
//****************** Interrupt initialisieren *************************************
PCMSK1 = (1 << PCINT
|(1 << PCINT9)|(1 << PCINT10)|(1 << PCINT11)|(1 << PCINT12)|(1 << PCINT13); //Pin C0-5 für Pin Change Interrupt in Maske 1 setzen
PCICR |= (1 << PCIE1); //Pin Change Interrupt Control Register - PCIE3 setzen für PCINT30
//*********** TIMER1 OVF *****************
TIMSK1|=(1<<TOIE1);
sei();
while (1) {}
}
ISR(TIMER1_OVF_vect)
{
zx++;
if(zx>100)
{
PORTB&=~(1<<PB0);
TCCR1B&=~(1<<CS10);
}
zx=0;
}
ISR(PCINT1_vect) //Interrupt Service Routine
{
if(!(PINC&(1<<PC0)))
{motorxR(zx);
}
if(!(PINC&(1<<PC1)))
{motorxL(zx);
}
}
void motorxR(unsigned int schr)
{
PORTB|=(1<<PB4);
PORTB|=(1<<PB0);
}
void motorxL(unsigned int schr)
{
PORTB&=~(1<<PB4);
PORTB|=(1<<PB0);
}
Lesezeichen