Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Save information into EEPROM

Status
Not open for further replies.

zulkifli

New Member
Hi All,
I got a quick questions here where i want to store data into my eeprom (16f84a).
this data is actually a condition data.
refer to my sample prog below, i when i pressed switch porta,0 , it will run the cond_A. What i would to do is store all the activities in cond_a into my eeprom. so when i pressed porta,1, it will recall all the activities in cond_a. Any idea, how can i implement this.
PRESS1
BTFSC PORTA,1
GOTO PRESS
GOTO COND_B

PRESS
BTFSC PORTA,0
GOTO PRESS1
GOTO COND_A ;yes goto cond_a

COND_A
BSF PORTB,0
CALL DELAY
BCF PORTB,0
BSF PORTB,1
CALL DELAY
BCF PORTB,1
BSF PORTB,2
CALL DELAY
BCF PORTB,2
BSF PORTB,3
CALL DELAY
BCF PORTB,3
GOTO PRESS

COND_B
CALL READ ; read from eeprom
MOVWF PORTB ; display at port b


Thanks All
 
I feel no use of writing to the EEPROM.With both the buttons you doing the same thing (calling COND_A).
Why cant you do it from one button without writing to EEPROM?

When power up when you press the button it will call the COND_A.(note this code doesn't contains any debouncing & button release routine)

Its less accuracy method,it cant detect the button while you inside the COND_A routine.

Code:
PRESS
	BTFSC 	PORTA,0
	GOTO 	PRESS
	GOTO 	COND_A 	;yes goto cond_a

COND_A
	movlw	b'00000001'
	movwf	PORTB
	CALL 	DELAY
	movlw	b'00000010'
	movwf	PORTB
	CALL 	DELAY
	movlw	b'00000100'
	movwf	PORTB
	CALL 	DELAY
	movlw	b'00001000'
	movwf	PORTB
	CALL 	DELAY
	movlw	b'00000000'
	movwf	PORTB
	GOTO 	PRESS
 
Last edited:
Um, wait, so you want to periodically record a register (Cond_a, as you mentioned) to EEPROM and be able to recall it in a stream? Look in the datasheet on how to initialize the EEPROM (It was pretty easy for my chip, even I got it right!) You'll just have to MOVF (address of cond_a),W, then MOVWF into the EEPROM write register. Recalling it should just be the opposite, it's all based on what the datasheet says. Course, you probably already knew that.
 
Um, wait, so you want to periodically record a register (Cond_a, as you mentioned) to EEPROM and be able to recall it in a stream? Look in the datasheet on how to initialize the EEPROM (It was pretty easy for my chip, even I got it right!) You'll just have to MOVF (address of cond_a),W, then MOVWF into the EEPROM write register. Recalling it should just be the opposite, it's all based on what the datasheet says. Course, you probably already knew that.

i can't get it work out from the datasheet given. can u give me an example. thanks
 
I feel no use of writing to the EEPROM.With both the buttons you doing the same thing (calling COND_A).
Why cant you do it from one button without writing to EEPROM?

When power up when you press the button it will call the COND_A.(note this code doesn't contains any debouncing & button release routine)

Its less accuracy method,it cant detect the button while you inside the COND_A routine.

Code:
PRESS
	BTFSC 	PORTA,0
	GOTO 	PRESS
	GOTO 	COND_A 	;yes goto cond_a

COND_A
	movlw	b'00000001'
	movwf	PORTB
	CALL 	DELAY
	movlw	b'00000010'
	movwf	PORTB
	CALL 	DELAY
	movlw	b'00000100'
	movwf	PORTB
	CALL 	DELAY
	movlw	b'00001000'
	movwf	PORTB
	CALL 	DELAY
	movlw	b'00000000'
	movwf	PORTB
	GOTO 	PRESS

Hi Gayan Soyza,
thanks for the respon. The program above is just the beginning. later there will be more conditions, the conditions will be varies depending on the input. SO what i need to do is that everytime i press certain switch, the EEPROM will memories the conditions. Any advice... or example that i can start with.. Thanks
 
hi,
Look at this short program, it works.

It writes 0x77 to EEPROM addr0
then Reads it back into the variable 'dta'
Remember the 16F84A has only 64bytes of EEPROM, so the addresses are 0 thru 63.


Code:
	list p=16f84a
	#include <p16f84a.inc>
	radix dec
; Begin
	R0L EQU 0xC
	R0H EQU 0xD
	R1L EQU 0xE
	R1H EQU 0xF
	R2L EQU 0x10
	R2H EQU 0x11
	R3L EQU 0x12
	R3H EQU 0x13
	R4L EQU 0x14
	R4H EQU 0x15
	R5L EQU 0x16
	R5H EQU 0x17

	ORG 0x0000
	BCF PCLATH,3
	BCF PCLATH,4
	GOTO L0002
	ORG 0x0004
	RETFIE
L0002:
 
; 5: Dim dta As Byte
;       The address of 'dta' is 0x18
	dta EQU 0x18: 
	BCF STATUS,RP0

; 10: main: 
L0001:
; 11: 
; 12: 
; 13: Write 0, 0x77; write 77h to eeprom addr 0
	MOVLW 0x00
	MOVWF EEADR
	MOVLW 0x77
	MOVWF EEDATA
	BSF STATUS,RP0
	BSF EECON1,WREN
	MOVLW 0x55
	MOVWF EECON2
	MOVLW 0xAA
	MOVWF EECON2
	BSF EECON1,WR
L0003:	BTFSC EECON1,WR
	GOTO L0003
	BCF EECON1,WREN
	BCF EECON1,EEIF
; 14: 
	BCF STATUS,RP0
; 15: Read 0, dta; read data from eeprom addr 0
	MOVLW 0x00
	MOVWF EEADR
	BSF STATUS,RP0
	BSF EECON1,RD
	NOP
	BCF STATUS,RP0
	MOVF EEDATA,W
	MOVWF 0x18
; 16: 
; 17: Goto main

; End of listing
	END
 
Tell in detail wise how many input buttons you have?
How many conditions you have?
How the conditions varies?

Without knowing these you cant write to EEPROM.

Do you get what I mean?
Tell in detail wise how many input buttons you have?
How many conditions you have?
How the conditions varies?

Without knowing these you cant write to EEPROM.

Do you get what I mean?

Let says, i got 8 switches as a input and i got 8 conditions. These 8 conditions control 4 outputs to turn on and off. For example, if you press switch 1. it will do condition 1, 2 and 8 in sequence. so i want these condition to be store in EEPROM.
 
Cant you still do like this?

Code:
PRESS
	BTFSS 	PORTA,0
	GOTO 	COND_A 	;yes goto cond_A
	BTFSS 	PORTA,1
	GOTO 	COND_B 	;yes goto cond_B
	BTFSS 	PORTA,2	
	GOTO 	COND_C 	;yes goto cond_C
	BTFSS 	PORTA,3
	GOTO 	COND_D	;yes goto cond_D
	GOTO	PRESS
 
Prom

hello,
want to know a C code which can write data to a Flash PROM or in case an EEPROM so that it holds and does not reset when power is turned off !

please suggest
regards
bhushan
 
Cant you still do like this?

Code:
PRESS
	BTFSS 	PORTA,0
	GOTO 	COND_A 	;yes goto cond_A
	BTFSS 	PORTA,1
	GOTO 	COND_B 	;yes goto cond_B
	BTFSS 	PORTA,2	
	GOTO 	COND_C 	;yes goto cond_C
	BTFSS 	PORTA,3
	GOTO 	COND_D	;yes goto cond_D
	GOTO	PRESS

But still, i need these conditions to be store in EEPROM. How can i implement..
 
Calm down! If only the inputs varying why can't you just keep the conditions in the main program?

Whenever the button press it will goto corresponding condition.The conditions still there in your main program after every power up.
 
Calm down! If only the inputs varying why can't you just keep the conditions in the main program?

Whenever the button press it will goto corresponding condition.The conditions still there in your main program after every power up.

Let say, i assign portb,0 as an input. so whenever i press this button, it will recall all the activities that i have done before. If, before i switched switch 0 and 2. so, by pressing button at portb,0, it will recall all the activities for switch 0 and 2 without switching it.
 
i can't get it work out from the datasheet given. can u give me an example. thanks
I thought your problem was that you could not write/read to the EEPROM.

I would suggest before you get bogged down in switches, that you try the test program I posted for you.

If that works OK, then we can sort out the switch logic..:)
 
Last edited:
hello,
want to know a C code which can write data to a Flash PROM or in case an EEPROM so that it holds and does not reset when power is turned off !

please suggest
regards
bhushan

hi bhushan, Welcome to the forum.:)

