View previous topic :: View next topic |
Author |
Message |
kazama
Joined: 01 Sep 2009 Posts: 10 Location: Malaysia
|
EEPROM programming |
Posted: Sat Jan 02, 2010 10:55 pm |
|
|
Hello, I have a problem regarding EEPROM programming. I use CCS help section to search the write_eeprom() syntax. I want to know, do I need to set the bits for eeprom such as EEADR or any bits that are required to make eeprom writing work ? Or do I just use the write_eeprom(address,value) ? _________________ CCS Version: 4.038
Current project: Obstacle detection robot |
|
|
Ttelmah Guest
|
|
Posted: Sun Jan 03, 2010 4:09 am |
|
|
Just use write_eeprom.
The function does all the 'donkey work' for you.
This is the basic 'point' about CCS. The supplied functions (RS232, eeprom etc.), 'encapsulate' all the basic operations, so you don't have to worry about how your particular PIC does it. You can take a program written on a PIC16xxx, and provided you only use the standard functions, just change the header (processor include, fuses etc.), and reompile it to run on a PIC18, and it works.
Best Wishes |
|
|
webgiorgio
Joined: 02 Oct 2009 Posts: 123 Location: Denmark
|
|
Posted: Sun Jan 03, 2010 7:14 am |
|
|
Code: | write_eeprom(address,value); |
Which address have I to use?
I have not understand looking to the datasheet.
I'm using a 16f876a and "value" is an int16.
tnx |
|
|
Ttelmah Guest
|
|
Posted: Sun Jan 03, 2010 8:52 am |
|
|
Address, is up to _you_ (within the limitations of the chip).
If your chip has 256 bytes of EEPROM, address, is the number of the location in this you want to use. If you use address=0, the data will be written to the first byte in the EEPROM. Use address=255, and the data will be written to the last byte.
On chips with 1024 bytes of EEPROM, address can be 0 to 1023.
Think of the EEPROM, like a set of numbered pigeon holes. The address, is the number of the pigeon hole to use.
Best Wishes |
|
|
webgiorgio
Joined: 02 Oct 2009 Posts: 123 Location: Denmark
|
|
Posted: Sun Jan 03, 2010 9:42 am |
|
|
looks very simple!
Is a byte in the eeprom 8 bit right? so doing write_eeprom(0,value); I will write byte 0 and byte 1, right? (value is int16 type) |
|
|
kazama
Joined: 01 Sep 2009 Posts: 10 Location: Malaysia
|
|
Posted: Sun Jan 03, 2010 10:19 am |
|
|
So if I use 16f877a with eeprom data memory 256 bytes.. the range of address is 0 - 255. For the syntax write_eeprom(address,value); the address can be use in hex form or not? eg: write_eeprom(0x00,value);. For the value if I declare the adc as var1 = read_adc(), so the value = var1.. eg: write_eeprom(0x00,var1);. Am I right?
thanks _________________ CCS Version: 4.038
Current project: Obstacle detection robot |
|
|
Ttelmah Guest
|
|
Posted: Sun Jan 03, 2010 11:21 am |
|
|
I think some reading on basic C, and numeric formats is needed....
Numbers inside the chip, are always _binary_ (nothing else). C handles automatically converting decimal, octal, or hex to this for you.
A 'byte' is always 8 bits.
Bit beans 'binary digit'. One digit of a binary value. A 'nibble' is four bits, and a byte is 8 bits.
Best Wishes |
|
|
|