View previous topic :: View next topic |
Author |
Message |
pebbert9
Joined: 31 Dec 2010 Posts: 39
|
Writing to lower 8 bits of a 16 bit port |
Posted: Sat Feb 12, 2011 1:39 am |
|
|
I am trying to use bits 0-7 of port D as an 8-bit data buss. and the upper bits for address. ( My part is a PIC24H without a PMP port.)
Is there an easy way to write a byte to port D without affecting the upper 8 bits?
output_d(0x00) will set the entire port ( bits 0-15) to zero, not just bits 0-7.
I can set the bits individually, but that isn't too efficient.
Thank you, |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Feb 12, 2011 2:50 am |
|
|
By accessing the SFRs directly:
Code: | #word LATD = 0x2DC
#byte LATDL = 0x2DC
#byte LATDH = 0x2DD
//e.g.
LATDL = 0x34; |
TRISx can defined accordingly, if required |
|
![](templates/subSilver/images/spacer.gif) |
pebbert9
Joined: 31 Dec 2010 Posts: 39
|
|
Posted: Sun Feb 13, 2011 12:59 am |
|
|
Thanks, that worked great.
BTW, I did have to manually set TRISD for it to work ( and LATD is 0x2D6 for my chip ) |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Feb 13, 2011 2:37 am |
|
|
Quote: | BTW, I did have to manually set TRISD for it to work |
It's one of several ways. You can also use set_tris_d() to initialize the port as a whole. |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Sun Feb 13, 2011 8:33 am |
|
|
FvM wrote: | By accessing the SFRs directly:
Code: | #word LATD = 0x2DC
#byte LATDL = 0x2DC
#byte LATDH = 0x2DD
//e.g.
LATDL = 0x34; |
TRISx can defined accordingly, if required |
You can also build a structure/union and overlay that on top of the port.
I also like "getenv" now instead of hard address assignments... _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Sun Feb 13, 2011 7:37 pm |
|
|
Just my two cents:
Code: |
int8 addr;
int8 data;
void write(void)
{
int16 wAddr;
wAddr = addr<<8;
output_d(wAddr | data);
}
|
this still writes the address in the upper 8 bits _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
![](templates/subSilver/images/spacer.gif) |
|