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

saving a code on pic

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



Joined: 05 Oct 2016
Posts: 120

View user's profile Send private message

saving a code on pic
PostPosted: Wed May 29, 2019 6:03 am     Reply with quote

Hello everyone,

This is not a code problem. I just wanted to ask a starting point on my research, since i don't know the correct keywords for searching.

My project example:

The code has a few functions. func1,func2,func3,...,funcN the user chooses a few of them, like 2,3,5. i want code to run the function 2,3,5 everytime pic started. If the user needs to change the functions he will go to a change commands function and give inputs again.

This is the structure basically. I hope i could define it well.

Where does the pic save the code? What keywords should i use to learn about this topic? Can you recommend any source?

Thank you so much!
Ttelmah



Joined: 11 Mar 2010
Posts: 19245

View user's profile Send private message

PostPosted: Wed May 29, 2019 8:38 am     Reply with quote

The PIC has flash memory. This is where your code will be stored.
Choose a PIC that also has EEPROM (about half have this). Then when the
options are selected, your code can store in the EEPROM which options are to
be used. Your booting code reads this and runs the functions this says.
temtronic



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

View user's profile Send private message

PostPosted: Wed May 29, 2019 9:00 am     Reply with quote

You should read the datasheet for whatever PIC you're using ! I know 300-500 pages of information, but it is critical to read a lot of if you want to understand HOW PICs operate. It's the 'details' like what can a pin do (input and output, output only, input only ?), what is the CORRECT setup for the ADC peripheral ? What voltage can it operate at ? That one is very important as most external devices like GPS modules,'sensors', etc. now are 3 volt devices.
The more you read and understand the better programmer you'll become.

Jay
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Wed May 29, 2019 9:44 am     Reply with quote

If possible, I would do something lazy with hardware like with a set of dip switches instead of having to save into eeprom.
doguhanpala



Joined: 05 Oct 2016
Posts: 120

View user's profile Send private message

PostPosted: Thu May 30, 2019 7:36 am     Reply with quote

thank you all

The hardware is fixed on this project. I will use the 18f4550. I tried to read the datasheet but its hard to understand. So i tried to search a more basic resource. Like program memory for dummies, or eeprom for dummies. I will search and read more. Thanks again!

My best wishes,

Doğuhan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 30, 2019 8:21 am     Reply with quote

doguhanpala wrote:
Where does the pic save the code?

The compiler handles the placement of the code for the functions.
It chooses the best location, based on some internal algorithm.
You don't have to manually place the functions in a specific program
memory location. That's a good thing. Let the compiler handle it.

doguhanpala wrote:
What keywords should i use to learn about this topic?

I'm not completely sure what you want, but here are things to research:
1. Look at the .SYM file that the compiler creates when it compiles your program.
2. Possibly, you may want to read about "function pointers" or "pointers to functions".
PrinceNai



Joined: 31 Oct 2016
Posts: 462
Location: Montenegro

View user's profile Send private message

PostPosted: Sun Jun 02, 2019 1:03 pm     Reply with quote

You need just two functions, write_eeprom() and read_eeprom(). You declare a variable like int8 my_functions. Let's say you have 8 functions. When you program your PIC, store somewhere in EEPROM 8 bits that tell you which functions have to be executed (00010110) for functions 2,3 and 5). Then you could just make a code which reads this EEPROM location at the start and stores that byte in my_functions and then have a series of 8 if statements which test one after another every bit from 0 - 7 and execute the function if the corresponding bit is set. When user changes the desired functions, just write my_function back to eeprom. If you want that behavior to be persistent, of course.
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