Pic 12F675 Eeprom read and write

Thread Starter

edsbrazil

Joined Feb 11, 2017
1
Hello friends, I am looking for helpo in a simple project, hope this forum can help solve my problems.. I am using PIC 12F675 because it is easy to find and low cost model , and programming with C code with PCH compiler... I just need to build a programm that blink a led when push a button.. it is easy so far.. but now we have to upgrade the code and use the memory eeprom from pic12f675. Now it is the problem.. The function is , press button and led blink, but have to record how many times you have pressed the button. Still a second button to read the memory and output results in the led.
Example: you pressed 3 times and led blinked 3 times. Than when power is off, and on again, when you press button 2, led blink 3 times. I may use the eeprom read and write function but this drive me crazy... Basically I am using (summarized):

Definition:
#define eeprom_write(addr, value)
#define eeprom_read(value)
int c1;
Main code:
c1== eeprom_read(0) // initialize the variable C1 with the value in the memory address 0

Some functions to blink led and count number os pressed button, in each press I do the following:
eeprom_write(0, c1); // write in the adress 0 the variable C1 value - this is because in the beggining of code I read C1

So when power is off, than on again, the C1 starts with a value (stocked in the memory), and can blink led accordinglly,

Please help me, let me know only about the memory how to read or write, maybe a simple example how can I do this please.. the other points about led and button I don´t need help.... just this *** memory.

Thanks, and sorry my bad English I am from Brazil.
Regards.
 

JohnInTX

Joined Jun 26, 2012
4,345
Welcome to AAC!

I am puzzled. You indicate you are using the PCH compiler but a quick search shows that PCH is for 18F devices. PCB or PCM compilers are for 12F.
http://www.ccsinfo.com/product_info.php?products_id=PCH_full

Anyway, the compilers provide library routines or macros to access the EEPROM. The 12F compiler manual shows
int_8 read_eeprom(address) for reading
and
void write_eeprom(address,value_to_write)
You should be able to incorporate these into your code pretty easily. I don't think you need those #defines for read/write. There are examples in the compiler manual.

With that, it's hard to know exactly what you need so to start, draw a simple flow chart showing how your code should run. Then code each part and test it. Post your code with questions/problems.

Here is an easy oneto fix:
c1= eeprom_read(0) // instead of..
c1== eeprom_read(0) // this does not assign a value to c1

Good luck!
 
Last edited:
Top