PIC registers

Discussion in 'Programmer's Corner' started by Dritech, Jan 31, 2012.

  1. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    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.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  3. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi,

    Is the On-chip Program Memory in the diagram below the EEPROM of the PIC18F ??
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  5. Dritech

    Thread Starter Well-Known Member

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

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  7. Dritech

    Thread Starter Well-Known Member

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

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  9. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    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.
     
  10. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    But he wouldn't learn *nearly* as much!
     
  11. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988

    I don't know about that. There is PLENTY to learn just with C.
     
  12. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    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: Feb 1, 2012
  13. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    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.
     
  14. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    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.
     
    ErnieM likes this.
  15. MrChips

    Moderator

    Oct 2, 2009
    12,415
    3,354
    If you really want to learn how a micro works, program in asm. But asm in Microchip PICs would not be my first choice.
     
  16. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    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.
     
  17. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    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.
     
  18. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,906
    2,159
    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.
     
  19. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    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.
     
  20. MrChips

    Moderator

    Oct 2, 2009
    12,415
    3,354
    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.
     
Loading...