View previous topic :: View next topic |
Author |
Message |
Andreas
Joined: 25 Oct 2004 Posts: 136
|
4-Bit Out at 8-Bit Port !? |
Posted: Tue Jan 30, 2007 3:01 am |
|
|
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
|
|
Posted: Tue Jan 30, 2007 3:32 am |
|
|
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
|
|
Posted: Tue Jan 30, 2007 5:59 am |
|
|
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
|
|
Posted: Tue Jan 30, 2007 6:05 am |
|
|
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
|
|
Posted: Thu Mar 29, 2007 11:20 pm |
|
|
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 |
|
|
|