Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] can i save memory?

Status
Not open for further replies.

gatoulisss

Junior Member level 2
Joined
Feb 5, 2015
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,474
hello everyone,
i need your help, i have a project with a pic mcu (pic16f88 & pic16f628a) which uses battery as power supplier, a reed switch is connected on my pic and makes several settings choices that work on the rest off the program.
my question is : is there any way to save this settings so if battery run out or disconnects my mcu will keep the settings i've already done before when i connect new battery?

thank you all very much!
 

hello,
maybe, you can use EEPROM to store a choice ... and read it back at Power On.
post your program if you want to get some support...
 

Both those PICs have non-volatile EEPROM memory. The 16F88 has an ADC you can use to monitor battery voltage and the 16F628A has a comparator (but no ADC), with these you can pre-emptively save setting to EEPROM as the voltage gets close to minimum for operation -or- you can simply save the settings each time they change then read them back after a reset. Beware of continuously saving to EEPROM as it does have a limited number of write cycles.

Brian.
 

here is my code is writen in mikro C , the choice i want to keep is the hx variable
usually this choice is done when first using the device hx starting value is 1 and then the user can choose between 1 and 6
so i want the user choice to be saved somehow so when for example the battery will be replaced the system will remember

Code:
void ephxou(){            //
  delay_ms(50);
while (portb.f0==1) {      // while reed switch is closed
  a=a+1;
  if (a==7){a=0;}           //number of different choices
  for (k=1; k<=a; k++){     //
sound_play(2600,80);       //
delay_ms(200);             //
hx=k;}                           // this is what i want to keep
delay_ms(1000);}
 
Last edited by a moderator:

I haven't got a copy of MikroC and I don't think it works with my OS (Linux) either but I'm sure it must have routines to write and read EEPROM if you look in the libraries.

It will be something like "EEPROM_write(0,hx);" where '0' is the address in EEPROM to store it. Then use "hx = EEPROM_read(0);" to recover the value when needed. Please check the command though, I cannot confirm that is the actual MikroC function but it will be something similar.

Brian.
 

hello,


not clear here , with parenthesis ! :
Code:
if (a==7){a=0;}           //number of different choices
could be:
  if (a>6)a=0;    //  >6 for better understanding
you must use a one-shot action
wait the release of portB after a short delai => anti bounce function

it seems hx can only get value 1 to 6
so store hx value in eeprom as suggested by Betwixt

then just after initialising hardware and etc ...
read back the Eeeprom to get back hx value ..
the first time
eeprom is virgin and can contains 0xFF
or you can put yourself a value inside Eeprom via the programmateur Pickit3 ? Pickit2 ?
before sending code & eeprom into the PIC

Code:
unsigned char a, hx;

void ephxou()
{            //
  delay_ms(50);
while (portb.f0==1)
{      // while reed switch is closed
  a=a+1;
  if (a==7){a=0;}           //number of different choices
  for (k=1; k<=a; k++)
  {     //
   //sound_play(2600,80);       //
    delay_ms(200);             //
    hx=k;
  }                           // this is what i want to keep
//void EEPROM_Write(unsigned short address, unsigned short data);
  EEPROM_Write( 0,hx);
delay_ms(1000);
}


void main()
{
   ... hardware init
   hx=EEPROM-Read(0x00);
   if (hx>6) hx=1;   // if virgin value 0xFF in eeprom put minimum value of hx

Eeeprom library must be checked in library manager
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top