• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to change a Single bit in MikroC

Status
Not open for further replies.

Pommie

Well-Known Member
Most Helpful Member
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:

gaspode42

Member
Bit Addressing

Taken from the Mikroe documentation

sbit type

The mikroC PRO for PIC compiler has sbit data type which provides access to bit-addressable SFRs. You can access them in the following manner:

sbit LEDA at PORTA.B0;
sbit bit_name at sfr-name.B<bit-position>;

sbit LEDB at PORTB.F0;
sbit bit_name at sfr-name.F<bit-position>;

// If you are familiar with a particular MCU and its ports and direction registers (TRIS), you can access bits by their names:
sbit LEDC at RC0_bit;
sbit bit_name at R<port-letter><bit-position>_bit;

sbit TRISC0 at TRISC0_bit;
sbit bit_name at TRIS<port-letter><bit-position>_bit;
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:

be80be

Well-Known Member
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
 

be80be

Well-Known Member
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.

Latest threads

EE World Online Articles

Loading
Top