LIST P=16f877 #INCLUDE <P16f877.INC> ; ;- RAM LOCATIONS------ ; ; Reserve RAM location 0x70 for ICD ; Data_EE_Addr equ 0X71 Data_EE_Data equ 0X72
;--------VECTORS------------
org 0x0 nop goto START
;-------PROGRAM-------------- org 0X20 START call INIT ; ;---- Test the WRITE EEPROM Routine ---- ; MOVlw 0x0 MOVwf Data_EE_Addr MOVlw '0' ; Load a ASCII code "0" to W MOVwf Data_EE_Data EE_Write call WRITE_EEPROM incf Data_EE_Data,F ; 0x30+ N incf Data_EE_Addr,F ; Point to next EEPROM Address btfss Data_EE_Addr,5 ; Write 32 bytes ? goto EE_Write ; ;---- Test the READ EEPROM Routine ---- ; MOVlw 0x20 ; Get back EEPROM data to RAM with start addr at 0x20 MOVwf FSR ; MOVlw 0x0 ; Point to EEPROM start address at 0x00 MOVwf Data_EE_Addr EE_Read call READ_EEPROM ; Read EEPROM data with curent address to W registre MOVwf INDF ; move W --> RAM ; incf FSR,F incf Data_EE_Addr,F ; Point to next EEPROM Address btfss Data_EE_Addr,6 ; Read 32 bytes ? goto EE_Read ; GOTO $ ; ;------ INTERNAL EEPROM READ ------ ; READ_EEPROM banksel EEADR MOVf Data_EE_Addr,W ; Load EEPROM Address into Pointer MOVwf EEADR ; ; bcf INTCON,GIE banksel EECON1 bcf EECON1,EEPGD bsf EECON1,RD ; banksel EEDATA MOVf EEDATA,W ; bsf INTCON,GIE ; banksel PORTA return ; ;----INTERNAL EEPROM WRITE----- ; WRITE_EEPROM banksel EEADR MOVf Data_EE_Addr,W ; Load EEPROM Address & Data into Register MOVwf EEADR MOVf Data_EE_Data,W MOVwf EEDATA ; banksel EECON1 bcf EECON1,EEPGD ; Selected Data EEPROM for Writing bsf EECON1,WREN ; Enable write function
; bcf INTCON,GIE ; Disable Interrupt
MOVlw 0x55 ; Write Sequence control MOVwf EECON2 MOVlw 0xAA MOVwf EECON2 bsf EECON1,WR ; Start EEPROM write operation ; ; bsf INTCON,GIE ; Enable Interrupt (If used interrupt ) bcf EECON1,WREN ; Disable write EEPROM ; btfsc EECON1,WR ; Waiting for writing completed (4mS) goto $-1 ; During write period, must hold both EEADR & EEDATA until complete ; banksel PORTA return ; ;---------INITIAL---------------- INIT BCF PIR2,EEIF banksel PIE2 BCF PIE2,EEIE RETURN ;-------------------------------- END |
|