Jump to content
Sign in to follow this  
jetster94

Wrong Condition Accessed !

Recommended Posts

Hi !

 

I've just written a simple program using PIC16F873. Configuring port b as input and port a as output, my program is using a switch/case structure.

 

First, the bit masking does not seem to work properly when written in that way.

Secondly, even if I present 0x03 on port b, the "case 0x01" is being executed anyway. Note that the first case 0x00 works properly. The debugger is also behaving in that "strange" way. COuld you please help me?

 

Thanks!!

 

---------------------------

 

void main()

{

trisb = 0xFF; //configure port B

trisa = 0x00;

spbrg = 25;

txsta = 0x26;

rcsta = 0x90;

 

 

 

#ifdef _PIC16

porta = 0x00; //clear port A

 

 

 

#endif

 

 

while(1) //endless loop

{

read=(portb&&0x03);

switch (read)

{

 

case 0x00 :

porta=0x01;

delay_s(1);

porta=0x00;

delay_s(1);

break;

 

case 0x01 :

porta=0x01;

delay_ms(50);

porta=0x00;

delay_ms(50);

break;

 

 

case 0x03 :

porta=0x01;

delay_ms(200);

porta=0x00;

delay_ms(200);

break;

 

 

 

}

}

}

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...