LIST P=16f877
#INCLUDE
;
;- 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
上一篇:PIC16F877A+18B10温度测量+LCD1602显示温度
下一篇:菜鸟学PIC单片机(一)
推荐阅读最新更新时间:2024-03-16 15:48