CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Setting known state in an 8-bit register.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
stevekos



Joined: 28 Dec 2006
Posts: 2

View user's profile Send private message

Setting known state in an 8-bit register.
PostPosted: Sat Apr 24, 2010 9:35 am     Reply with quote

Good afternoon.

This is a silly question, but I can't seem to figure out how to
set a bit in a register LOW in C. I know how to do it in assembly,
but for some reason I can't do it in C.

Let me give you an example:

I have a 8 position DIP switch on PORTB. I want to ignore RB6 and RB7
but get the values of the other 6 positions. So I am reading in portb into
a shadow register and I want to set RB6 and RB7 LOW.

I am drawing a blank, and I searched for this but something tells me it is
so simple that I am the only person "that doesn't get it" ... Smile

Thanks in advance.

Steve
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Apr 24, 2010 10:45 am     Reply with quote

Code:

#define MASK 0x3F       // =0b00111111 Pre-processor directive     
unsigned int DIP_Sw;    // Variable to store the the DIP switch value   

main()
  {
    DIP_Sw = PORTB & MASK;  // Read the whole PORTB, then AND with MASK and place the result in the variable DIP_Sw
  }                                         


Humberto
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group