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.

pic16f877 Flash Memory C Code

Status
Not open for further replies.

Tiwana6330

Member level 1
Joined
Feb 3, 2011
Messages
36
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,536
Hi Everyone!

I have been using pic16f877 for last 2 years but for the first time I need to store some data into its Flash Memory. I use HiTech C compiler. Can anyone please give me a simple example code written in C to read and write Data to Flash Memory? Many thanks for your help
 

If you look in the <pic.h> file you will find:
'FLASH memory read/write/erase macros and function definitions'

Hi-Tech has done it for you, just call the functions.
 
Here you go.
This is one example, you can modify it to your need
Code:
void save_data(int abc, int xyz)
{
    intToByte(abc, &byte1, &byte2);
    intToByte(xyz, &byte3, &byte4);

    EEPROM_WRITE(0x00, byte1);
    EEPROM_WRITE(0x01, byte2);
    EEPROM_WRITE(0x02, byte3);
    EEPROM_WRITE(0x03, byte4);
}
 
Here you go.
This is one example, you can modify it to your need
Code:
void save_data(int abc, int xyz)
{
    intToByte(abc, &byte1, &byte2);
    intToByte(xyz, &byte3, &byte4);

    EEPROM_WRITE(0x00, byte1);
    EEPROM_WRITE(0x01, byte2);
    EEPROM_WRITE(0x02, byte3);
    EEPROM_WRITE(0x03, byte4);
}

Thanks alot. I need to ask two questions

What is the function of this statement and is there a similar command for float varables (float to byte)?

intToByte(abc, &byte1, &byte2);

Secondly, Whats the maximum address I can go upto? 0xFF? Thanks
 

Hi,

First I sugest you that you have 2 threads of the same topic. If you close one thread then it will be more clear to explain. I think you can understand better if it is in one single place instead of 2 place.

Thankyou
 

Thanks alot. I need to ask two questions

What is the function of this statement and is there a similar command for float varables (float to byte)?



Secondly, Whats the maximum address I can go upto? 0xFF? Thanks

Sorry missed pasting the function:

Code:
int intToByte(int integer, unsigned char * byte1, unsigned char * byte2)
{
    *byte1 = (char)(integer >> 8);
    *byte2 = (char)(integer);

    return 0;
}

Code:
int                     intToByte(int, unsigned char *, unsigned char *);
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top