View previous topic :: View next topic |
Author |
Message |
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
saving a code on pic |
Posted: Wed May 29, 2019 6:03 am |
|
|
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: 19549
|
|
Posted: Wed May 29, 2019 8:38 am |
|
|
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: 9245 Location: Greensville,Ontario
|
|
Posted: Wed May 29, 2019 9:00 am |
|
|
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
|
|
Posted: Wed May 29, 2019 9:44 am |
|
|
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
|
|
Posted: Thu May 30, 2019 7:36 am |
|
|
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
|
|
Posted: Thu May 30, 2019 8:21 am |
|
|
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: 480 Location: Montenegro
|
|
Posted: Sun Jun 02, 2019 1:03 pm |
|
|
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. |
|
|
|