Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Individual bit access MikroC

Status
Not open for further replies.
Possibly but a more universal way would be to use:
if(TEMP & 0x08)
using 0x08 as the value represented by the bit you are checking. You can use a variable as well as a constant.
Brian.
 
  • Like
Reactions: M.Rehan

    M.Rehan

    Points: 2
    Helpful Answer Positive Rating
Yes, you can access bit of a PORT or regiset or a 1 byte variable using below format.

Code:
unsigned char myVar = 0;

TRISA.F0 = 1;

myVar.B0 = 1;

ANSELA.B0 = 1;

PORTB.B0 = 0;
 
  • Like
Reactions: M.Rehan

    M.Rehan

    Points: 2
    Helpful Answer Positive Rating
Possibly but a more universal way would be to use:
Code:
if(TEMP & 0x08)

The PIC16F’s instruction set provides (individual) bit mapped access to I/O ports, so the code in post #1 could reach the same result, but I fully agree with you that in order to turn the whole code portable to other cores without this feature, if the sacrifice of some cycles is not any issue, I would prefer your suggestion.
 

If TEMP.F4 and TEMP & (1<<4) means the same, then it will never be equal to 1.
So, if(TEMP.F4 ==1) is incorrect. Have to be if(TEMP.F4)
 

TEMP.F4 or TEMP.B4 is referring to only 4th bit of TEMP variable

while TEMP & (1<<4) is comparing all zero too(left and right side)

but i think results will be same
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top