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

📄 controllogic.asm

📁 Alarm clock with PIC microcontroller
💻 ASM
📖 第 1 页 / 共 3 页
字号:
                movlw   RTC_AL_SAT_MIN  ; .. and HOUR
                movwf   I2C_REGISTER
                movlw   .2
                movwf   I2C_REGCOUNT
                bankisel AL_SAT_MIN     ; Point the FSR at the MINUTE
                movlw   AL_SAT_MIN
                movwf   FSR
                lcall   DS1307Tx        ; And write them back

;------------------------------------------------------------------------------

AdjustAlarmSu:
                call    WaitForRelease
                banksel CHANGED
                clrf    CHANGED

AlarmSuAdjust:
                bankisel AL_SUN_MIN     ; Point the FSR at the MINUTES
                movlw   AL_SUN_MIN
                movwf   FSR
                call    ShowTime        ; Update the displayed time 
                banksel CTRL
                bcf     CTRL,CTRL_SECS
                call    WaitForChange
                banksel SCRATCH
                movwf   SCRATCH
                btfsc   SCRATCH,SW_R
                goto    TweakAlarmSu
                btfsc   SCRATCH,SW_H
                goto    TweakHourSu
                btfsc   SCRATCH,SW_M
                goto    TweakMinSu
                goto    AlarmSuAdjust

TweakHourSu:
                bankisel AL_SUN_HOUR
                movlw   AL_SUN_HOUR
                movwf   FSR
                call    TweakAlarmHour
                banksel CHANGED
                bsf     CHANGED,7
                call    WaitForRelease
                goto    AlarmSuAdjust

TweakMinSu:
                bankisel AL_SUN_MIN
                movlw   AL_SUN_MIN
                movwf   FSR
                call    TweakAlarmMinute
                banksel CHANGED
                bsf     CHANGED,7
                call    WaitForRelease
                goto    AlarmSuAdjust

TweakAlarmSu:
                banksel CHANGED
                btfss   CHANGED,7
                goto    AdjustmentOver

                banksel I2C_REGISTER    ; Set I2C registers to update MINUTE
                movlw   RTC_AL_SUN_MIN  ; .. and HOUR
                movwf   I2C_REGISTER
                movlw   .2
                movwf   I2C_REGCOUNT
                bankisel AL_SUN_MIN     ; Point the FSR at the MINUTE
                movlw   AL_SUN_MIN
                movwf   FSR
                lcall   DS1307Tx        ; And write them back

AdjustmentOver:
                call    WaitForRelease
                banksel CTRL
                bcf     CTRL,CTRL_LAMP
                return

;------------------------------------------------------------------------------

TweakAlarmHour:
                incf    INDF,W          ; Bump the hour by one
                andlw   h'3f'           ; Mask out all but the hours and PM
                addlw   .6              ; Add one and check for >9 digit
                skpdc
                addlw   -.6             ; Its not, so take back 6
                movwf   INDF
                andlw   h'1f'           ; Mask out all but hours
                addlw   -h'13'          ; Is the value >12?
                skpc
                goto    Set12HourBitAl
                movf    INDF,W
                addlw   .14
                movwf   INDF
Set12HourBitAl:
                bsf     INDF,6          ; Force AM/PM mode
                return

TweakAlarmMinute:
                incf    INDF,W          ; Bump the minutes by one
                addlw   .6              ; See if the lo nybble is >9
                skpdc
                addlw   -.6             ; Its not, so take the 6 back
                movwf   INDF         
                addlw   -h'60'          ; Is the value >59?
                skpnc
                clrf    INDF            ; Yes, set it back to 0
                return
                    
;------------------------------------------------------------------------------

HandleDayDate:
                call    ShowDate
                goto    WaitForRelease

;------------------------------------------------------------------------------

HandleMonthYear:
                call    ShowMonth

;------------------------------------------------------------------------------

WaitForRelease:
                call    WaitForSync     ; Give the switches time to settle
                banksel PORTE           ; Read the switch states
                movf    PORTE,W
                xorlw   h'ff'           ; Invert the switch states
                andlw   (1<<SW_R)|(1<<SW_H)|(1<<SW_M)
                skpz
                goto    WaitForRelease  ; Repeat until all switches released
                return

;------------------------------------------------------------------------------

ShowTime:

; Converts minutes to led pattern

                swapf   INDF,W
                andlw   h'0f'
                lcall   HexLedPattern
                xorlw   h'ff'
                banksel SEG3
                movwf   SEG3
                movf    INDF,W
                andlw   h'0f'
                lcall   HexLedPattern
                xorlw   h'ff'
                banksel SEG4
                movwf   SEG4
                incf    FSR,F

; Converts hours to led pattern

                swapf   INDF,W
                andlw   h'01'
                lcall   HexLedPattern
                xorlw   h'ff'
                banksel SEG1
                movwf   SEG1
                movf    INDF,W
                andlw   h'0f'
                lcall   HexLedPattern
                xorlw   h'ff'
                banksel SEG2
                movwf   SEG2

