PIC registers

Thread Starter

Dritech

Joined Sep 21, 2011
863
Hi all,

I want to save binary values in the PIC18F4550 so that when i turn the supply off and then on again they will be re-stored. Is that possible to do by saving the value in registers? or will registers loose or change their content when the supply turns off ?

Thanks.
 

t06afre

Joined May 11, 2009
5,934
Hi all,

I want to save binary values in the PIC18F4550 so that when i turn the supply off and then on again they will be re-stored. Is that possible to do by saving the value in registers? or will registers loose or change their content when the supply turns off ?
The values in the register file. Will for sure be zapped out then power is lost. But your PIC have something named Data EEPROM (256 bytes) And everything stored in the EEPROM will not be affected by loosing power. Refer to your data sheet for how to use the data EEPROM. And if you do not use Assembler you must also refer to your compiler manual on how to use the EEPROM.
 

Thread Starter

Dritech

Joined Sep 21, 2011
863
Thanks for your reply. Is it difficult to access and save in the EEPROM for someone who is a beginner in programming??
 

t06afre

Joined May 11, 2009
5,934
The data sheet do have full Assembler examples on how to use the EEPROM. So I would not worry about that part. From your postings I understand it as you will be using assembler. Besides you can ask for help here
 

Thread Starter

Dritech

Joined Sep 21, 2011
863
Yes im using assembly. I will try using the examples from the datasheet and will let you know if it works. Thanks.
 

t06afre

Joined May 11, 2009
5,934
Oh just one thing. Do not singlestep( in MPLAB) then simulating EEPROM code. Use the "Run to cursor option" to the first point past EEProm writing. And do not use the EEProm as a general storing register
 

spinnaker

Joined Oct 29, 2009
7,835
Yes im using assembly. I will try using the examples from the datasheet and will let you know if it works. Thanks.
Microchip may have a library file (or whatever the assembler equivalent is called) for that in assembler they do in C.

Why aren't you using C. Far easier for a beginner and the 18F is optimized for C.
 

atferrari

Joined Jan 6, 2004
3,926
Keep in mind that the sequence and values shown in the data sheet are a must.

When writing to an EEPROM you could need to disable interruptions. Most probably.

That is why you are suggested not to break in the middle of the process. Timing matters.
 
Last edited:

Thread Starter

Dritech

Joined Sep 21, 2011
863
Hi,
Thanks for your replies. The reason that i want to do it in assembly is that the rest of the program is written in assembly.
 

joeyd999

Joined Jun 6, 2011
4,374
I don't know about that. There is PLENTY to learn just with C.
Starting out with C (or any high level language) for embedded processing is like learning to build a house with prefabricated walls, floors, trusses, etc., especially if you use the vendor-supplied libraries.

For someone who really wants to learn how things work, a great deal can be learned by writing asm code and building your own libraries for various pieces of hardware, without the interference/opaqueness of a compiler and precompiled libraries.
 

MrChips

Joined Oct 2, 2009
20,904
If you really want to learn how a micro works, program in asm. But asm in Microchip PICs would not be my first choice.
 

thatoneguy

Joined Feb 19, 2009
6,359
Starting out with C (or any high level language) for embedded processing is like learning to build a house with prefabricated walls, floors, trusses, etc., especially if you use the vendor-supplied libraries.

For someone who really wants to learn how things work, a great deal can be learned by writing asm code and building your own libraries for various pieces of hardware, without the interference/opaqueness of a compiler and precompiled libraries.
True, but a lot of people just want the house done fast and reliable.

Look at why the Arduino is so popular... Faster than the BASIC stamp, but about as easy to use and program, for $20 less.
 

joeyd999

Joined Jun 6, 2011
4,374
True, but a lot of people just want the house done fast and reliable.
And why do you make the assumption that vendor supplied libraries are reliable? Have you seen the underlying code?

Sorry, I don't mean to hijack yet another thread, but this is an *extremely* important issue for me.
 

nsaspook

Joined Aug 27, 2009
7,184
And why do you make the assumption that vendor supplied libraries are reliable? Have you seen the underlying code?

Sorry, I don't mean to hijack yet another thread, but this is an *extremely* important issue for me.
You can have your own (portable) C libraries if you don't want to use the vendor supplied versions. Microchip provides all the source for their PIC hardware specific C libraries. When you use a IDE like MPLAB you can mix and match languages with ASM, C or anything else to make the complete program. At some level of coding in any language the problem becomes less about the actual function of hardware and more about the structure and movement of data and how that data affects program logic. As the program becomes increasingly data bound the importance of high-level data abstraction becomes a critical factor in the correctness of operation. This abstraction allows us to think of the problem with a general computer model instead of a specific computer set of instructions. If the general computer model is complete , efficient and portable like C most of the knowledge gained from programming one type of CPU architecture can be easily reused on something completely different.
 

spinnaker

Joined Oct 29, 2009
7,835
Starting out with C (or any high level language) for embedded processing is like learning to build a house with prefabricated walls, floors, trusses, etc., especially if you use the vendor-supplied libraries.

For someone who really wants to learn how things work, a great deal can be learned by writing asm code and building your own libraries for various pieces of hardware, without the interference/opaqueness of a compiler and precompiled libraries.
Did you build your PC from raw materials? This is a lot to be learned doing that too but it just is not practical. Frankly I just don't have enough hours in the day to sit down and learn assembler to the point that I know C. And I can get the job done in C far faster than assembler.
 

MrChips

Joined Oct 2, 2009
20,904
You can have your own (portable) C libraries if you don't want to use the vendor supplied versions. Microchip provides all the source for their PIC hardware specific C libraries. When you use a IDE like MPLAB you can mix and match languages with ASM, C or anything else to make the complete program. At some level of coding in any language the problem becomes less about the actual function of hardware and more about the structure and movement of data and how that data affects program logic. As the program becomes increasingly data bound the importance of high-level data abstraction becomes a critical factor in the correctness of operation. This abstraction allows us to think of the problem with a general computer model instead of a specific computer set of instructions. If the general computer model is complete , efficient and portable like C most of the knowledge gained from programming one type of CPU architecture can be easily reused on something completely different.
Did you build your PC from raw materials? This is a lot to be learned doing that too but it just is not practical. Frankly I just don't have enough hours in the day to sit down and learn assembler to the point that I know C. And I can get the job done in C far faster than assembler.
There is a huge difference between getting the job done in a hurry and truly learning and understanding what goes on behind the scene. You have to choose which one you want. Some folks just want to get there fast and don't care for the scenery.
 
Top