Hello Friends i dont know what happen neither switch-case nor if,else statement works for me i want to give some data to both PORTB & PORTD when some specific data are come to the PORTA register in my "switch block" previously i used PINA instead of PORTA but it still not works but when i start debugging and giving some data by giving PORTA=0b00001110 it easily gives values PORTB=0b00000010.... please help..
/*
* robotic_arm.c
*
* Created: 2/3/2015 10:39:25 AM
* Author: Shrikant Vaishnav
*/
#define F_CPU 1600000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{ DDRA=0x00;//make PORTA as input
DDRB=0xFF;//make PORTB as output
DDRD=0XFF;//make PORTD as output
while(1)
{
switch(PORTA)
{
//First Three conditions for Robotic ARMs
case 0b00001110:
{
PORTB=0b00000010;
_delay_ms(50);
break;
}
case 0b00001101:
{
PORTB=0b00001000 ;
_delay_ms(50);
break;
}
case 0b00001011:
{
PORTB=0b00100000 ;
_delay_ms(50);
break;
}
//Condition for Direction Change of Motors of Robotic Arms
case 0b00000110:
{
PORTB=0b00000001;
_delay_ms(50);
break;
}
case 0b00000101:
{
PORTB=0b00000100;
_delay_ms(50);
break;
}
case 0b00000011:
{
PORTB=0b00100000;
_delay_ms(50);
break;
}
//Now Driving Robotic Car
case 0b00000010:
{
PORTD=0b00000010;
_delay_ms(50);
break;
}
case 0b00000001:
{
PORTD=0b00000001;
_delay_ms(50);
break;
}
default:
{
PORTB=0b00000000; //0ff motors when no signal sent
PORTD=0b00000000; //OFF DRIVING CAR
_delay_ms(50);
break;
}
}
}
return 0;
}