|
|
View previous topic :: View next topic |
Author |
Message |
Andre Jr. Richard
Joined: 23 Sep 2003 Posts: 6
|
prob with trisc |
Posted: Thu Jul 08, 2004 8:39 am |
|
|
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
|
|
Posted: Thu Jul 08, 2004 9:44 am |
|
|
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 |
Posted: Thu Jul 08, 2004 9:51 am |
|
|
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
|
|
Posted: Fri Jul 09, 2004 8:24 am |
|
|
The tris wasn't ok... but physicly the hardware makes that work anyway....
I programed like that since 2 month without problem...
I see in my list file you said right
I will program far the edge
Thanks for your reply. |
|
|
|
|
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
|