[Menu]>[Circuits Gallery]>[Signboard 2]>[Software]


Software for Signboard 2
[Edge LED Timer]




This routine sholud be put on the main process.
Function
    This routine changes the turn of the edge LED with the timer.
    The direction of the turn of the edge LEDs are changed every about 6 seconds.
    In the animation which is shown above, it is changing within about 1 second to make a file size small.


Source code

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
;*************  Edge LED timer process  *****************
edge_timer
        bsf     status,rp0      ;Change to Bank1
        movlw   b'00000111'     ;TOCS/PSA=0,PS=111
        movwf   option_reg      ;Set OPTION_REG
        bcf     status,rp0      ;Change to Bank0
        movlw   d'0'            ;Set Hard timer(26msec)
        movwf   tmr0            ;Set TMR0
        movlw   d'255'          ;Set Soft count
        movwf   h_timer         ;Save soft count
        movlw   h'a0'           ;GIE=1,TOIE=1
        movwf   intcon          ;Interruption enable
        return

;---------------  Interruption processing  --------------
int
        movwf   w_save          ;Save W register
        movf    status,w        ;Read STATUS reg
        movwf   s_save          ;Save STATUS reg
        bcf     status,rp0      ;Change to Bank0
        btfsc   intcon,t0if     ;Time out interruption ?
        goto    timer_int       ;Jump to Timer process
 
;------------  END of Interruption Process --------------
int_end
        movf    s_save,w        ;Read saved STATUS reg
        movwf   status          ;Recover STATUS reg
        swapf   w_save,f        ;Read saved W register
        swapf   w_save,w        ;Recover W register
        retfie        

;-----------  Time-out interruption Process  ------------
timer_int
        bcf     intcon,t0if     ;Clear timer int flag
        movlw   d'0'            ;Set Hard timer(26msec)
        movwf   tmr0            ;Set TMR0
        decfsz  h_timer,f       ;Time over ?
        goto    int_end         ;No. Retry
        movlw   d'255'          ;Set Soft count
        movwf   h_timer         ;Save Soft count

;------------------  Switch Process  --------------------
        btfsc   portb,7         ;RB7 = 0(Left) ?
        goto    timer_right     ;RB7 = 1(Right)
        movf    portb,w         ;Read portb
        iorlw   h'80'           ;Set right data
        movwf   portb           ;Output data
        goto    int_end
timer_right
        movf    portb,w         ;Read portb
        andlw   h'7f'           ;Set left data
        movwf   portb           ;Output data
        goto    int_end



Explanation
    When using an edge LED timer subroutine, be careful of the following point.
    When calling this subroutine at the main processing, don't call in the loop.

    In this subroutine, it has start-up processing of the hard timer. It doesn't need to start up once again if it starts up once. A hard timer is restarted by short time when calling a subroutine in the loop and it doesn't have normal operation.
    —á
    main
            call    edge_timer
    main1
            call    subroutine-1
    
            call    subroutine-n
            goto    main1
    When pasting this subroutine to the main processing, it needs to paste after deleting the INT label line of the main processing.

    Otherwise, the duplication of the INT label occurs. The INT label of this processing must be used.

    When using prescaler, the time-out of the hard timer occurs within a maximum of 26 milliseconds. Therefore, it counts the interruption of the time-out by the software and the direction of the turn of the edge LED makes change every about 6.6 seconds(26msec x 255).