coding problem???

Thread Starter

fiezzshah

Joined Feb 2, 2010
6
this is my first project..
i'm confuse bcoz some of the coding didn't work when i'm running it..
this is my sample coding...hope someone can help me to expain to me why it happened..

main(){
int cnt, value, Junc;
set_tris_a(0); /* set port_a to be outputs */
set_tris_b(0); /* set port_b to be outputs */
port_a = 0; /* initialize All port_b outp/uts to be zero */
port_b = 0; /* initialize All port_b outp/uts to be zero */
value = 0x01;
while( TRUE )
{ /* forever loop using WHILE construct */
cnt = 1;
value = 0x01;
while ( cnt<9 )
{
for ( ;Junc; )
{

if (port_b = 0x10)
port_a =0x0E;
Delay_MS(8000);

if (port_b = 0x01)
port_a =0x0E;
Delay_MS(2000);

if (port_b = 0x00) <<--/* this coding it didn't work when im running
port_a =0xFF; it..only working when i removed the if
Delay_MS(2000); statement */

}

why it happened???help me...
 

Thread Starter

fiezzshah

Joined Feb 2, 2010
6
the circuit work properly when im using this code:

main(){
int cnt, value, Junc;
set_tris_a(0); /* set port_a to be outputs */
set_tris_b(0); /* set port_b to be outputs */
port_a = 0; /* initialize All port_b outp/uts to be zero */
port_b = 0; /* initialize All port_b outp/uts to be zero */
value = 0x01;
while( TRUE )
{ /* forever loop using WHILE construct */
cnt = 1;
value = 0x01;
while ( cnt<9 )
{
for ( ;Junc; )
{

port_b = 0x10;
port_a =0x0E;
Delay_MS(8000);

port_b = 0x01;
port_a =0x0E;
Delay_MS(2000);

port_b = 0x00;
port_a =0xFF;
Delay_MS(2000);
}
}
 

AlexR

Joined Jan 16, 2008
732
You don't say what language you are using but it looks like C to me so assuming it is C.

Your statement should be;
if(port_b == 0x00)

The statement as you wrote it sets port_b to 0x00 and then test to see if it's true (which it never will be).
 

AlexR

Joined Jan 16, 2008
732
Looking at your first posting you made the same mistake in all of your "if()" statements.

To test of equality you must use a double equal sign as in example if(a == b).

If you use a single equal sign you just assigns the right hand value to the left hand variable so if(a = b) would put the value of b into a and then test to see whether a is true or false.
 
Top