It would be best if you started your own new thread, else it gets confusing replying to two OP's..
 
Last edited:
I thought your problem was that you could not write/read to the EEPROM.

I would suggest before you get bogged down in switches, that you try the test program I posted for you.

If that works OK, then we can sort out the switch logic..:)

Hi, i did manage to work on the read and write routine.
But the only thing that happen is that, the routine is write and read a certain state. It did not write the whole conditions as i wanted to. How can i do that.
 
Hi, i did manage to work on the read and write routine.
But the only thing that happen is that, the routine is write and read a certain state. It did not write the whole conditions as i wanted to. How can i do that.


Hi,
I do not follow what you mean.:confused:

What conditions.?
 
Hi,
I do not follow what you mean.:confused:

What conditions.?
Before this, i did manage to count 0-255 and display it to portb using LEDs. everytime i presses button at porta,0, it will count and write the value to EEprom. so, if i turn off power supply and turn back on, first thing is to read the
EEprom. so i can continue counting. and all this working well.

So, the problem i got now is shown on the following flowchart below
**broken link removed**

So from the flowchart above, the conditions include turn off and on portB. i.e turn on led, turn on motor etc..
Let say, i let it run for 2 minutes, i pressed porta,1 porta,3 and porta,4. all the combinations of the conditions will be store in EEPROM.

