PIC單片機內(nèi)部EEPROM讀寫程序
W_TEMP EQU 20H ; 實際上20H、A0H、120H和1A0H
STATUS_TEMP EQU 21H ;在體0中建立保護單元
PCLATH_TEMP EQU 22H ;在體0中建立保護單元
ORG 000H
GOTO A1
ORG 004H;定時中斷入口地址
GOTO ZD01;
ORG 0CH
Q1 ADDWF PCL,1
RETLW 00C0H ;0
RETLW 00F9H ;1
RETLW 00A4H ;2
RETLW 00B0H ;3
RETLW 0099H ;4
RETLW 0092H ;5
RETLW 0082H ;6
RETLW 00F8H ;7
RETLW 0080H ;8
RETLW 0090H ;9
RETLW 0088H ;A
RETLW 0083H ;B
RETLW 00C6H ;C
RETLW 00A1H ;D
RETLW 0086H ;E
RETLW 008EH ;F
A1 MOVLW 1;位1顯示數(shù)
MOVWF 50H;
MOVLW 2;位2顯示數(shù)
MOVWF 51H;
MOVLW 3;位3顯示數(shù)
MOVWF 52H;
MOVLW 4;位4顯示數(shù)
MOVWF 53H;
CLRF 60H
MOVLW 4;顯示位數(shù)
MOVWF 40H;
MOVLW B00000001;位碼
MOVWF 41H;
MOVLW 50H;
MOVWF FSR ;間接尋址
BSF STATUS,RP0;選擇體1
BCF STATUS,RP1;
MOVLW 00H;1:2TMRO比例
MOVWF OPTION_REG;分頻1/2
BCF STATUS,RP0;體0
BCF STATUS,RP1;
MOVLW 0FFH;
MOVFW TMR0;初值
BCF INTCON,T0IF;清定時中斷標志
BSF INTCON,T0IE;開定時中斷
BSF INTCON,GIE;開總中斷
;**********************************************************
; 按鍵修改數(shù)據(jù)程序
;**********************************************************
A2 BSF STATUS,RP0
BCF STATUS,RP1;體1
MOVLW 0FFH
MOVWF TRISB;設置B口為輸入口
BCF STATUS,RP0
BCF STATUS,RP1;體0
BTFSC PORTB,0;判斷B口第0位是否按下
GOTO A3;位0則按下按鍵
MOVLW 1;按下存1到EEPROM
MOVWF 61H;數(shù)據(jù)寄存器
CALL WR1;寫數(shù)據(jù)到EEPROM
A3 BCF STATUS,RP0
BCF STATUS,RP1;體0
BTFSC PORTB,1;判斷B口第1位是否按下
GOTO A4;
MOVLW 2;按下存2到EEPROM
MOVWF 61H;數(shù)據(jù)寄存器
CALL WR1;寫數(shù)據(jù)到寄存器
A4 BCF STATUS,RP0;
BCF STATUS,RP1;體0
BTFSC PORTB,2;判斷B口第2位是否按下
GOTO A5;
MOVLW 3;
MOVWF 61H;
CALL WR1;
A5 BCF STATUS,RP0;
BCF STATUS,RP1;
BTFSC PORTB,3;
GOTO A6;
MOVLW 4;
MOVWF 61H;
CALL WR1;
A6 BCF STATUS,RP0;
BCF STATUS,RP1;
BTFSC PORTB,4;
GOTO A7;
MOVLW 5;
MOVWF 61H;
CALL WR1;
A7 BCF STATUS,RP0;
BCF STATUS,RP1;
BTFSC PORTB,5;
GOTO A8;
MOVLW 6;
MOVWF 61H;
CALL WR1;
A8 BCF STATUS,RP0;
BCF STATUS,RP1;
BTFSC PORTB,6;
GOTO A9;
MOVLW 7;
MOVWF 61H;
CALL WR1;
A9 BCF STATUS,RP0;
BCF STATUS,RP1;
BTFSC PORTB,7;
GOTO A10;
MOVLW 8;
MOVWF 61H;
CALL WR1;
A10
CALL RD01;調(diào)用讀數(shù)據(jù)程序
評論