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 CCS Technical Support

4-Bit Out at 8-Bit Port !?

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



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

4-Bit Out at 8-Bit Port !?
PostPosted: Tue Jan 30, 2007 3:01 am     Reply with quote

Hi Friends !

Looking thru some post and manual I ike to get a confirmation if I am right with this:

I need to set the lower port to specific values without disturbing the upper half of the port.

Is there the only way to define a 4-bit structure and send this to the port??

and of course how should I define this struct ???

Thanks for Your answers.

best regards
Andreas
Ttelmah
Guest







PostPosted: Tue Jan 30, 2007 3:32 am     Reply with quote

Basically, no...
The port, _is_ an eight bit wide unit. The only 'way', is to actually read the port, modify the required bits, and write the 8 bits back.
All other routes, will 'lead' to this in some form. So (for instance), the 'bit' operations, available from the compiler, internally function, by reading the whole port, changing the one bit, and writing back the value (this is what leads to the possibility of the 'read modify write' problem...). A 'structure', has no 'magic'. A four bit field defined in this, still results in a bytewide access.
The questions are, 'what are the other four bits'?. Input or output?. How is TRIS being handled?. By you, or the compiler?.

Best Wishes
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Tue Jan 30, 2007 5:59 am     Reply with quote

Hello Ttelmah !

Thank You for Your quick reply.

All Bits are handled by me, so I think I got the answer now, keeping a copy of all Bits, so I can move a nibble to the copy and send it to the port.

I'am right ?

best regards
Andreas
Ttelmah
Guest







PostPosted: Tue Jan 30, 2007 6:05 am     Reply with quote

Yes. Spot on.
Hold the whole byte, mask it as needed, and add in the extra bits.

Best Wishes
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Thu Mar 29, 2007 11:20 pm     Reply with quote

I might have a similar problem. I want to write a lower nibble of the port D, while D5 & D6 are used as PWM outputs and D4 & D7 are unused. What will happen to PWM outputs, if I do the read-modify-write Question
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