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

Port_C and tris problem with 18f452

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







Port_C and tris problem with 18f452
PostPosted: Wed Dec 13, 2006 9:03 am     Reply with quote

I have been using PCWH 3.221. I created my project using wizart. I defined the PIN_C7, PIN_C6, PIN_C5 as a input. The other pins as a output. If a use the following statements , The green and red led don't light.

#define Green_Led PIN_C3
#define Red_Led PIN_C2

#use fast_io (C)
output_high(Red_Led);
output_High(Green_Led);

if I deleted the statement "#use fast_io (C)" then led is giving light. But this time the other pin c7 and c6 create the problem.

#include <18F452.h>
#device adc=10
#FUSES NOWDT, WDT128, HS, NOPROTECT, NOOSCSEN, NOBROWNOUT, BORV20, NOPUT, NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB

#use delay(clock=20000000)
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Wed Dec 13, 2006 10:22 am     Reply with quote

Don't trust the wizard to properly set things up. If it did function correctly, there should be this in the wizard-generated code:

Code:
set_tris_c(0xe0);


If it isn't, then the wizard didn't do what it was supposed to do. Just add this line and you should be fine.
Guest2
Guest







PostPosted: Wed Dec 13, 2006 10:23 am     Reply with quote

Ok I find the problem But what is the reason the following. I didn't understand. (Effect of #use fast_io (C))


#use fast_io (C)
output_high(Red_Led);
output_High(Green_Led);

if I deleted the statement "#use fast_io (C)" then led is giving light.
Ttelmah
Guest







PostPosted: Wed Dec 13, 2006 10:30 am     Reply with quote

With 'fast_io' selected, _you_ must set the TRIS variable yourself, and get it right. Otherwise, the compiler will _automatically_ set the TRIS, so a pin is an output, if you perform an output instruction, and so it is an input, if you perform an input instruction. Fast_io is _faster_, and also means that you can (for example), elect to 'setup' a pin,and then change the TRIS to output the data when required. Hence to work with fast_io selected, you need the tris line suggested by newguy, or the pins will remain as inputs (the default on wake up).

Best Wishes
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Wed Dec 13, 2006 10:37 am     Reply with quote

The compiler has been written in such a way as to take care of a lot of "behind the scenes" things automatically for you. One of those things are the port direction registers.

With some exceptions, almost all PIC port pins can be configured as input (1) or output (0). If, in your C code, you set a particular pin high or low, then obviously you want that pin to be an output. The compiler will then add extra instructions, hidden from you, that make the appropriate pin an output first, then actually set the pin high or low. Same thing goes for reading a pin's state: extra instructions are added to make the pin an input before it is read.

This takes place by default, unless you tell the compiler "no, I'll take care of the port direction myself, thank you very much."

To let the compiler take care of things: no extra directives are needed, this is the default state. Can also be invoked by

Code:
#use standard_io(port name here)


To tell the compiler that you will take care of the port direction:

Code:
#use fast_io(port name here)


The reason that why you originally tried didn't work is because each port defaults to an input on powerup/reset. You used the fast_io directive too, so the compiler did not set the necessary pins to outputs, and thus, you saw no flashing LED.

This stuff is in the manual.

Edit: RJ beat me to it! Very Happy
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