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

8 bit read on a 16 bit port

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



Joined: 30 Aug 2005
Posts: 155
Location: Calgary, AB

View user's profile Send private message

8 bit read on a 16 bit port
PostPosted: Fri Dec 26, 2014 3:42 pm     Reply with quote

Is it possible to port read the lower 8 bits of a 16 bit port without affecting the upper bit ports? I'm using the 8 LSBs of port_d as a bus and would like to use the upper ones as I/O.


Code for a int8 port read (CCS V5.016). It works but the compiler sets the entire port to input.

Code:

....................     i = input_d();
04BAE:  SETM    2D2                 <- Set the entire port to input
04BB0:  MOV.B   2D4,W0L
04BB2:  PUSH    33B4
04BB4:  MOV.B   W0L,[W15-#2]
04BB6:  POP     33B4
.................... 



This code is modified to only set the required tris bits, but it doesn't work. Is there a way of doing this?

Code:

....................     bus_set_to_input;
04BB8:  SETM.B  2D2
....................     i = bus_port;
04BBA:  MOV.B   2D6,W0L
04BBC:  PUSH    33B4
04BBE:  MOV.B   W0L,[W15-#2]
04BC0:  POP     33B4
.................... 
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 1:38 am     Reply with quote

The obvious basic one it to switch to using fast_io.

With this selected, the compiler will not change the TRIS. So you can then just do a read on the port, and the upper bits will stay set as they were.
For a 'bus' type application, this is probably better anyway. Means you will have to set the tris on the other pins (either use the tris command, or output_drive and output_float), rather than it being set automatically.

The alternative is to bypass the CCS access for the low half of the port.

So:
Code:

#byte Low_D = getenv("SFR:PORTD")

    val = Low_D;

Will read the single byte from the low half of port D, without adjusting the tris.
Eugeneo



Joined: 30 Aug 2005
Posts: 155
Location: Calgary, AB

View user's profile Send private message

PostPosted: Tue Dec 30, 2014 8:31 pm     Reply with quote

Thank you. This worked!

Can you use these two directives one after another and expect the fixed directive to trump *only PIN_A2?

Code:

#use standard_io(a)
#use fixed_io(a_outputs=PIN_A2)


I'm thinking this could be useful.

Cheers.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 30, 2014 8:47 pm     Reply with quote

not to sure how it could be useful...
..it's a waste of PIC resources( memory) and speed( does unessessary operations( the first directive).

kinda the same as
...
a=0;
a=1;
...

coding a=0; is a waste as PIC does that THEN does a=1.

hth
jay
Eugeneo



Joined: 30 Aug 2005
Posts: 155
Location: Calgary, AB

View user's profile Send private message

PostPosted: Tue Dec 30, 2014 9:14 pm     Reply with quote

You're right.

How about this then:

Code:

#use fast_io(a)
#use fixed_io(a_outputs=PIN_A2)


So you don't have to mess with registers.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Wed Dec 31, 2014 2:16 am     Reply with quote

The second I/O directive overrides the first. Wastes time again, since the compiler will then be setting the port direction every time the port is accessed.

Just either use fast I/O and tris or do the direct access as I showed.
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