Atmega128 Program Problem

Thread Starter

hhumberto.av

Joined Jan 16, 2015
3
Hi.

Im trying to move 2 motors with an atmega128 microcontroller. The issue is that i cant change my ports values in execution time. Two results. If i dont call the reverse function, the motor never stops, and if i call reverse() Function, the motor stops, but it doesnt change the movement sense or the moovement speed.

Here my code:


Code:
#include <avr/io.h>
#include <util/delay.h>

int cont=0;

void reverse()
{
          while(1);
        {
            PORTC=0b01010101;
            PORTD|=_BV(PD0); //Se activa el bit 0 del PORTD
            PORTD|=_BV(PD1); //Se activa el bit 1 del PORTB
           
            _delay_us(5000);
            //de la función, con la variable SH, SH veces
           
            PORTD&=~(_BV(PD0)); //Desactiva el bit 0 del PORTD
            PORTD&=~(_BV(PD1)); //Desactiva el bit 1 del PORTB
           
           
            _delay_us(5000);
        }
}

void motors(int pA, int pB, int power, int duration)
{


    //PORTC=0b10101010;
    PORTC=0b01010101;

   
    DDRC= 0xFF; //puerto C como salida
    DDRD= 0xF0;    //Nible alto del puerto D como salida



   
        while (1)
        {
           
            PORTD|=_BV(PD0); //Se activa el bit 0 del PORTD
            PORTD|=_BV(PD1); //Se activa el bit 1 del PORTB
           
            _delay_us(9800);
            //de la función, con la variable SH, SH veces
           
            PORTD&=~(_BV(PD0)); //Desactiva el bit 0 del PORTD
            PORTD&=~(_BV(PD1)); //Desactiva el bit 1 del PORTB
           
           
            _delay_us(200);
           
            //cont++;

        }
       
        //reverse();
       
        //    return 0; //Como la función no es void se regresa un 0
   
   
    return;
}





int main()
{
   
        int power = -40;
       
        int pA=1;
        int pB=2;
        int duration=20;
       
        motors(pA, pB, power, duration);
       
        return 0;
}
 
Top