Difference between revisions of "EEPROM"
Line 148: | Line 148: | ||
==user guide== | ==user guide== | ||
<syntaxhighlight> | <syntaxhighlight> | ||
− | + | #include"uart.h" | |
+ | #include"delay.h" | ||
+ | #include"eeprom.h" | ||
− | + | int main() | |
− | + | { | |
+ | uint8_t a_writeBuffer_u8[5]={10,20,35,50,60}; | ||
+ | char a_readString_u8[20]; | ||
+ | char v_readChar_u8; | ||
+ | uint8_t a_readBuffer_u8[5]; | ||
+ | uint8_t i; | ||
+ | UART_Init(9600); //Initialize UART at 9600 baud | ||
+ | |||
+ | UART_TxString("\n\rErasing the Eeprom"); | ||
+ | EEPROM_Erase(); | ||
+ | UART_TxString("\n\rWriting below data into eeprom"); | ||
+ | UART_TxString("\n\rchar= A"); | ||
+ | UART_TxString("\n\r5-Bytes= 10,20,35,50,60"); | ||
+ | UART_TxString("\n\rString: hello, world"); | ||
+ | EEPROM_WriteByte(10,'A'); | ||
+ | EEPROM_WriteNBytes(100,a_writeBuffer_u8,5); | ||
+ | EEPROM_WriteString(150,"hello, world"); | ||
− | |||
− | |||
+ | UART_TxString("\n\r\n\rReading Data back from eeprom"); | ||
+ | v_readChar_u8 = EEPROM_ReadByte(10); | ||
+ | EEPROM_ReadNBytes(100,a_readBuffer_u8,5); | ||
+ | EEPROM_ReadString(150,a_readString_u8); | ||
+ | UART_Printf("\n\rchar:%c",v_readChar_u8); | ||
+ | UART_TxString("\n\r5-Bytes: "); | ||
+ | for(i=0;i<5;i++) | ||
+ | UART_Printf("%d ",a_readBuffer_u8[i]); | ||
+ | UART_Printf("\n\rstring:%s",a_readString_u8); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | while(1); | |
− | + | ||
− | + | ||
− | + | ||
− | + | return 0; | |
+ | } | ||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 20:09, 25 December 2014
Contents
EEPROM
EEPROM_WriteByte
Defination | void EEPROM_WriteByte(uint16_t v_eepromAddress_u16, uint8_t v_eepromData_u8) |
Input Arguments | uint16_t: eeprom_address at which eeprom_data is to be written. uint8_t: byte of data to be to be written in eeprom. |
Return Value | none |
Description | This function is used to write the data at specified EEPROM_address.. |
Usage | EEPROM_WriteByte(1234,25); //Writes 25 at the eeprom address 1234. |
EEPROM_WriteNBytes
Defination | void EEPROM_WriteNBytes(uint16_t v_eepromAddress_u16, uint8_t *p_ramAddress_u8, uint16_t v_numOfBytes_u16) |
Input Arguments | uint16_t,: eeprom_address from where the N-bytes are to be written. uint8_t*: Pointer to the N-bytes of data to be written. |
Return Value | none |
Description | This function is used to write N-bytes of data at specified EEPROM_address. |
Usage | uint8_t A_RamBuffer_U8[5]={10,20,30,40,50}; // Buffer containing the data to be written in Eeprom EEPROM_WriteNBytes(100,A_RamBuffer_U8,5); //Copies 5bytes of data from A_RamBuffer_U8 into eeprom location 100. |
EEPROM_WriteString
Defination | void EEPROM_WriteString(uint16_t v_eepromAddress_u16, char *p_stringPointer_u8) |
Input Arguments | uint16_t: eeprom_address where the String is to be written. char*: Pointer to String which has to be written. |
Return Value | none |
Description | This function is used to Write a String at specified EEPROM_address.NOTE: Null char is also written into the eeprom. |
Usage | uint8_t A_StringBuffer_U8[20]="Hello, World"; // String to be written in eeprom EEPROM_WriteString(50,A_StringBuffer_U8); //Copies "Hello, World" along with NULL character into eeprom location 50. |
EEPROM_Erase
Defination | void EEPROM_Erase() |
Input Arguments | none |
Return Value | none |
Description | This function is used to erase the entire Eeprom memory. Complete Eeprom(C_MaxEepromSize_U16) is filled with 0xFF to accomplish the Eeprom Erase. |
Usage | EEPROM_Erase(); //Erases the complete(C_MaxEepromSize_U16 bytes) eeprom. |
EEPROM_ReadByte
Defination | uint8_t EEPROM_ReadByte(uint16_t v_eepromAddress_u16) |
Input Arguments | uint16_t: eeprom_address from where eeprom_data is to be read. |
Return Value | uint8_t: data read from Eeprom. |
Description | This function is used to read a byte of data from specified EEPROM_address. |
Usage | eeprom_data = EEPROM_ReadByte(100); reads the data from eeprom location 100 which is copied to eeprom_data |
EEPROM_ReadNBytes
Defination | void EEPROM_ReadNBytes(uint16_t v_eepromAddress_16, uint8_t *p_ramAddress_u8, uint16_t v_numOfBytes_u16) |
Input Arguments | uint16_t,: eeprom_address from where the N-bytes is to be read. uint8_t*: Pointer into which the N-bytes of data is to be read. |
Return Value | none |
Description | This function is used to Read N-bytes of data from specified EEPROM_address. The data read from the eeprom will be copied into the specified RamAddress . Note:Care should be taken to allocate enough buffer to read the data. |
Usage | uint8_t A_RamBuffer_U8[20]; // Buffer to read the Eeprom data EEPROM_ReadNBytes(1000,A_RamBuffer_U8,20); //Copies 20bytes of eeprom data(address 1000) into A_RamBuffer_U8 |
EEPROM_ReadString
Defination | void EEPROM_ReadString(uint16_t v_eepromAddress_u16, char *p_destStringAddress_u8) |
Input Arguments | uint16_t: eeprom_address from where the String is to be read. char*: Pointer into which the String is to be read. |
Return Value | none |
Description | This function is used to Read a String from specified EEPROM_address.The string read from eeprom will be copied to specified buffer along with NULL character. |
Usage | uint8_t A_StringBuffer_U8[20]; // Buffer to read the Eeprom data EEPROM_ReadString(200,A_StringBuffer_U8); //Copies a string from eeprom(address 200) along with NULL caharacter into A_StringBuffer_U8 |
user guide
#include"uart.h" #include"delay.h" #include"eeprom.h" int main() { uint8_t a_writeBuffer_u8[5]={10,20,35,50,60}; char a_readString_u8[20]; char v_readChar_u8; uint8_t a_readBuffer_u8[5]; uint8_t i; UART_Init(9600); //Initialize UART at 9600 baud UART_TxString("\n\rErasing the Eeprom"); EEPROM_Erase(); UART_TxString("\n\rWriting below data into eeprom"); UART_TxString("\n\rchar= A"); UART_TxString("\n\r5-Bytes= 10,20,35,50,60"); UART_TxString("\n\rString: hello, world"); EEPROM_WriteByte(10,'A'); EEPROM_WriteNBytes(100,a_writeBuffer_u8,5); EEPROM_WriteString(150,"hello, world"); UART_TxString("\n\r\n\rReading Data back from eeprom"); v_readChar_u8 = EEPROM_ReadByte(10); EEPROM_ReadNBytes(100,a_readBuffer_u8,5); EEPROM_ReadString(150,a_readString_u8); UART_Printf("\n\rchar:%c",v_readChar_u8); UART_TxString("\n\r5-Bytes: "); for(i=0;i<5;i++) UART_Printf("%d ",a_readBuffer_u8[i]); UART_Printf("\n\rstring:%s",a_readString_u8); while(1); return 0; }