讀寫PIC18F452內(nèi)部EEPROM的源程序?qū)嵗?/h1>
讀寫PIC18F452內(nèi)部EEPROM的實例源程序
list p=18f452
#i nclude P18F452.INC>
;
;---- 18F452 RAM LOCATIONS ------
Data_EE_Addr EQU 0X000
Data_EE_Data EQU 0X001
EEPROM_Buffer equ 0x02
;--------VECTORS------------
org 0x00
bra START
;-------PROGRAM--------------
org 0x20
START
rcall INIT
;
;---- Test the WRITE EEPROM Routine ----
;
clrf Data_EE_Addr ; set EEPROM start address at 0x00
movlw '0' ; Load a ASCII code "0" to W
movwf Data_EE_Data
EE_Write
rcall IN_DATA_EEW
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 ----
;
clrf FSR0H ; Set RAM point to 0x010
movlw 0x10
movwf FSR0L
;
clrf Data_EE_Addr
EE_Read
rcall READ_EEPROM
movwf POSTINC0 ; move W --> RAM then point + 1
;
incf Data_EE_Addr,F ; Point to next EEPROM Address
btfss Data_EE_Addr,5 ; Read 32 bytes ?
goto EE_Read
;
LSTOP
GOTO LSTOP
;
;------ INTERNAL EEPROM READ ------
;
READ_EEPROM
movff Data_EE_Addr,EEADR
;
; bcf INTCON,GIE
bcf EECON1,EEPGD
bsf EECON1,RD
movf EEDATA,W
; bsf INTCON,GIE
return
;
;----INTERNAL EEPROM WRITE-----
;
IN_DATA_EEW
movff Data_EE_Addr,EEADR
movff Data_EE_Data,EEDATA
;
BCF EECON1,EEPGD
BCF EECON1,CFGS ; There are difference with data sheet
; BCF INTCON,GIE
BSF EECON1,WREN
;
MOVLW 0X55
MOVWF EECON2
MOVLW 0XAA
MOVWF EECON2
BSF EECON1,WR
;
; BSF INTCON,GIE
LOOP1 BTFSS PIR2, EEIF
GOTO LOOP1
;
BCF EECON1,WREN
BCF PIR2,EEIF
RETURN
;---------INITIAL----------------
INIT
BCF PIR2,EEIF
BCF PIE2,EEIE
RETURN
;--------------------------------
END
讀寫PIC18F452內(nèi)部EEPROM的實例源程序
list p=18f452
#i nclude P18F452.INC>
;
;---- 18F452 RAM LOCATIONS ------
Data_EE_Addr EQU 0X000
Data_EE_Data EQU 0X001
EEPROM_Buffer equ 0x02
;--------VECTORS------------
org 0x00
bra START
;-------PROGRAM--------------
org 0x20
START
rcall INIT
;
;---- Test the WRITE EEPROM Routine ----
;
clrf Data_EE_Addr ; set EEPROM start address at 0x00
movlw '0' ; Load a ASCII code "0" to W
movwf Data_EE_Data
EE_Write
rcall IN_DATA_EEW
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 ----
;
clrf FSR0H ; Set RAM point to 0x010
movlw 0x10
movwf FSR0L
;
clrf Data_EE_Addr
EE_Read
rcall READ_EEPROM
movwf POSTINC0 ; move W --> RAM then point + 1
;
incf Data_EE_Addr,F ; Point to next EEPROM Address
btfss Data_EE_Addr,5 ; Read 32 bytes ?
goto EE_Read
;
LSTOP
GOTO LSTOP
;
;------ INTERNAL EEPROM READ ------
;
READ_EEPROM
movff Data_EE_Addr,EEADR
;
; bcf INTCON,GIE
bcf EECON1,EEPGD
bsf EECON1,RD
movf EEDATA,W
; bsf INTCON,GIE
return
;
;----INTERNAL EEPROM WRITE-----
;
IN_DATA_EEW
movff Data_EE_Addr,EEADR
movff Data_EE_Data,EEDATA
;
BCF EECON1,EEPGD
BCF EECON1,CFGS ; There are difference with data sheet
; BCF INTCON,GIE
BSF EECON1,WREN
;
MOVLW 0X55
MOVWF EECON2
MOVLW 0XAA
MOVWF EECON2
BSF EECON1,WR
;
; BSF INTCON,GIE
LOOP1 BTFSS PIR2, EEIF
GOTO LOOP1
;
BCF EECON1,WREN
BCF PIR2,EEIF
RETURN
;---------INITIAL----------------
INIT
BCF PIR2,EEIF
BCF PIE2,EEIE
RETURN
;--------------------------------
END
評論