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.

[SOLVED] help with PIC internal EEPROM

Status
Not open for further replies.

noobeestudent

Member level 1
Member level 1
Joined
Jul 4, 2019
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
290
Hi guys ,

I am currently writing a program that records the total time used based on the user input.
For example, the user enters a value such as 45 minutes and it stored in the EEPROM. Then, on the second entry, if the user enters 25, the microcontroller automatically adds it up and save 70 into the internal EEPROM.

However, I am just a beginner in PIC programming. Can anyone guide me through writing the code. The PIC that I am using is PIC16F887 and the compiler I am using XC8.

All help will be very much appreciated. Thanks in advance
 

Hi,

We are not here to give ready solutions.

You need to do the main part on your own.
Indeed the datasheet gives all informatiibs you need.
But in this case there are many example codes in the internet how to access the EEPROM.
Go through some codes, descriptiins, read documents, see videos.

Then try to write/modify code on your own.

Test it.
If it does not work
* try to debug it
In case it still does not work:
* post your code (with comolete informations like power supply, clock frequency, wiring diagram...)
* tell us how you expect it to work
* tell us exactly what does not work like expected

Then we will help you to rectify the mistake.

Klaus
 

When user enters 25, your program should read stored value from EEPROM, perform addition with entered value and store new value back to EEPROM.

Simple as that, regardless of programming language/compiler.
 

1595775589320.png

I was looking at the datasheet and came across this.
This is the Data EEPROM Read instruction. On the first line, there is a 'BANKSEL EEADR'.

How do I write this using XC8 Compiler.
 

This is what i found for the EEPROM Read Instruction
1595821402944.png


and EEPROM Write Instruction
1595821461571.png


C:
/***************************** EEPROM Functions *******************************/
void EEPROM_Write(uint8_t Address, uint8_t Data)
{
    EEADR = Address;
    EEDAT = Data;
    EECON1bits.EEPGD = 0;
    EECON1bits.WREN = 1;
   
    INTCONbits.GIE == 0;
    EECON2 = 0x55;         // Part Of Writing Mechanism..
    EECON2 = 0xAA;         // Part Of Writing Mechanism..
    EECON1bits.WR = 1;
    INTCONbits.GIE = 1;
   
    SLEEP();
    EECON1bits.WREN = 1;
    STATUSbits.RP0 = 0;
    STATUSbits.RP1 = 0;  
}
uint8_t EEPROM_Read(uint8_t Address)
{
    uint8_t Data;
    EEADR = Address;
    EECON1bits.EEPGD = 0;
    EECON1bits.RD = 1;
    Data = EEDAT;
    return Data;
}
/*************************** End EEPROM Functions *****************************/
This is what i wrote.
Is this correct?
Please let me know. Thanks for your help.
 

Hi,

Did you test your code? What are the results?
If you don't have the hardware, then there are simulators.

The solution for your application depends on a lot of things:
* Range of value to write
* safety level (need redundancy? What happens when data gets currupt?)
* power supply (to be sure the data can be written befor power supply breakdown)
* how often you write data to the EEPROM (wear out)

Klaus
 

i am just asking if the functions i wrote was correct or incorrect before i start testing. i am not used to using assembly language.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top