最近学习到PIC单片机的EEPROM的读写操作,想在EEPROM的地址00H中写入20H这个数,然后再读出来到端口显示,但是操作后无反映,请大家帮忙.
;**************************************************
LIST P=16f877
#INCLUDE <P16f877.INC>
__1EB9h;
;***************************************
ADDR equ 170h
VALUE equ 171h
COUNT1 equ 172h
COUNT2 equ 173h
EEDATA equ 10ch
EECON1 equ 18ch
EECON2 equ 18dh
EEADR equ 10dh
INTCON equ 0bh
PORTB equ 06h
TRISB equ 86h
;**************************************************
ORG 000H
NOP
GOTO MAIN
ORG 0005H
MAIN:
BANKSEL TRISB
MOVLW 0x00
MOVWF TRISB
;**********************写EEPROM************************
WRITE:
BANKSEL EECON1
BTFSS EECON1,WR
GOTO $-1
BANKSEL EEADR
MOVLW 00h
MOVWF ADDR ;EEPROM指定单元(00H)地址送ADDR
MOVLW 20h
MOVWF VALUE ;立即数送VALUE
MOVF ADDR,w
MOVWF EEADR
MOVF VALUE,w
MOVWF EEDATA
BANKSEL EECON1
BCF EECON1,EEPGD
BSF EECON1,WREN
BCF INTCON,GIE
MOVLW 0x55
MOVWF EECON2
MOVLW 0xAA
MOVWF EECON2
BSF EECON1,WR
BSF INTCON,GIE
BCF EECON1,WREN
HH: BTFSS INTCON,EEIF ;判断是否写EEPROM操作完成
GOTO HH
;*****************读EEPROM**********************
READ:
BANKSEL EEADR
MOVF ADDR,w ;把EEPROM的地址送EEADR (00H)
MOVWF EEADR
BANKSEL EECON1
BCF EECON1,EEPGD
BSF EECON1,RD
BANKSEL EEDATA
MOVF EEDATA,W ;取出上面写到EEPROM的数据(20H)
BANKSEL PORTB
YY MOVWF PORTB ;送到PORTB口显示
GOTO YY
;*************************************
END |