Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

help required urgently for reading and writting in PIC16F877A using CCS C compiler

Status
Not open for further replies.

tehmaas hasan

Junior Member level 1
Joined
Mar 21, 2012
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,414
greeting every one

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.

PLZ HELP URGENTLY

THANKS IN ADVANCE
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
try doing like this

when ever you press a key do
Code:
 value = value * 10 + key;
where key holds the value of key pressed.

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
Code:
 value1 = value1 * 10 + key; 

if(value == value1) {
          //then allow access
}
else {
       //do some other thing
}
- - - Updated - - -

read the post. Is it what you want?
 

tehmaas hasan

Junior Member level 1
Joined
Mar 21, 2012
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,414
extremely nice logic my friend.WHEN VALUE WILL BE SAVED IN VALUE(VARIABLE). HOW IT CAN BE WRITTEN TO INTERNAL
EEPROM
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
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
 
Last edited:

bmb_10

Member level 1
Joined
Feb 7, 2012
Messages
38
Helped
15
Reputation
30
Reaction score
15
Trophy points
1,288
Location
Colombia
Activity points
1,506
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

Greetings!
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top