View previous topic :: View next topic |
Author |
Message |
Herbert
Joined: 20 Jul 2008 Posts: 32 Location: Brisbane, Australia
|
TRIS not being set correctly? |
Posted: Wed Dec 31, 2008 9:27 pm |
|
|
Judging by the number of forum entries, this should not be worth putting in another post! But I am confused. The gory details are 18F2620, PCWH V4.079, XP.
What I find is that I expect pin C3 to be an output. With the followng code and looking at the C/ASM output
Code: |
#use fixed_io( c_outputs=PIN_C0, PIN_C3 )
...
.................... Output_low( PIN_C3 );
*
0FFC: MOVLW FB
0FFE: MOVWF F94
1000: BCF F8B.3
|
C3 always is an input, from measurements on the pin. The trisc is consistent with C3 being an input. The Output_low should not be using FB ( The one bit in FB that is set as output is for PWM module ) for setting the trisc. It should be more like F3.
If I comment out the "fixed_io" I get the same result (FB for trisc).
So sadly, what obvious mistake am I making here? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 31, 2008 10:35 pm |
|
|
Quote: | So sadly, what obvious mistake am I making here |
Not posting a test program.
Here's the output of the test program shown below. It's correct.
This was compiled with vs. 4.079. Since you're getting something
different, post (very short) test program that shows the problem.
Code: | .................... void main()
.................... {
00004: CLRF TBLPTRU
00006: BCF RCON.IPEN
00008: CLRF FSR0H
0000A: CLRF FSR0L
0000C: MOVF ADCON1,W
0000E: ANDLW C0
00010: IORLW 0F
00012: MOVWF ADCON1
00014: MOVLW 07
00016: MOVWF CMCON
....................
.................... output_low(PIN_C3);
00018: MOVLW F6 // This is the correct TRIS.
0001A: MOVWF TRISC
0001C: BCF LATC.3
....................
....................
.................... while(1);
0001E: BRA 001E
.................... } |
Code: | #include <18F2620.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use fixed_io(c_outputs=PIN_C0, PIN_C3)
//====================================
void main()
{
output_low(PIN_C3);
while(1);
} |
|
|
|
Herbert
Joined: 20 Jul 2008 Posts: 32 Location: Brisbane, Australia
|
|
Posted: Wed Dec 31, 2008 10:42 pm |
|
|
Offending code is in the middle of something much bigger. I was hoping there might be an obvious reason for this behaviour. Gutting the code to get it down to a bit of test code that shows the problem involves a bit of pain. Looks like I may have to do this. |
|
|
Herbert
Joined: 20 Jul 2008 Posts: 32 Location: Brisbane, Australia
|
|
Posted: Thu Jan 01, 2009 12:16 am |
|
|
Problem solved. Had a second "#use fixed_io..." hidden away in an include file that came after the one I had indicated, so it was in effect at the point I was looking at in the code. Thanks PCM, the test code you showed did make me think in terms of this possibility. |
|
|
|