Other Parts Discussed in Thread: MSP430G2553
Tool/software: Code Composer Studio
when i try to define dirction port by bitwise opperation like that
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define SETBIT(VAR,BITNO) VAR|= (1<<BITNO) <---------------------------
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
it work fine and i can made pin number 0 had output diection like that
SETBIT(PORT1,BITNO) // made pin number 0 output diection .
but when i made liberary to called in main.c
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Set_Pin_direction(u8 port_id,u8 pin_id,u8 pin_direction)
{
if (port_id<=PORT_D && pin_id<=DIO_PIN_7)
{
if(pin_direction==OUTPUT)
{
switch(port_id)
{
case PORT_A: SET_BIT(DDRA_REG,pin_id); break; <------ this is from my made DIO_prog.c
case PORT_B: SET_BIT(DDRB_REG,pin_id); break;
case PORT_C: SET_BIT(DDRC_REG,pin_id); break;
case PORT_D: SET_BIT(DDRD_REG,pin_id); break;
}
}
else if (pin_direction==INPUT)
{
switch(port_id)
{
case PORT_A: CLR_BIT(DDRA_REG,pin_id); break;
case PORT_B: CLR_BIT(DDRB_REG,pin_id); break;
case PORT_C: CLR_BIT(DDRC_REG,pin_id); break;
case PORT_D: CLR_BIT(DDRD_REG,pin_id); break;
}
}
}
else
{
/*do nothing*/
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
i made the porogram like that to made it more modelar and avoid spageti code
it made activate pin 1 instead pin 0 in port 1 and that made me very upset
so
why did the program do that (shifting pin number by one )?
thank you