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
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
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 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
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?
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
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
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.
I thought your problem was that you could not write/read to the EEPROM.i can't get it work out from the datasheet given. can u give me an example. thanks
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
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.
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 theHi,
I do not follow what you mean.
What conditions.?
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.?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?