#define set_bit(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define clear_bit(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define toggle_bit(ADDRESS,BIT) (ADDRESS ^= (1<<BIT))
#define test_bit(ADDRESS,BIT) (ADDRESS & (1<<BIT))
#define _TOTAL_LIGHTS 5
void some_function(void)
{
for(i = 0; i<_TOTAL_LIGHTS; i++)
{
if (test_bit(PORTD, i))
{
set_bit(PORTC, i);
}
else
{
clear_bit(PORTC, i);
}
}
}
You can always pass the port by reference, ie, by passing the address of the port:I have often wanted to pass a port or latch in a function call myself. ... I realize you can do it with #defines but it would be nice to be able to pass a port or latch as a argument in a function.
void ClrPort(near unsigned char* Port);
void main (void)
{
ClrPort(&LATA);
}
void ClrPort(near unsigned char* Port)
{
*Port = 0;
}
I am using 16F , so i cant use the LATCHAs long as you insist on using a loop you will be using more code and a longer time to execute then just doing a direct assignment:
Rich (BB code):LATC.B0 = PORTD.B0; LATC.B1 = PORTD.B1; LATC.B2 = PORTD.B2; LATC.B3 = PORTD.B3; LATC.B4 = PORTD.B4;
They you use PORT.I am using 16F , so i cant use the LATCH
Patient said:Doctor, it hurts when I do this.
Doctor said:Then don't do that.
nice , hahhhaOriginally Posted by Patient
Doctor, it hurts when I do this.
Quote:
Originally Posted by Doctor
Then don't do that.
Just declare all of your variables globally. Buy a PIC with enough RAM first.I have often wanted to pass a port or latch in a function call myself. I have yet to figure out a way to do it.
pseudo code example
void foo(PortType port)
{
port = 1;
}
I realize you can do it with #defines but it would be nice to be able to pass a port or latch as a argument in a function.
by Jake Hertz
by Jake Hertz
by Aaron Carman
by Duane Benson