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

set_tris_x( ) & PIC16F84

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



Joined: 09 Feb 2010
Posts: 17

View user's profile Send private message

set_tris_x( ) & PIC16F84
PostPosted: Mon Feb 15, 2010 2:16 pm     Reply with quote

Hello,

I used set_tris_x( ) function to configure PIC16F84 ports, like this :
Code:

set_tris_a(0x00);


and I got an error in Proteus

I checked the LST file..and found out that the asm code generated by the compiler for this function is
Code:

....................    set_tris_a(0x00);
0007:  MOVLW  00
0008:  TRIS   5

is this a bug or my misunderstood of the of PIC C compiler ? coz TRIS doesn't exist. So how can I fix it, I heard that I can modify existing function in PIC-C, How ?

Since I'm a fan of assembly language, I did this small modification.
Code:

 #asm
   bsf    STATUS,5   // bit6 EQU RP0, go to BANK1
   
   bcf      TRISA,0
   bcf      TRISA,1
   bcf      TRISA,2
//or
   movlw   0x00
   movwf   TRISA // all PORTA pins are in output mode

   #endasm

And it works Twisted Evil

Also, I notice that the function output_high/low(PIN_X)
always configure the bit first as an output, and then set the bit high or low.
Code:

....................    output_high(PIN_A2);
0025:  BSF    03.5
0026:  BCF    05.2
0027:  BCF    03.5
0028:  BSF    05.2

I read that this is an instant output configuration or something like that.

My question is, Why always configuring the bit, while, in most cases, you use a pin as an input or an output and not both, in the same program.

Any help from expert people here. It will be much appreciated.

--------------------
sorry for my english
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 15, 2010 2:25 pm     Reply with quote

Quote:

coz TRIS doesn't exist

The TRIS instruction sure does exist for the 16F84. Download the 16F84
data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/30430c.pdf
Go to page 69. There is a gray box for the TRIS instruction.
It says:
Quote:

TRIS -- Load TRIS Register

Description:
The instruction is supported for code
compatibility with the PIC16C5X products.
Since TRIS registers are readable
and writable, the user can directly
address them.



Quote:
always configure the bit first as an output, and than set the bit high or low

That's "standard i/o mode" in CCS. It's the default mode of the compiler.
You can also specify "fast i/o mode" for an i/o Port, and the compiler will
not automatically set the tris in that case. You then have to set the tris
with a set_tris_x() statement. See the CCS manual.
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf

Quote:
My question is, Why...

CCS is designed (at the default level) to make everything as easy as
possible. Unlike Hi-tech C (for example) where you have to specify
much more, just to make a program work. CCS is for "rapid development".
You can whip out a program very quickly. But, if you want to, you can
use other CCS features do more low level programming (which you
seem to want to do).
Hicham



Joined: 09 Feb 2010
Posts: 17

View user's profile Send private message

PostPosted: Tue Feb 16, 2010 2:11 am     Reply with quote

#PCM programmer
thanks for the help
but the instruction TRIS is valid just for PIC16C5X and not for pic16F84. right ?
and i choose pic16F84A to program ????

any idea ?
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Tue Feb 16, 2010 6:25 am     Reply with quote

TRIS work's on every PIC that I know of.

If you program in CCS you do not need to use that function (TRIS) because CCS will do that for you. I was programming the PIC16F84A with CCS and I was using the TRIS function because of some time important function on low speed clock and everything was working like a charm. And when you want to use that kind of port direction programming you have to tell that to the compiler with #use fast_io(A)


I reckon that it is problem in Proteus not in CCS....
Try to use the real hardware Wink
Hicham



Joined: 09 Feb 2010
Posts: 17

View user's profile Send private message

PostPosted: Tue Feb 16, 2010 1:27 pm     Reply with quote

#bungee-

like i said, Proteus show me an error about this function. that's why i asked
but i'll test it in real circuit to be sure about it
thanks for your help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 16, 2010 1:39 pm     Reply with quote

Quote:
but the instruction TRIS is valid just for PIC16C5X and not for pic16F84. right ?

How did you decide that ? I repeat, the 16F84 data sheet says clearly:
Quote:

TRIS -- Load TRIS Register

Description:
The instruction is supported for code
compatibility with the PIC16C5X products.
Since TRIS registers are readable
and writable, the user can directly
address them.


Quote:

and i choose pic16F84A to program ????

You were using the 16F84. Now you suddenly change to 16F84A.
But, the 16F84A data sheet also says TRIS is supported for that PIC.
http://ww1.microchip.com/downloads/en/DeviceDoc/35007b.pdf
On page 80 of the data sheet, it says this:
Quote:

4. Four new instructions have been added:
RETURN, RETFIE, ADDLW, and SUBLW. Two
instructions, TRIS and OPTION, are being
phased out, although they are kept for
compatibility with PIC16C5X.

Therefore the TRIS instruction is supported, and is legal to use, for
both the 16F84 and 16F84A.

This is really a Proteus problem. It's not the fault of CCS in this case.
However, if you have the IDE version of the compiler (PCW, PCHW, etc),
I believe you may be able to use the Device Editor to modify the Device
Data for those PICs so they doesn't use the TRIS instruction.

I don't have the IDE version of the compiler. But here's a screenshot
of the Device Editor. You can probably disable use of the TRIS instruction
by "unchecking" TRIS instruction tickbox in the Features section, or
possibly it may be in another section:
http://www.ccsinfo.com/images/content/device_editor.gif

For more information, see this CCS FAQ article on the TRIS instruction:
http://www.ccsinfo.com/faq.php?page=ccs_tris
Hicham



Joined: 09 Feb 2010
Posts: 17

View user's profile Send private message

PostPosted: Wed Feb 17, 2010 4:20 am     Reply with quote

Quote:
Quote:
but the instruction TRIS is valid just for PIC16C5X and not for pic16F84. right ?

How did you decide that ? I repeat, the 16F84 data sheet says clearly:

Well, I guess I didn't read it well, sorry about the pic I'm using, its 16F84A.
And thanks for the information about the IDE. I'll try this option.
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