I WANT TO WRITE AND READ DATA TO EEPROM OF PIC16F877A USING CCS C COMPILER I DONT KNOW HOW TO PERFORM THE REQUIRED TASK. I WANT TO SAVE A PASSWORD FOR ELECTRONIC LOCK MY CODE IS READY WITH KEYPAD AND LCD BUT I AM STUCK IN THIS TASK. I WANT TO SAVE SOME DIGITS LIKE 1234. LIKE NORMAL LOCK WORKS.
If you press 1234, then 1234 will be saved in value variable. then write this value to internal eeprom of mcu, so that you can restore the password after a power reset. Then you compare value with user entered password using the same code
I don't know CCS C. You see, there are libraries for eeprom thing in CCS C Compiler. You use that some eeprom_write() function to write the value of value variable.
Then on power reset you will use eeprom_read() function to read the password into memory.
Yes, there is read_eeprom() and write_eeprom() functions in CCS C.
read eeprom returns 1 byte and write eeprom write 1 byte. If your password is 1234 it is greater than 255. So, it takes 2 bytes. you have to extract the 2 bytes and write it to eeprom at some address like 0x01 and 0x02. When you read eeprom, you have to read the 2 bytes from the address 0x01 and 0x02 and combine it to get 1234.
you do something like this to split the 1234 like values
you have to convert 1234 to hex first.
Code:
int8 var1, var2;
int16 number;
number = 0xAA88;
var1 = number & 0xFF;// stuff lower byte into var1
var2 = number >> 8 & 0xFF;// shift upper byte to lower position and store it into var2
Hello tehmaas hasan, in the installation folder of the CCS C compiler you find another folder named "examples". There you will find and study in, a very simple example on reading and writing of the EEPROM that is called: EX_INTEE.C