PROCESSOR 16C74
INCLUDE "P16C74B.INC "
SECEQU 0X23
MSEC EQU 0x24
TEMP1 EQU 0X22
FLAG2 EQU 0X28
ORG 0x00
GOTO START
ORG 0x04设定中断向量
BCF STATUS,RP0
BTFSC INTCON,T0IF 判断TIER0中断标志位是否被设置
GOTO TMR0_ISR 若是,则去执行TIMER0中断子程序
RETFIE
START:
CALL PIC_INIT 去设置端口、TIMER0工作滑消模式
BSF INTCON,GIE
BSF INTCON,T0IE
MAIN_LOOP:
程序的主体是个无限循环
BTFSC FLAG2,7
CALL DISPLAY
GOTO MAIN_LOOP
PIC_INIT:
CLRF INTCON
BCF INTCON,T0IE
BSF STATUS,RP0
MOVLW B'00000000'梁掘B’XXXXXXXX’表示单引号中橡让核的数是二
MOVWF TRISB
MOVLW B'00000000'
MOVWF TRISC
BCF STATUS,RP0
MOVLW B'11000000'B’XXXXXXXX’表示单引号中的数是二
MOVWF PORTB
MOVLW B'11000000'
MOVWF PORTC
BSF STATUS,RP0
MOVLW B'11000100'
MOVWF OPTION_REG 对TIMER0工作模式进行设置,32分频
BCF STATUS,RP0
MOVLW 0X06
MOVWF TMR0
CLRF SEC
CLRF MSEC
CLRF TEMP1
CLRF FLAG2
RETURN
TMR0_ISR:
CLRWDT
BSF FLAG2,7
BCF INTCON,T0IF
MOVLW 0X06
MOVWF TMR0
CLRWDT
INCF TEMP1,1
MOVF TEMP1,0
SUBLW .125 125-TEMP
BTFSS STATUS,2
RETFIE
CLRWDT
CLRF TEMP1
INCF MSEC,1
RETFIE
DISPLAY:
MOVF MSEC,0
SUBLW .10
BTFSS STATUS,2
GOTO NEXT_1
CLRWDT
CLRF MSEC
INCF SEC,1
MOVF SEC,0
SUBLW .6
BTFSS STATUS,2
GOTO NEXT_1
CLRF SEC
NEXT_1:
CLRWDT
MOVF MSEC,W
CALL CHAR_CODE
MOVWF PORTC
MOVF SEC,W
CALL CHAR_CODE
MOVWF PORTB
BCF FLAG2,7
RETURN
CHAR_CODE:
ADDWF PCL,1PCL+=W
RETLW B'11000000' Code for 0
RETLW B'11111001' Code for 1
RETLW B'10100100' Code for 2
RETLW B'10110000' Code for 3
RETLW B'10011001' Code for 4
RETLW B'10010010' Code for 5
RETLW B'10000010' Code for 6
RETLW B'11111000' Code for 7
RETLW B'10000000' Code for 8
RETLW B'10010000' Code for 9
END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)