View previous topic :: View next topic |
Author |
Message |
tonkostz
Joined: 07 May 2011 Posts: 40 Location: Bulgaria
|
Store number in rom and than read it. |
Posted: Wed Mar 05, 2014 2:31 am |
|
|
I use
#rom #ROM 0x3FF0={1234} to store 04D2 to rom address 0x3FF0.
Hot to read 0x3FF0 address and if number is the same to perform some operation? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Wed Mar 05, 2014 3:21 am |
|
|
Question one, 'why bother'....
You do realise that if you declare a variable as 'const', it is stored in ROM for you, and can be used as a normal variable.
So:
Code: |
const int16 ROM_val=1234;
if (ROM_val==1234)
//do something....
|
'1234' is actually stored for you in ROM.
However if you 'must' store at a specific location, then use 'read_program_eeprom'
So:
Code: |
#rom #ROM 0x3FF0={1234}
int16 ROM_val;
ROM_val=read_program_eeprom(0x3FF0);
if (ROM_val==1234)
//do something
|
But _caveat_. What can be stored at a location depends on your chip. With a PIC16, each ROM 'word' is only 14 bits wide. So could store 0x3FFF, but not 0x7FFF.
Then some older chips _cannot_ read their own ROM. They just don't have the instructions to do this. If you code as the 'const', the compiler will instead generate a _program_ to return the correct values on such chips. If you use #ROM, it cannot be retrieved in such chips. |
|
|
tonkostz
Joined: 07 May 2011 Posts: 40 Location: Bulgaria
|
|
Posted: Wed Mar 05, 2014 4:18 am |
|
|
Thanks Ttelmah! |
|
|
|