⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interrupt.asm

📁 Alarm clock with PIC microcontroller
💻 ASM
字号:
;==============================================================================
; Interrupt Handler
;------------------------------------------------------------------------------

; Notes:
;
; A regular interrupt generated by TMR0 is used to update one seven segment
; display (with a 25% duty cycle), the LEDs, alarm off lamp and buzzer.
;
; The interrupt code does not call any other subroutines and ensures that the
; W, STATUS and FSR registers are preserved during processing.

;==============================================================================
; Revision History:
;
; 2005-01-24 AJ Initial version
;------------------------------------------------------------------------------

                include ../pic.inc
                include display.inc
                include hardware.inc

                extern  _WREG

;==============================================================================

                udata

; _STATUS and _FSR hold copies of the corresponding
; register file during the interrupt.

_STATUS         res     1
_FSR            res     1

; The low 2 bits of PLEX determine which seven segment
; display is updated this iteration.

PLEX            res     1

; Temporary register used during bit mask calculation.

MASK            res     1

;==============================================================================

.interrupt      code    h'004'

; Start of interrupt save all the critical registers

                movwf   _WREG
                swapf   STATUS,W
                banksel _STATUS
                movwf   _STATUS
                movf    FSR,W
                movwf   _FSR

; Is this a timer interrupt?

                btfss   INTCON,T0IF
                goto    Restore
                bcf     INTCON,T0IF

; Update TMR0 count ready for next interrupt

                movlw   -.78
                addwf   TMR0,F

; Determine which segment will be updated this time

                movlw   SEG1
                movwf   FSR
                movf    PLEX,W
                incf    PLEX,F
                andlw   h'03'
                addwf   FSR,F
                bankisel SEG1

; Convert segment number (0-3) to a bit mask

                movwf   MASK
                incf    MASK,W
                btfsc   MASK,1
                iorwf   MASK,F
                incf    MASK,F
                movf    MASK,W
                banksel PORTA
                movwf   PORTA

; Update the pattern for the selected segment

                banksel PORTB
                movf    INDF,W
                movwf   PORTB

; Update AM/PM, seconds, lamp and buzzer

                banksel CTRL
                clrw
                btfsc   CTRL,CTRL_AMPM
                iorlw   (1<<AMPM)
                btfsc   CTRL,CTRL_SECS
                iorlw   (1<<SECS)
                btfsc   CTRL,CTRL_BUZZ
                iorlw   (1<<BUZZ)
                btfsc   CTRL,CTRL_LAMP
                iorlw   (1<<LAMP)
                banksel PORTD
                movwf   PORTD

                banksel CTRL            ; Clear the synchonisation flag
                bcf     CTRL,CTRL_SYNC

; Restore the saved registers and return

                banksel _STATUS
Restore:        movf    _FSR,W
                movwf   FSR
                swapf   _STATUS,W
                movwf   STATUS
                swapf   _WREG,F
                swapf   _WREG,W

                retfie

                end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -