Witam,
napisałem sobie kod i nie wiem co zrobiłem źle, ale po prostu nie działa. Proszę o pomoc.
/*
* Krokowy.cpp
*
* Created: 2014-10-12 01:28:31
* Author: Pixel
*/
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
bool isright = true;
bool mode = 0;
volatile unsigned short int speed = 1000;
ISR(INT0_vect)
{
speed++;
_delay_ms(500);
}
ISR(INT1_vect)
{
speed--;
_delay_ms(500);
}
ISR(INT2_vect)
{
mode = !mode;
_delay_ms(500);
}
int main(void)
{
MCUCR |= (1 << ISC11) | (1 << ISC10); //Ustawienie bitu przerwań int1 wyzwalanego zboczem wzrastającym
MCUCR |= (1 << ISC01) | (1 << ISC00); // Jak wyżej int0
GICR |= (1 << INT1) | (1 << INT0) | (1 << INT2);
DDRA |= (1 << PA7) | (1 << PA6) | (1 << PA5) | (1 << PA4); // Wyjścia krokowe
DDRA &= (0 << PA3) & (0 << PA2); // Wejścia na regulację kierunku
DDRA |= (1 << PA1) | (1 << PA0); //DIUDY
PORTA |= (1 << PA7) | (1 << PA6) | (1 << PA5) | (1 << PA4) | (1 << PA3) |
(1 << PA2)| (1 << PA1) | (1 << PA0);
// To wyżej to ustawienie wyjść na stan wysoki ( Podciągnięcie do VCC)
DDRD &= (0 << PD2) & (0 << PD3); //Wejścia na przerwania predkosci // predkosc ++ i --
DDRB &= (0 << PB2); // Zmiana kolejności // trybu
PORTD |= (1 << PD2) | (1 << PD3);
PORTB |= (1 << PB2);
sei();
while (1)
{
while(mode == true)
{
if (!(PINA & (1<<PA2)))
{
isright=true;
PORTA |= (1 << PA0);
PORTA &= (0 << PA1);
}
if (!(PINA & (1<<PA3)))
{
isright = false;
PORTA |= (1 << PA1);
PORTA &= (0 << PA0);
}
if (isright == true)
{
PORTA &= (0 << PA7) & (0 << PA6) & (0 << PA5) & (0 << PA4);
PORTA |= (1 << PA7);
for (int i;i == speed;i++)
{
_delay_ms(1);
}
PORTA &= (0 << PA7) & (0 << PA6) & (0 << PA5) & (0 << PA4);;
PORTA |= (1 << PA6);
for (int i;i == speed;i++)
{
_delay_ms(1);
}
PORTA &= (0 << PA7) & (0 << PA6) & (0 << PA5) & (0 << PA4);
PORTA |= (1 << PA5);
for (int i;i == speed;i++)
{
_delay_ms(1);
}
PORTA &= (0 << PA7) & (0 << PA6) & (0 << PA5) & (0 << PA4);
PORTA |= (1 << PA4);
for (int i;i == speed;i++)
{
_delay_ms(1);
}
}
else
{
PORTA &= (0 << PA7) & (0 << PA6) & (0 << PA5) & (0 << PA4);
PORTA |= (1 << PA4);
for (int i;i == speed;i++)
{
_delay_ms(1);
}
PORTA &= (0 << PA7) & (0 << PA6) & (0 << PA5) & (0 << PA4);
PORTA |= (1 << PA5);
for (int i;i == speed;i++)
{
_delay_ms(1);
}
PORTA &= (0 << PA7) & (0 << PA6) & (0 << PA5) & (0 << PA4);
PORTA |= (1 << PA6);
for (int i;i == speed;i++)
{
_delay_ms(1);
}
PORTA &= (0 << PA7) & (0 << PA6) & (0 << PA5) & (0 << PA4);
PORTA |= (1 << PA7);
for (int i;i == speed;i++)
{
_delay_ms(1);
}
}
}
}
}