; Set AM/PM indicator

                movf    INDF,W
                banksel CTRL
                bcf     CTRL,CTRL_AMPM
                andlw   h'20'
                skpz
                bsf     CTRL,CTRL_AMPM

; Use 1Hz input to set seconds indicator

                banksel PORTD
                movf    PORTD,W
                banksel CTRL
                bcf     CTRL,CTRL_SECS
                andlw   (1<<HZ)
                skpz
                bsf     CTRL,CTRL_SECS

                return

;------------------------------------------------------------------------------
; Changes the display to show the current day and date

ShowDate:
                bankisel DAY            ; Point FSR at DAY
                movlw   DAY
                movwf   FSR

                movf    INDF,W          ; Determine the LED pattern for the
                andlw   .7              ; .. first letter
                call    LetterPattern
                xorlw   h'ff'           ; Invert to match hardware
                banksel SEG1            ; And store in SEG1 pattern buffer
                movwf   SEG1
                movf    INDF,W          ; Determine the LED pattern for the
                andlw   .7              ; .. second letter
                iorlw   .8
                call    LetterPattern
                xorlw   h'ff'           ; Invert to match hardware
                banksel SEG2            ; And store in SEG2 pattern buffer
                movwf   SEG2

                incf    FSR,F           ; Point FSR at DATE

                swapf   INDF,W          ; Convert date hi nybble to LED
                andlw   h'0f'           ; .. pattern
                lcall   HexLedPattern
                xorlw   h'ff'           ; Invert to match hardware
                banksel SEG3            ; And store in SEG3 pattern buffer
                movwf   SEG3
                movf    INDF,W          ; Convert date lo nybble to LED
                andlw   h'0f'           ; .. pattern
                call    HexLedPattern
                xorlw   h'ff'           ; Invert to match hardware
                banksel SEG4            ; And store in SEG4 pattern buffer
                movwf   SEG4
                bcf     CTRL,CTRL_AMPM  ; Ensure AM/PM LED is off
                return

LetterPattern:
                banksel SCRATCH         ; Save day code in scratch area
                movwf   SCRATCH
                movlw   high Values     ; Set up PCLATH for jump table
                movwf   PCLATH
                movlw   low Values      ; Compute address of table entry
                addwf   SCRATCH,W
                skpnc                   ; Increment PCLATH if jump goes across
                incf    PCLATH,F        ; .. page boundary.
                movwf   PCL             ; Goto the target entry

Values          retlw                     SG    ; --
                retlw   SA   |SC|SD|   SF|SG    ; Su
                retlw   SA|SB|SC|   SE|SF       ; Mo
                retlw   SA|SB|SC                ; Tu
                retlw      SB|SC|SD|SE|SF       ; We
                retlw   SA|SB|SC                ; Th
                retlw   SA|         SE|SF|SG    ; Fr
                retlw   SA   |SC|SD|   SF|SG    ; Sa

                retlw                     SG    ; --
                retlw         SC|SD|SE          ; Su
                retlw         SC|SD|SE|   SG    ; Mo
                retlw         SC|SD|SE          ; Tu
                retlw   SA|      SD|SE|SF|SG    ; We
                retlw         SC|   SE|SF|SG    ; Th
                retlw               SE|   SG    ; Fr
                retlw   SA|SB|SC|   SE|SF|SG    ; Sa

;------------------------------------------------------------------------------
; Changes the display to show the current month and year

ShowMonth:
                bankisel MONTH          ; Point FSR at the MONTH
                movlw   MONTH
                movwf   FSR

                swapf   INDF,W          ; Convert month hi nybble to LED
                andlw   h'0f'           ; .. pattern
                lcall   HexLedPattern
                xorlw   h'ff'           ; Invert to match hardware
                banksel SEG1            ; And store in SEG1 pattern buffer
                movwf   SEG1    
                movf    INDF,W          ; Convert month lo nybble to LED
                andlw   h'0f'           ; .. pattern
                lcall   HexLedPattern
                xorlw   h'ff'           ; Invert to match hardware
                banksel SEG2            ; And store in SEG2 pattern buffer
                movwf   SEG2                                

                incf    FSR,F           ; Point FSR at the YEAR

                swapf   INDF,W          ; Convert month hi nybble to LED
                andlw   h'0f'           ; .. pattern
                lcall   HexLedPattern
                xorlw   h'ff'           ; Invert to match hardware
                banksel SEG3            ; And store in SEG1 pattern buffer
                movwf   SEG3    
                movf    INDF,W          ; Convert month lo nybble to LED
                andlw   h'0f'           ; .. pattern
                lcall   HexLedPattern
                xorlw   h'ff'           ; Invert to match hardware
                banksel SEG4            ; And store in SEG2 pattern buffer
                movwf   SEG4                                
                bcf     CTRL,CTRL_AMPM  ; Ensure AM/PM LED is off
                return

;==============================================================================
; Wait until the interrupt routine clears the synchronisation flag.

WaitForSync:
                banksel CTRL            ; Set the synchronisation bit
                bsf     CTRL,CTRL_SYNC
                btfsc   CTRL,CTRL_SYNC  ; Then wait until it is cleared
                goto    $-1
                return

                end

⌨️ 快捷键说明

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