View previous topic :: View next topic |
Author |
Message |
Eugeneo
Joined: 30 Aug 2005 Posts: 155 Location: Calgary, AB
|
8 bit read on a 16 bit port |
Posted: Fri Dec 26, 2014 3:42 pm |
|
|
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: 19546
|
|
Posted: Sat Dec 27, 2014 1:38 am |
|
|
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
|
|
Posted: Tue Dec 30, 2014 8:31 pm |
|
|
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: 9245 Location: Greensville,Ontario
|
|
Posted: Tue Dec 30, 2014 8:47 pm |
|
|
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
|
|
Posted: Tue Dec 30, 2014 9:14 pm |
|
|
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: 19546
|
|
Posted: Wed Dec 31, 2014 2:16 am |
|
|
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. |
|
|
|