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

How to run my init code before ccs init code ?

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



Joined: 24 Apr 2020
Posts: 1
Location: Banned - spammer

View user's profile Send private message

How to run my init code before ccs init code ?
PostPosted: Fri Apr 24, 2020 12:08 am     Reply with quote

Before ccs initializes things like the uart I want my init code to run first. How do I do this? What I need to do is to set outputs as quick as possible.

thx Soman
_________________
He-banned-llo, My na-banned-me is So-banned-man, ni-banned-ce to me-banned-et y-banned-ou
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Apr 24, 2020 12:54 am     Reply with quote

There is a little tiny bit you can't avoid, but several things are involved:
First for all your peripheral setups, use 'NOINIT'. This prevents the boot
initialisation code being generated. You then have to call the initialisation
for each peripheral after the boot.
So (for example)
Code:

#USE RS232(UART1, BAUD=9600, BITS=8, NOINIT, STREAM=PC)

//Then main
void main(void)
{
    //your code to intialise

   setup_uart(9600,PC); //will generate the UART init code
}


Then second thing is not to have any variables initialised. Have your main
do your required initialisation, and then do the port setups for I2C, RS232
etc, and then call the 'real' main function. Have this contain your variables
then these will only be initialised when this function is called, not at boot.

Then the third, add:
Code:

#device NO_DIGITAL_INIT

This prevents the I/O pin initialisation from being done.

Done like this, your port initialisation can be just about four instruction
times after boot.

I have to query the thinking here though. The PIC takes time before it's
code actually starts running. If you have a crystal oscillator you really
need PUT, and in this case many clock cycles will pass before the chip
actually starts. You really need to design the external hardware, so all
pins are held to 'safe' levels, until the PIC starts. So high impedance bias
resistors ensuring switches are turned 'off' and nothing untoward will
happen till you start things....
newguy



Joined: 24 Jun 2004
Posts: 1900

View user's profile Send private message

PostPosted: Fri Apr 24, 2020 4:26 am     Reply with quote

Ttelmah wrote:
I have to query the thinking here though. The PIC takes time before it's
code actually starts running. If you have a crystal oscillator you really
need PUT, and in this case many clock cycles will pass before the chip
actually starts. You really need to design the external hardware, so all
pins are held to 'safe' levels, until the PIC starts. So high impedance bias
resistors ensuring switches are turned 'off' and nothing untoward will
happen till you start things....


This is absolutely correct. Keep in mind that the PIC powers up with all pins as inputs which is the safest possible way to start. Anything that the PIC drives should have appropriate pullup/pulldown/bias resistors to ensure that nothing bad will happen between power being applied and processor actually starting to execute code.
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 24, 2020 5:04 am     Reply with quote

An 'old school' test

1) remove PIC from socket. yes, back then, when the dinosaurs roamed ,we put PICs in sockets.....heck every DIP was in a socket (with bypass cap).

2) apply power to PCB.

3) see if anything 'bad' happens, motors spinning, valves energized, LEDs on...

The point being that NOTHING should happen, if it does, then you need to pullup or pulldown the control inputs to whatever devices the PIC will be controlling.
newguy



Joined: 24 Jun 2004
Posts: 1900

View user's profile Send private message

PostPosted: Fri Apr 24, 2020 9:51 am     Reply with quote

temtronic wrote:
An 'old school' test

1) remove PIC from socket. yes, back then, when the dinosaurs roamed ,we put PICs in sockets.....heck every DIP was in a socket (with bypass cap).

2) apply power to PCB.

3) see if anything 'bad' happens, motors spinning, valves energized, LEDs on...


4) If the project can be hot swapped (system as a whole powered but your project can be inserted into or removed from the system at any time), and your project has some sort of communication channel/lines with the rest of the system, you must ensure that if the PIC isn't powered, then that does not hurt the communication going on in the rest of the system.
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 25, 2020 5:38 am     Reply with quote

I've been thinking about this again.. and it also depends upon PIC and clock speed.
Modern PICs (16/18) can run at 64MHz, so 'power up / init' is less than a 'blink of an eye' compared to 16C84s running at 4MHz.

and yes, I've been bitten by 4.........sigh, more than once too....
newguy



Joined: 24 Jun 2004
Posts: 1900

View user's profile Send private message

PostPosted: Sat Apr 25, 2020 10:28 am     Reply with quote

temtronic wrote:
and yes, I've been bitten by 4.........sigh, more than once too....


Why do you think I added it to the list? Laughing I think most experienced people have had this happen to them.
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