• 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.

Pic16f690 eepprom

Status
Not open for further replies.

prean

New Member
hey guys.i set up a counterand im trying to write these values to the eeprom of the pic16f690 and then read the value. the read which is outputted to port C,where leds should display them. i taken the eeprom code from the data sheet however it does not work. i have pasted my code below. please could somebody help me. thank you

#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)

cblock 0x70
DATA_EE_ADDR
DATA_EE_DATA
dly0
dly1
endc

org 0
nop

; intialise output ports
banksel ANSEL
movlw 0x00
movwf ANSEL
banksel ANSELH
movlw 0x00
movwf ANSELH
banksel TRISC
movlw 0xF0
movwf TRISC
movlw 0xF0
movwf DATA_EE_DATA
movlw 0x00
movwf DATA_EE_ADDR

WRITE
banksel EEADR
movf DATA_EE_ADDR
movwf EEADR
movf DATA_EE_DATA
movf EEDAT
banksel EECON1
bcf EECON1,EEPGD
bsf EECON1,WREN

bcf INTCON,GIE
btfsc INTCON,GIE
goto $-2
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1,WR
bsf INTCON,GIE

;SLEEP
;bcf EECON1,WREN
banksel PIR2
movlw 0x01
movwf PIR2
;incf DATA_EE_DATA
READ
banksel EEADR
movf DATA_EE_ADDR,W
movf EEADR

banksel EECON1
bcf EECON1,EEPGD
bsf EECON1,RD
banksel EEDAT
movf EEDAT,W
banksel PORTC
movwf PORTC

incf DATA_EE_DATA
;delay code
;movlw H'F0'
;movwf dly1
;movlw H'0F'
;movwf dly0

;OndelayLoop
;decfsz dly0,f -Waste time.
;goto OndelayLoop -The Inner loop takes 3instructions per loop * 256 loopss = 768 instructions
;decfsz dly1,f -The outer loop takes and additional 3 instructions per lap * 256 loops
;goto OndelayLoop


goto WRITE
end
 

SPDCHK

Member
Try the following code ...

Code:
#include <p16F690.inc>
	__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)

	cblock 0x70
	DATA_EE_ADDR
	DATA_EE_DATA
	dly0
	dly1
	EE_ADR
	W_DATA
	R_DATA
	endc

	org 0
	nop

; intialise output ports
	banksel	ANSEL
	movlw	0x00
	movwf	ANSEL
	banksel	ANSELH
	movlw	0x00
	movwf	ANSELH
	banksel	TRISC
	movlw	0xF0
	movwf	TRISC
	movlw	0xF0
	movwf	DATA_EE_DATA
	movlw	0x00
	movwf	DATA_EE_ADDR

; To WRITE into EEPROM
	banksel EE_ADR
	movlw	0x00		; EE_ADDR 
	movwf	EE_ADR		; move 0x00 into EE_ADR
	movlw	0x12		; Writes Hous data into EEPROM
	movwf	W_DATA		; Data to be written
	call	EE_WR		; Write routine for EE_Addr


; To READ from EEPROM
	movlw	0x00		; EE_ADDR 
	movwf	EE_ADR		; move 0x00 into EE_ADR
	call	EE_RD		; Read EEPROM Addr 0
	movwf	R_DATA		; Write into Hyst High register		


; -------------------------------------------------------------------------------------------------
;EE_WR			EEPROM DATA WRITE SEQUENCE				
; -------------------------------------------------------------------------------------------------
EE_WR		
		banksel	EECON1 			; Select Bank of EECON1
		btfsc	EECON1,WR		; Wait for write
		goto	$-1			; to complete
		banksel	EE_ADR			;
		movf	EE_ADR,W 		;
		banksel	EEADR			; (0x10C) Select Bank of EEADR
		movwf	EEADR			; Data Memory Address to write
		banksel	W_DATA			;
		movf	W_DATA,W		; Register containing data to be stored
		banksel	EEDATA			; (0x10D)
		movwf	EEDATA			; Data Memory Value to write
		bsf	STATUS,RP0		;
		bcf	EECON1,EEPGD		; Point to DATA  memory
		bsf	EECON1,WREN		; Enable writes
		bcf	INTCON,GIE		; Disable INTs.
		movlw	H'55'			;
		movwf	EECON2			; (0x18C) Write 55h
		movlw	H'AA'			; 
		movwf	EECON2			; (0x18C) Write AAh
		bsf	EECON1,WR		; Set WR bit to begin write
		bsf	INTCON,GIE		; Enable INTs.
		bcf	EECON1,WREN		; Disable writes
		banksel	PIR2			;
		btfss	PIR2,EEIF		; Wait for interrupt flag to be set
		goto	$-1			; Current line -1
		bcf	PIR2,EEIF		; Clear the EEWRITE interrupt flag
		return				; return to caller

; -------------------------------------------------------------------------------------------------
;	EE_RD			EEPROM DATA READ SEQUENCE				;
; -------------------------------------------------------------------------------------------------
EE_RD						;
		movf	EE_ADR,W		;
		banksel	EEADR			;
		movwf	EEADR			; Data Memory Address to read
		banksel	EECON1			;
		bcf	EECON1,EEPGD		; Point to Data memory
		bsf	EECON1,RD		; EE Read
		banksel	EEDATA			;
		movf	EEDATA,W 		; W = EEDATA
		banksel	R_DATA			;
		movwf	R_DATA			; Move W into EE_BYTE
		incf	EE_ADR,f		; increment EE_Addr with 1
		return				; Value now in W, to be used

; -------------------------------------------------------------------------------------------------
; WRITE	routine to write data			;
; into EEPROM memory Hours			;
; -------------------------------------------------------------------------------------------------
WriteEE:					;	
		movwf	W_DATA			; Writes Hous data into EEPROM
		call	EE_WR			; Write routine for EE_Addr
		incf	EE_ADR,f		; increment EE_Addr with 1
		return				; return to caller

	end
This does work.
 

Space Varmint

New Member
hey thanx alot for your help. but it seems the counter does not output to the 4 leds in PORTC
Did you set up port C? I know you got to do something with ANSEL then set ports to input or output:

050 1683 BSF 0x3, 0x5 ; Set program counter to
051 1303 BCF 0x3, 0x6 ; Bank1 memory
052 1007 BCF 0x7, 0 ; Set Port C bit 0 to output
053 1087 BCF 0x7, 0x1 ; " " " 1 " "
054 1107 BCF 0x7, 0x2 ; " " " 2 " "
055 1187 BCF 0x7, 0x3 ; " " " 3 " "
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top