读写PIC16F877单片机內部EEPROM的实例
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
【读写PIC16F877单片机內部EEPROM的实例】
推荐阅读
- PIC单片机AD转换LED显示程序
- mcs51单片机计数器工作方式1 计数初值计算与定时编程举例
- AVR单片机—_五、ATMEGA16的USART与PC机串行通信—02
- 51单片机测量占空比
- PIC系列单片机的优势
- 单片机中用C语言查表和移位问题
- STC单片机 IAP_EEPROM的使用
- 8031单片机各种算术操作指令简介
- STM8S单片机入门1_开发环境搭建
- 51单片机驱动1602程序