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.

How to access only 4 bits of microcontroller port in C

Status
Not open for further replies.

quris_terris

Junior Member level 3
Joined
May 29, 2005
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,513
bitwise operator +microcontroller

i m using port 1 of microcontroller n want to acess only four bits at a time without disturbing other four bits. I want to do this in C language.i want method which work on four bits at a time not one by one bit.
 

how to access bits in c language

On output, you fake this by setting the "undisturbed" bits to the values they already have.
 

If you want to access only 4 bits at a time then do masking operation by using BITWISE operators & (Bitwise AND) | (Bitwise OR) ....

for eg var=79
to use only 4 lower bits and the original no with " 0F " .
temp = var & "0F";
similarly for upper 4 bits use " F0 "
 

quris_terris said:
i m using port 1 of microcontroller n want to acess only four bits at a time without disturbing other four bits. I want to do this in C language.i want method which work on four bits at a time not one by one bit.


perhaps you can describe more clearly what tasks you're gonna perform on the port..

if your port is bidirectional (read+write), it is ok to read in 8bits at a time, modify your 4bits and write back 8bits.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top