|
|
View previous topic :: View next topic |
Author |
Message |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
Strange...This might be useful information for you all |
Posted: Tue Jan 06, 2004 10:30 pm |
|
|
After wasting two days on a stupid problem, I discovered something today. Most of you may know it already but for those of you who don't (I didn't) it can save a lot of time & hassle. In an application I'm using PCM 3.181, PIC16F870 with a software I2C port (C4 & C5). I had set C0 and C1 to outputs. The problem is everytime an I2C function was called, C0 and C1 were set back to inputs (bits 0 and 1 of TRISC got set). After two frustrating days I found the reason:
When I use this method to set TRISC:
#byte TRISC=0x87
TRISC = 0b11111100;
I get this in the list file:
Code: |
.................... TRISC = 0b11111100;
0067: MOVLW FC
0068: MOVWF 07 |
But when I use set_tris_c(0b11111100); I get this:
Code: |
.................... set_tris_c(0b11111100);
0067: MOVLW FC
0068: MOVWF 07
0069: BCF 03.5
006A: MOVWF 2E |
It seems the compiler uses the address 2E to hold a second copy of the value of TRISC. Then in the I2C routines that value is used to change the configuration of the SDA pin. Forexample:
Code: |
.................... #use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
*
00E4: MOVLW 08
00E5: MOVWF 21
00E6: NOP
00E7: NOP
00E8: BCF 07.3
00E9: BCF 2E.3
00EA: MOVF 2E,W
00EB: BSF 03.5
00EC: MOVWF 07
00ED: NOP
..........................
|
And in the Symbol Map file I have these two lines:
02E @TRIS_C
087 TRISC
Well it seems setting TRISC directly is not always a good idea.
And there other strange thing...This only happens for TRISC. When I changed my #USE I2C to use B4 and B5 instead, the compiler didn't do the same thing for TRISB, but still did it for TRSIC. And the I2C routine looked like this:
Code: |
.................... #use i2c(Master,Fast,sda=PIN_B4,scl=PIN_B3)
*
00E4: MOVLW 08
00E5: MOVWF 21
00E6: NOP
00E7: NOP
00E8: BCF 06.3
00E9: BSF 03.5
00EA: BCF 06.3
00EB: NOP
.........................
|
As you can see TRISB got modified directly, unlike when I used pins C4 and C5 where the address 2E is also used.
Using both standard_io and fast_io yield to the same results.
Does anyone know why the compiler acts like that?? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
burnsy
Joined: 18 Oct 2003 Posts: 35 Location: Brisbane, Australia
|
got me too! |
Posted: Wed Jan 07, 2004 1:11 am |
|
|
Yep that one always comes back to bite you on the backside. It got me in the last 24 hours as well. grrrr _________________ This is the last code change until its ready.... |
|
|
|
|
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
|