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

writing only LSB to 16Bit port

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



Joined: 05 Jun 2006
Posts: 41
Location: Belgium

View user's profile Send private message Visit poster's website MSN Messenger

writing only LSB to 16Bit port
PostPosted: Thu May 17, 2012 8:41 am     Reply with quote

hello,
Is it possible to write only the lower 8 bits to a 16 bit port (CPU is DSPIC30f6014a) ?

I want to write data to the lower 8 bits, and leave the state of the higher 8 bits at its actual state.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Fri May 18, 2012 1:49 am     Reply with quote

Should be easy. Since the chip supports a byte wide write. On a lot of '16bit' chips, this is impossible (they only do a 16bit I/O operation to the ports), and on these you have to read the whole word, mask in the new bits you want, and write the word back. On the PIC30 though a byte wide write is supported. So:
Code:


#byte PORT_B_L=getenv("SFR:PORTB")
#byte PORT_B_H=PORT_B_L+1

//Then write to the low byte with:
   PORT_B_L=val_to_output;

If you look at the assembler this generates, you will see it uses the mov.b instruction correctly accessing the single byte.

Best Wishes
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