Jump to content

Confused ? What Am I Doing Wrong ?


Recommended Posts

Since i use boostC i have some problems setting and clearing bits. the problem is when i set a bit in a register it seems to clear all other bit.

 

i just want to set a simple bit for example porta.

#include <system.h>
#pragma CLOCK_FREQ 8000000


void main()
{
trisa=0;
porta=0;

while(1)
{
set_bit( porta, 0 ); //bit1
set_bit( porta, 1 ); //bit2
delay_s(1);
clear_bit( porta, 0 ); //bit1
clear_bit( porta, 1 ); //bit2
delay_s(1);
}	


}

 

so i would expect

porta = 00000001

porta = 00000011

delay

porta = 00000010

porta = 00000000

delay

 

but in my target a 16f877a i only see the led connected to porta.1 blink and not the led connected to porta.0. when i remove the set en clear bit for bit2 the led connected to porta.0 does blink. When i watch the led block in sourceboost i do see what i expected but not in my device.

 

i also used volatile bit pinA1@PORTA.0; but got the same result. so my question is am i expecting wrong things or ??

 

#include <system.h>
#pragma CLOCK_FREQ 8000000

volatile bit pinA1@PORTA.0;
volatile bit pinA2@PORTA.1;

void main()
{
trisa=0;
porta=0;

while(1)
{
pinA1 = 0; //bit1
pinA2 = 0; //bit2
delay_s(1);
pinA1 = 1; //bit1
pinA2 = 1; //bit2
delay_s(1);
}	


}

Link to post
Share on other sites

I had a similar problem with my 16F877 and it turned out it was due to some floating pins...

Check your RB3, 6 and 7 and, if you don't need it, disable the LVP fuse.

 

I don't think the fault is due to the compiler, since I'm using it to blink some LED and, after taking care of floating pins, it works fine.

 

Cheers

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...
×
×
  • Create New...