How to change a Single bit in MikroC

Status
Not open for further replies.

Peter_wadley

New Member
Hey,

Just wondering how you change a single bit in MikroC...

that is, what is the equivalent of this assembly:

BSF PORTA,1

in MikroC?


Seems simple enough but I haven't been able to find the syntax...
 
I don't use microC but in other Cs it's done in various ways.

PORTA.1=1;
PORTA|=2;
RA1=1;
PORTAbits.RA1=1;

Most of the compilers I've seen will turn any of the above into a single bsf instruction.

Edit, forgot I have the manual here. It's PORTA.F1=1;
Why F1 I have no idea.

Mike.
 
Last edited:
Bit Addressing

Taken from the Mikroe documentation


Also have a look at this thread - I know it's on MikroB but most of their compliers are the same.

Hope this helps
 
Last edited:
You use the PORTA.f0
Edit, forgot I have the manual here. It's PORTA.F1=1;
Why F1 I have no idea.
It's kind of crazy They use the PORT.F1 the f matches the numbers on there
experimenter boards that way if you wanted to use pin f1 you use porta.f1.
I like using it for small chips
You can all so hit a bit like this
Code:
         PORTB |=  (1<<5);  // Sets bit five of portb
 
If you are going to use different compilers I suggest you set bits using compiler independent code.

Masking as described by Daniel Johnson in JPUG#1 will work.

3v0
 
The good thing about this is it works in any C boostC HI-tech C18 microC you name it
Code:
PORTB |=  (1<<0);  // Sets bit O of portb
PORTB |=  (1<<1);  // Sets bit one of portb
PORTB |=  (1<<2);  // Sets bit two of portb
PORTB |=  (1<<3);  // Sets bit threeof portb
PORTB |=  (1<<4);  // Sets bit four of portb
PORTB |=  (1<<5);  // Sets bit five of portb
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…