Continue to Site

Welcome to EDAboard.com

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

writing in EEPROM in PIC16f887

Status
Not open for further replies.

charu2539211

Junior Member level 3
Joined
Jul 22, 2013
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
200
hi.... i am writing a program using pic16f887 and i am trying to save some data by writing in EEPROM. i have written the EEPROM write program as a macro and assigned values to the address and data in the main program. i need to store data in three memory locations.

(assembly language)

this is my code

#INCLUDE<P16F887.INC>
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _FOSC_HS
__CONFIG _CONFIG2, _WRT_OFF & _BOR40V

CBLOCK 0X20
ADD1 ;; three address
ADD2
ADD3
DAT1 ;; three data
DAT2
DAT3
ENDC

BANKSEL ADD1
MOVLW 06h
MOVWF ADD1
MOVLW 07h
MOVWF ADD2
MOVLW 08h
MOVWF ADD3
MOVLW 05h
MOVWF DAT1
MOVLW 03h
MOVWF DAT2
MOVLW 02h
MOVWF DAT3

#INCLUDE"EEPROM.INC"
WRITE1 ADD1,DAT1

WRITE1 ADD2,DAT2

WRITE1 ADD3,DAT3


END

MACRO:


WRITE1 MACRO PAR1,PAR2

BANKSEL PAR1
MOVF PAR1,W
BANKSEL EEADR ;
MOVWF EEADR
BANKSEL PAR2 ;Data Memory Address to write
MOVF PAR2,W;
BANKSEL EEDAT
MOVWF EEDAT
BANKSEL EECON1 ;
BCF EECON1, EEPGD ;Point to DATA memory
BSF EECON1, WREN ;Enable writes
BCF INTCON, GIE ;Disable INTs.
BTFSC INTCON, GIE ;SEE AN576
GOTO $-2
MOVLW 55h ;
MOVWF EECON2 ;Write 55h
MOVLW 0AAh ;
MOVWF EECON2 ;Write AAh
BSF EECON1, WR ;Set WR bit to begin write
BSF INTCON, GIE ;Enable INTs.
SLEEP ;Wait for interrupt to signal write complete
BCF EECON1, WREN ;Disable writes

ENDM

i checked the EEPROM memory after running this program, it seems that only the first time the macro function has run. can u tell where i have gone wrong??
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top