详情请进入 湖南阳光电子学校 已关注:人 咨询电话:0731-85579057 微信号:yp941688, yp94168
LISTP=16f877
#INCLUDE
;
;-RAMLOCATIONS------
;
;ReserveRAMlocation0x70forICD
;
Data_EE_Addrequ0X71
Data_EE_Dataequ0X72
;--------VECTORS------------
org0x0
nop
gotoSTART
;-------PROGRAM--------------
org0X20
START
callINIT
;
;----TesttheWRITEEEPROMRoutine----
;
movlw0x0
movwfData_EE_Addr
movlw'0';LoadaASCIIcode"0"toW
movwfData_EE_Data
EE_Write
callWRITE_EEPROM
incfData_EE_Data,F;0x30+N
incfData_EE_Addr,F;PointtonextEEPROMAddress
btfssData_EE_Addr,5;Write32bytes?
gotoEE_Write
;
;----TesttheREADEEPROMRoutine----
;
movlw0x20;GetbackEEPROMdatatoRAMwithstartaddrat0x20
movwfFSR
;
movlw0x0;PointtoEEPROMstartaddressat0x00
movwfData_EE_Addr
EE_Read
callREAD_EEPROM;ReadEEPROMdatawithcurentaddresstoWregistre
movwfINDF;moveW-->RAM
;
incfFSR,F
incfData_EE_Addr,F;PointtonextEEPROMAddress
btfssData_EE_Addr,6;Read32bytes?
gotoEE_Read
;
GOTO$
;
;------INTERNALEEPROMREAD------
;
READ_EEPROM
bankselEEADR
movfData_EE_Addr,W;LoadEEPROMAddressintoPointer
movwfEEADR
;
;bcfINTCON,GIE
bankselEECON1
bcfEECON1,EEPGD
bsfEECON1,RD
;
bankselEEDATA
movfEEDATA,W
;bsfINTCON,GIE
;
bankselPORTA
return
;
;----INTERNALEEPROMWRITE-----
;
WRITE_EEPROM
bankselEEADR
movfData_EE_Addr,W;LoadEEPROMAddress&DataintoRegister
movwfEEADR
movfData_EE_Data,W
movwfEEDATA
;
bankselEECON1
bcfEECON1,EEPGD;SelectedDataEEPROMforWriting
bsfEECON1,WREN;Enablewritefunction
;bcfINTCON,GIE;DISAbleInterrupt
movlw0x55;WriteSequencecontrol
movwfEECON2
movlw0xAA
movwfEECON2
bsfEECON1,WR;StartEEPROMwriteoperation
;
;bsfINTCON,GIE;EnableInterrupt(Ifusedinterrupt)
bcfEECON1,WREN;DisablewriteEEPROM
;
btfscEECON1,WR;Waitingforwritingcompleted(4mS)
goto$-1;Duringwriteperiod,mustholdbothEEADR&EEDATAuntilcomplete
;
bankselPORTA
return
;
;---------INITIAL----------------
INIT
BCFPIR2,EEIF
bankselPIE2
BCFPIE2,EEIE
RETURN
;--------------------------------
END