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

Can a variable be mapped to the upper nibble of a byte?

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



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

Can a variable be mapped to the upper nibble of a byte?
PostPosted: Thu Mar 03, 2005 10:26 am     Reply with quote

I would like to define a variable to the upper nibble of Port B for the INT_RB interrupt. How can I define this instead of masking out the rest of the entire port B byte? For ex:

#byte discs = PORTB
#bit discs.0 = PORTB.4
#bit discs.1 = PORTB.5
#bit discs.2 = PORTB.6
#bit discs.3 = PORTB.7

Thanks in advance.

Dan
valemike
Guest







PostPosted: Thu Mar 03, 2005 11:14 am     Reply with quote

What's wrong with simply doing:

#byte port_b=0x06; // verify actual location in device's datasheet
...
unsigned char discs;
discs = port_b >> 4;

There is no masking necessary here. After a boolean, a char is the next size unit can get.
dan king



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

PostPosted: Thu Mar 03, 2005 12:10 pm     Reply with quote

nothing is wrong with that, as a matter of fact that's how I'm currently doing it. I just wanted to know if there was a way to specify the port bits used as in the following, instead of starting at bit 0.

struct {
BYTE data:4; // bits 0 - 3
BYTE regsel:1; // bit 4
BYTE read:1; // bit 5
} LCD_PORT;

#byte PORTB = 6 // port a = 0x05, b = 0x06

#BYTE LCD_PORT = 6
#BIT LCD_E = PORTB.6 // bit 6
#define LCD_RD LCD_PORT.read
#define LCD_RS LCD_PORT.regsel
#define LCD_DATA LCD_PORT.data
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