INCLUDE<P16F877.INC>
#INCLUDE"MAIN.INC"
#INCLUDE"LEDSN.INC"
#INCLUDE"DEL.INC"
#INCLUDE"KEYS.INC"
#INCLUDE"EEPROM.INC"
EADR EQU 31H
COUNT EQU 32H
ORG 00H
NOP
MAIN:
CALL MAINIT
MLP:
CALL DEL
BTFSS 2FH,0
GOTO MLP
CALL KEYS
CALL DISP
BCF 2FH,0
GOTO MLP
DELA
LEDNS
KEYFS
KEYSA
EPFLASH
KEYS:
MOVF KID,0
ADDWF PCL,1
KTAB:GOTO KEYEN
GOTO KEYDEL
GOTO KEYSCAN
GOTO KEYUP
GOTO KEYPROC
CLRF KID
RETLW 0
KEYPROC:
CLRF KID
MOVLW 0AH
SUBWF VAL,0
BTFSS STATUS,C
GOTO KEYNUM
ADDWF PCL,F
GOTO KEYA ;读数据并比较
GOTO KEYB ;清0
GOTO KEYC ;修改地址
GOTO KEYD ;写入新数据
GOTO KEYE ;--
GOTO KEYF ;--
CLRF VAL
RETLW 0
KEYA: ;AFUN
; MOVLW 0AH
; MOVWF DAT1
BTFSC 2FH,3
GOTO KAEXT
MOVLW DAT1
MOVWF FSR
MOVLW 6
MOVWF R0
KAL:CALL EPREAD
MOVF DAT,W
XORWF INDF,W
BNZ KAEXT
INCF ADR,F
DECFSZ R0,F
GOTO KAL
BSF 2EH,0
KAEXT:
RETLW 0
KEYB: ;BFUN
; MOVLW 0BH
; MOVWF DAT1
MOVLW 6
MOVWF R0
MOVLW DAT1
MOVWF FSR
CLRW
KBL:CLRF INDF
;MOVWF INDF,1
INCF FSR,F
DECFSZ R0,1
GOTO KBL
RETLW 0
KEYC: ;CFUN
; MOVLW 0CH
; MOVWF DAT1
BSF 2EH,1
MOVF EADR,0
MOVWF ADR
CALL EPREAD
XORLW .200
BNZ KCEXT
; CLRF EADR
MOVLW 7
ADDWF EADR,F
ADDWF ADR,F
KCEXT:
RETLW 0
KEYD:
; MOVLW 0DH
; MOVWF DAT1
BTFSS 2EH,1
GOTO KCEXT
MOVLW DAT1
MOVWF FSR
MOVLW 6
MOVWF R0
KDL:MOVF INDF,0
MOVWF DAT
CALL EPWRITE
INCF FSR,F
INCF ADR,F
DECFSZ R0,F
GOTO KDL
MOVF EADR,0
MOVWF ADR
MOVF COUNT,W
MOVWF DAT
CALL EPWRITE
INCF COUNT,F
BCF 2EH,1
RETLW 0
KEYE:
RETLW 0
KEYF:
RETLW 0
KEYNUM:
MOVLW DAT1
MOVWF FSR
MOVLW 2
MOVWF R1
MOVF VAL,0
MOVWF R0
KPL:
MOVF INDF,0
MOVWF KTMP
MOVF R0,0
MOVWF INDF
INCF FSR,1
MOVF INDF,0
MOVWF R0
MOVF KTMP,0
MOVWF INDF
INCF FSR,1
DECFSZ R1,1
GOTO KPL
KNEXT:
RETLW 0
MAINIT:
BANK1
MOVLW 0FH
MOVWF TD
CLRF TC
CLRF TB
BANK0
CLRF ADR
CLRF DAT
CLRF COUNT
MOVLW 7
MOVWF EADR
MOVLW 04H
MOVWF DAT1
MOVLW 6H
MOVWF DAT2
CLRF DAT3
CLRF DAT4
MOVLW 0FFH
MOVWF PB
MOVLW 0FFH
MOVWF PC
RETLW 0
END
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
TITLE "MAIN MACRO FILE"
;经常用到的自定义宏命令和变量
;简略指令集
;程序内部暂存器,只中当前子程序中使用
;程序退出后其值效 常作循环 暂存变量
DAT1 EQU 20H
DAT2 EQU 21H
DAT3 EQU 22H
DAT4 EQU 23H
DAT5 EQU 24H
DAT6 EQU 25H
DAT7 EQU 26H
DAT8 EQU 27H
R0 EQU 40H
R1 EQU 41H
R2 EQU 42H
R3 EQU 43H
R4 EQU 44H
R5 EQU 45H
R6 EQU 46H
R7 EQU 47H
AW EQU 48H
BW EQU 49H
CW EQU 4AH
EW EQU 4BH
;2FH SYSTEM BYTE
SYS EQU 0 ;系统标志位
TMENA EQU 1
EMEND EQU 2
;KEYEN EQU 4
;SETRP0=RP0=1 SETRP1=RP1=1
#DEFINE SETRP0 BSF STATUS,5
#DEFINE SETRP1 BSF STATUS,6
;CLRP0=RP0=0 CLRP1=RP1=0
#DEFINE CLRP0 BCF STATUS,5
#DEFINE CLRP1 BCF STATUS,6
;CLRGIE=GIE=0 SETGIE=GIE=1
#DEFINE CLRGIE BCF INTCON,7
#DEFINE SETGIE BSF INTCON,7
#DEFINE CLRPBF BCF INTCON,0
#DEFINE SETPBF BSF INTCON,0
#DEFINE CLRINTF BCF INTCON,1
#DEFINE SETINTF BSF INTCON,1
#DEFINE CLRPEIE BCF INTCON,6
#DEFINE SETPEIE BSF INTCON,6
;CLRT0F=T0IF=0 SET0F=T0IF=1
#DEFINE CLRT0F BCF INTCON,2
#DEFINE SET0F BSF INTCON,2
;
#DEFINE CLRT1F BCF PIR1,0
#DEFINE SET1F BSF PIR1,0
;
#DEFINE CLRT2F BCF PIR1,1
#DEFINE SET2F BSF PIR1,1
#DEFINE CLRCP1F BCF PIR1,2
#DEFINE SETCP1F BSF PIR1,2
#DEFINE CLRSPF BCF PIR1,3
#DEFINE SETSPF BSF PIR1,3
#DEFINE CLRTXF BCF PIR1,4
#DEFINE SETTXF BSF PIR1,4
#DEFINE CLRRXF BCF PIR1,5
#DEFINE SETRXT BSF PIR1,5
#DEFINE CLRADF BCF PIR1,6
#DEFINE SETADF BSF PIR1,6
#DEFINE CLRPSPF BCF PIR1,7
#DEFINE SETPSPF BSF PIR1,7
#DEFINE CLRCP2F BCF PIR2,0
#DEFINE SETCP2F BSF PIR2,0
#DEFINE CLRBCF BCF PIR2,3
#DEFINE SETBCF BSF PIR2,3
;
#DEFINE T1ON BSF T1CON,0
#DEFINE T1OFF BCF T1CON,0
#DEFINE T2ON BSF T2CON,2
#DEFINE T2OFF BCF T2CON,2
#DEFINE EPRD BSF EECON1,0
#DEFINE EPNRD BCF EECON1,0
#DEFINE EPWR BSF EECON1,1
#DEFINE EPNWR BCF EECON1,1
#DEFINE EPWEN BSF EECON1,2
#DEFINE EPWNE BCF EECON1,2
#DEFINE EEPOM BCF EECON1,7
#DEFINE FLASH BSF EECON1,7
#DEFINE PA PORTA
#DEFINE PB PORTB
#DEFINE PC PORTC
#DEFINE PD PORTD
#DEFINE PE PORTE
#DEFINE CLRPA CLRF PA
#DEFINE CLRPB CLRF PB
#DEFINE CLRPC CLRF PC
#DEFINE CLRPD CLRF PD
#DEFINE CLRPE CLRF PE
#DEFINE TA TRISA
#DEFINE TB TRISB
#DEFINE TC TRISC
#DEFINE TD TRISD
#DEFINE TE TRISE
#DEFINE CLRTA CLRF TA
#DEFINE CLRTB CLRF TB
#DEFINE CLRTC CLRF TC
#DEFINE CLRTD CLRF TD
#DEFINE CLRTE CLRF TE
BANK0 MACRO
BCF STATUS,RP0
BCF STATUS,RP1
ENDM
BANK1 MACRO
BSF STATUS,RP0
BCF STATUS,RP1
ENDM
BANK2 MACRO
BCF STATUS,RP0
BSF STATUS,RP1
ENDM
BANK3 MACRO
BSF STATUS,RP0
BSF STATUS,RP1
ENDM
一周热门 更多>