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 support@ccsinfo.com

Strange...This might be useful information for you all

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



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Strange...This might be useful information for you all
PostPosted: Tue Jan 06, 2004 10:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 06, 2004 11:06 pm     Reply with quote

The problem is due to "peripheral override" of the TRIS bits.
This is unique to Port C, and that's why CCS has added a
special case for it.
Read this PicList article, which pretty well explains it:
http://groups.google.com/groups?&selm=200209110952_MC3-1-F93-4637%40compuserve.com&rnum=1

For more information on RMW operations, and the requirement
for a shadow register (with respect to I/O ports, not just TRISC)
see this page:
http://www.piclist.com/techref/readmodwrite.htm
burnsy



Joined: 18 Oct 2003
Posts: 35
Location: Brisbane, Australia

View user's profile Send private message Send e-mail Visit poster's website

got me too!
PostPosted: Wed Jan 07, 2004 1:11 am     Reply with quote

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....
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