So later, when i turn off and turn back on again and i press portb,1 so it will recall what ever conditions stored in EEPROM before the power turn off.

Thanks.. really need a help here.
 
hi,
I am still completly sure what parameter you want to save to eeprom.

If its the ON/OFF state of the PORTB output pins, that say drive LED's you could do it this way.
You show 8 states, why dont you allocate the 8 bits in a temporary register to say SwA=bit7,SwB=bit6...SwH=bit0

Then bit7 represents the state of SwA, the bit set at '1' represents ON and '0' represents OFF.
Then bit6 represents the state of SwB, the bit set at '1' represents ON and '0' represents OFF.
So as the Switches are operated ON/OFF the bits in the Temp register are changed and the temporary reg saved in eeprom.

If PORTB was driving LED's say, then when you recall the eeprom value you had saved earlier in the temp reg to PORTB.

Do you follow.?
 
Last edited:
hi,
I am still completly sure what parameter you want to save to eeprom.

If its the ON/OFF state of the PORTB output pins, that say drive LED's you could do it this way.
You show 8 states, why dont you allocate the 8 bits in a temporary register to say SwA=bit7,SwB=bit6...SwH=bit0

Then bit7 represents the state of SwA, the bit set at '1' represents ON and '0' represents OFF.
Then bit6 represents the state of SwB, the bit set at '1' represents ON and '0' represents OFF.
So as the Switches are operated ON/OFF the bits in the Temp register are changed and the temporary reg saved in eeprom.

If PORTB was driving LED's say, then when you recall the eeprom value you had saved earlier in the temp reg to PORTB.

Do you follow.?

I try to follow you, but i'm still bit blur without example. Could you please give an example. or any webpage that i can follow that represent your last responsed. Thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top