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

prob with trisc

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Andre Jr. Richard



Joined: 23 Sep 2003
Posts: 6

View user's profile Send private message

prob with trisc
PostPosted: Thu Jul 08, 2004 8:39 am     Reply with quote

I try to access to pin c2 without manage the trisc.

I'm able to access all the other ports pins in that condition with using:
#bit RB0 = PORTB.0 for example.

In my program I can do:

RB0 = 1; or if(RB0){}
and that code work perfectly i.e the trisb is manage by compiler.

Why i'm unable to do the same with the portc pin ? i.e the trisc isn't manage by compiler ?

I don't use: #use fast_io(c) and I'm unable to do this command anyway with portc only, why ?

is it normal ? and why ?

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 08, 2004 9:44 am     Reply with quote

Quote:
RB0 = 1; or if(RB0){}
and that code work perfectly i.e the trisb is manage by compiler.


The compiler does not manage the TRISB when you write directly
to port pins. Here is a sample program:
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#byte PORTB = 6
#bit RB0 = PORTB.0
//====================================
void main()
{
RB0 = 1;

while(1);
}


Here is the .LST file for the above program. Notice that
there is no ASM code that writes to the TRISB register.
So this program will not work. That's because the i/o
ports are configured as input pins upon power-up.
Code:
0000                00273 .................... void main() 
0000                00274 .................... { 
0004 0184       00275 CLRF   04
0005 301F       00276 MOVLW  1F
0006 0583       00277 ANDWF  03,F
0007 3006       00278 MOVLW  06
0008 1683       00279 BSF    03.5
0009 009F       00280 MOVWF  1F
0000                00281 ....................   
0000                00282 .................... RB0 = 1; 
000A 1283       00283 BCF    03.5
000B 1406       00284 BSF    06.0
0000                00285 ....................   
0000                00286 ....................   
0000                00287 .................... while(1); 
000C 280C       00288 GOTO   00C


If you want to write directly to port pins which are declared
with #bit statements, then you need to set the TRIS first.
Example:
set_tris_b(0xFE); // Set pin RB0 to be an output pin

Here is the ASM code for the revised program.
Notice how the TRISB register is now set.
Code:
0000                00273 .................... void main() 
0000                00274 .................... { 
0004 0184       00275 CLRF   04
0005 301F       00276 MOVLW  1F
0006 0583       00277 ANDWF  03,F
0007 3006       00278 MOVLW  06
0008 1683       00279 BSF    03.5
0009 009F       00280 MOVWF  1F
0000                00281 ....................   
0000                00282 .................... set_tris_b(0xFE);   
000A 30FE       00283 MOVLW  FE
000B 0086       00284 MOVWF  06
0000                00285 .................... RB0 = 1; 
000C 1283       00286 BCF    03.5
000D 1406       00287 BSF    06.0
0000                00288 ....................   
0000                00289 ....................   
0000                00290 .................... while(1); 
000E 280E       00291 GOTO   00E


If you want to let the compiler manage the TRIS for you,
then you need to use "standard i/o" mode (which is the
default mode), and you need to use these CCS functions:
output_low();
output_high();
output_bit();
input();
etc.

To discover what the compiler is doing, you need to compile
a small test program and look at the .LST file.
Ttelmah
Guest







Re: prob with trisc
PostPosted: Thu Jul 08, 2004 9:51 am     Reply with quote

Andre Jr. Richard wrote:
I try to access to pin c2 without manage the trisc.

I'm able to access all the other ports pins in that condition with using:
#bit RB0 = PORTB.0 for example.

In my program I can do:

RB0 = 1; or if(RB0){}
and that code work perfectly i.e the trisb is manage by compiler.

Why i'm unable to do the same with the portc pin ? i.e the trisc isn't manage by compiler ?

I don't use: #use fast_io(c) and I'm unable to do this command anyway with portc only, why ?

is it normal ? and why ?

thanks

The 'key' (as has been pointed out by anothr poster), is that when you direct IO like this, _the compiler does not 'manage' the TRIS_. The reason it is working with the other registers, is that you have done other operations allready on the port, that have left the TRIS register set to the required mode. If you want the compiler to handle TRIS, then use the 'output_bit' instruction (or output_high/output_low), for which the compiler will set the TRIS register.

Best Wishes
Andre Jr. Richard



Joined: 23 Sep 2003
Posts: 6

View user's profile Send private message

PostPosted: Fri Jul 09, 2004 8:24 am     Reply with quote

The tris wasn't ok... but physicly the hardware makes that work anyway....

I programed like that since 2 month without problem... Evil or Very Mad

I see in my list file you said right Shocked

I will program far the edge Wink

Thanks for your reply.
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