pic18f452读写EEPROM程序
扫描二维码
随时随地手机看文章
pIC18f452读写EEPROM程序
listp=18f452
#include
;
;----18F452RAMLOCATIONS------
Data_EE_AddrEQU0X000
Data_EE_DataEQU0X001
EEPROM_Bufferequ0x02
;--------VECTORS------------
org0x00
braSTART
;-------PROGRAM--------------
org0x20
START
rcallINIT
;
;----TesttheWRITEEEPROMRoutine----
;
clrfData_EE_Addr;setEEPROMstartaddressat0x00
MOVlw’0’;LoadaASCIIcode"0"toW
MOVwfData_EE_Data
EE_Write
rcallIN_DATA_EEW
incfData_EE_Data,F;0x30+N
incfData_EE_Addr,F;PointtonextEEPROMAddress
btfssData_EE_Addr,5;Write32bytes?
gotoEE_Write
;
;----TesttheREADEEPROMRoutine----
;
clrfFSR0H;SetRAMpointto0x010
MOVlw0x10
MOVwfFSR0L
;
clrfData_EE_Addr
EE_Read
rcallREAD_EEPROM
MOVwfPOSTINC0;moveW-->RAMthenpoint+1
;
incfData_EE_Addr,F;PointtonextEEPROMAddress
btfssData_EE_Addr,5;Read32bytes?
gotoEE_Read
;
LSTOP
GOTOLSTOP
;
;------INTERNALEEPROMREAD------
;
READ_EEPROM
MOVffData_EE_Addr,EEADR
;
;bcfINTCON,GIE
bcfEECON1,EEPGD
bsfEECON1,RD
MOVfEEDATA,W
;bsfINTCON,GIE
return
;
;----INTERNALEEPROMWRITE-----
;
IN_DATA_EEW
MOVffData_EE_Addr,EEADR
MOVffData_EE_Data,EEDATA
;
BCFEECON1,EEPGD
BCFEECON1,CFGS;Therearedifferencewithdatasheet
;BCFINTCON,GIE
BSFEECON1,WREN
;
MOVLW0X55
MOVWFEECON2
MOVLW0XAA
MOVWFEECON2
BSFEECON1,WR
;
;BSFINTCON,GIE
LOOP1BTFSSPIR2,EEIF
GOTOLOOP1
;
BCFEECON1,WREN
BCFPIR2,EEIF
RETURN
;---------INITIAL----------------
INIT
BCFPIR2,EEIF
BCFPIE2,EEIE
RETURN
;--------------------------------
END