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.

[PIC] how can I access CHAR type dtavariable bitwise in mplab in c language

Status
Not open for further replies.

mathssciencerobotic

Newbie level 1
Joined
Mar 4, 2016
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
10
Sorry for the language mistake>

Code:
#include<htc.h>
unsigned char temp;      //I want to access the each of bit of this 'temp' variable
                                    //HOW CAN I ASSIGN ALL THE BITS OF 'TEMP' SAPERATELY                   
                                        TO SOME BIT TYPE VARIABLE?


in the past during the coading in keil for 8051 it is very simple as,

Code:
unsigned char top;
sbit a1 top^0;
sbit a2 top^1;
sbit a3 top^2;
sbit a4 top^3;
sbit a5 top^4;
sbit a6 top^5;
sbit a7 top^6;
sbit a8 top^7;

is there any way like this for PIC16F877A in mplab ide?
please help me..
Im using MPLAB ide with universal toolsuit.
language of programing: C language
uC: PIC16f877A
 
Last edited by a moderator:

You can use bit shift arithmetic
eg
Code:
if( (temp >> 5) % 2)
   //bit 5 is SET

or use bitwise OR,XOR,AND

Code:
if (temp & (1<<5))
      //bit 5 is set

RA0 = (temp & 0x10) ? 1 : 0;
//set RA0 in the same value with the 5th bit of temp
    //

or use a union (the PIC are LSB mcu, so b0 is first)

Code:
union {
  unsigned char val;
  struct {
         unsigned char b0:1;
         unsigned char b1:1;
         unsigned char b2:1;
         unsigned char b3:1;
         unsigned char b4:1;
         unsigned char b5:1;
         unsigned char b6:1;
         unsigned char b7:1;
  } bits;
} temp;

void main(){
      temp.val = 47;
      if(temp.bits.b5)
            //do something
}


all the above are standard C language usage.

The sbit etc are non standard.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top