View previous topic :: View next topic |
Author |
Message |
shson
Joined: 12 Feb 2016 Posts: 11
|
Send data to PIC over RS232 and store in ROM |
Posted: Mon Feb 15, 2016 11:13 pm |
|
|
Hi
I have a small hobby project that involves PIC reading ADC value through multiple multiplexers then sending the reading to PC via RS-232. The program so far works.
But I also need to send data (an integer) over RS-232 from PC to PIC, and whatever this value I sent must replace the existing integer variable's value and retain the sent integer even after the PIC turned off.
For instance:
Code: |
unsigned int8 WaterLevel_Tank1;
unsigned int8 WaterLevel_Tank2;
unsigned int8 WaterLevel_Tank3;
void main() {
// Initialise default value;
WaterLevel_Tank1 = 7;
WaterLevel_Tank2 = 2;
WaterLevel_Tank3 = 20;
while(1) {
// Codes for reading ADC and sending ADC value to PC
// Incoming serial data says 'replace WaterLevel_Tank1 value to 1'
WaterLevel_Tank1 = 1;
// Now need to make this change permanent, maybe write to ROM? How?
}
}
|
The only way I can think of is add an EEPROM to store this new value of 1 for WaterLevel_Tank1, and let PIC poll for changes every now and then.
But is there a way without adding EEPROM?
I'm using PIC16F1527 and compiler version v5.045.
Thank you. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Feb 15, 2016 11:36 pm |
|
|
Well, according to the data sheet for that chip, it has
High-Endurance Flash Data Memory (HEF)
- 128B of nonvolatile data storage
- 100K erase/write cycles
which would probably support what you want to do. See the chip data sheet at http://ww1.microchip.com/downloads/en/DeviceDoc/40001458D.pdf
See pg 17 "Memory Organization" which provides some additional information about HEF memory in that location. _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9215 Location: Greensville,Ontario
|
|
Posted: Tue Feb 16, 2016 6:46 am |
|
|
Two other options
1) Use an RTC like the DC1307 and store the data in it's RAM buffer. Should be good for 5-8 years. Having a hardware RTC could be 'nice'.
2) Add a 'super cap' to the PIC's power supply NOT the board supply. You need to isolate the PIC from everything else and have a 'main power off' indicator to put PIC in 'very low power mode'.
Which is best is up to you as you kow how long PIC will be 'off' as wellas othr 'system parameters'.
Jay |
|
|
|