Efekt barevného podsvícení krystalu

Jde o podsvícení krystalu RGB led diodami s efektem pomalého vzájemného prolínání spektra barev 🙂

V každé ze tří RGB led diod (zde dvojic) se dle kroku efektu aktuálně prolínají jen dvě barvy. Kombinace barev se obměňují ve chvíli utlumení dané barvy v RGB led diodě.

Jas je na principu PWM (pulsně šířková modulace). Jelikož PIC16F73 má v sobě jen jedno PWM a pro RGB led diody je jich potřeba 9, pořešil jsem programově.

Oproti schématu jsem zdvojnásobil počet RGB led diod s předřazenými odpory, zapojil je ve třech dvojicích.

Program si průběžně upravuju. Datum změny je uveden v názvu skompilovaného programu a ve zdrojácích.

 

El. schéma:

 

Skompilovaný program:

RGB-LED-EFEKT-16F73.20211018.hex

 

Assembler zdrojáky:

RGB-LED-EFEKT-16F73.asm

;#ASM###########################################################################################MCH#
;#                                                                                                 #
;# RGB-LED-EFEKT-16F73.asm                                                                         #
;# ```````````````````````                                                                         #
#DEFINE  k_YY    .21     ; rok      (jen dekada)                                                   #
#DEFINE  k_mm    .10     ; mesic                                                                   #
#DEFINE  k_dd    .18     ; den                                                                     #
;#-------------------------------------------------------------------------------------------------#
;#                             _______________PIC-16F73_______________                             #
;#                            |                   ^                   |                            #
;#                 VPP --> [01| -> MCLR/VPP                PGD/RB7 <> |28] <-> PGD                 #
;#             #LED3_B <-- [02| <> RA0/AN0                 PGC/RB6 <> |27] <-- PGC                 #
;#             #LED3_R <-- [03| <> RA1/AN1                     RB5 <> |26]                         #
;#             #LED3_G <-- [04| <> RA2/AN2                     RB4 <> |25]                         #
;#                         [05| <> RA3/AN3/VREF            PGM/RB3 <> |24]                         #
;#                         [06| <> RA4/T0CKI                   RB2 <> |23]                         #
;#                         [07| <> RA5/AN4/SS                  RB1 <> |22]                         #
;#                     GND [08| VSS                        INT/RB0 <> |21]                         #
;#          8 Mhz .-|X|--- [09| -> OSC1/CLKIN                     VDD |20] +5V                     #
;#                '------- [10| <- OSC2/CLKOU                     VSS |19] GND                     #
;#             #LED1_G <-- [11| <> RC0/T1OSO/T1CK        RX/DT/RC7 <- |18]                         #
;#             #LED1_R <-- [12| <> RC1/T1OSI/CCP2        TX/CK/RC6 -> |17]                         #
;#             #LED1_B <-- [13| <> RC2/CCP1                SDO/RC5 <> |16] --> #LED2_B             #
;#             #LED2_R <-- [14| <- RC3/SCK/SCL         SDA/SDI/RC4 <> |15] --> #LED2_G             #
;#                            |_______________________________________|                            #
;#_________________________________________________________________________________________________#
;#                                                                                                 #
;# Popis:   Svetelny efekt. Ve smycce pomale prolinani barev tri RGB LED diod.                     #
;#                                                                                                 #
;# Princip: Kazda ze tri RGB LED diod prechazi z jedne zakladni barvy do druhe (v kazde z RGB LED  #
;#        se jedna barva vynecha) dle predvolenych kombinaci barev. Prepnuti barevne kombinace je  #
;#        pri uplnem stlumeni barvy v RGB LED diode. Prolinaci cykly RGB LED diod jsou synchronni. #
;#        Rychlost prolinani je udavana casovacem TMR1.                                            #
;#          Jas je PWM (pulsne sirkovou modulaci) ve 12,6 ms periodach s 6 bitovym rozlisenim.     #
;#        PWM pro 3 RGB LED je SW a obhospodarovane v prerusenich od casovace TMR0.                #
;#                                                                                                 #
;# ............................................................................................... #
;#_________________________________________________________________________________________________#

; ________
; PROCESOR

    LIST P=16F73

    __CONFIG    0x52      ; BOREN:ON, CP0:OFF, PWRTEN:ON, DTWEN:OFF, FOSC:HS 

; _______
; SDILENO

    INCLUDE     

    EXTERN      r_LED1_R, r_LED1_G, r_LED1_B, r_LED2_R, r_LED2_G, r_LED2_B
    EXTERN      r_LED3_R, r_LED3_G, r_LED3_B, _PWM_LED_INIT, _PWM_LED_MPX

; ________
; REGISTRY

MEM_0x20                        UDATA_SHR       0x20

r_SAVE__W                       RES 1           ; USCHOVANI 'W'
r_SAVE__STATUS                  RES 1           ; USCHOVANI REGISTRU 'STATUS'
r_SAVE__PCLATH                  RES 1           ; USCHOVANI STRANKY PROGRAMU
r_SAVE__FSR                     RES 1           ; USCHOVANI ADRESY REGISTRU
r_FLG                           RES 1           ; BITOVE PRIZNAKY

r_PAUZA                         RES 1           ; OBECNA PAUZA
r_PAUZA_2                       RES 1           ; -"-

r_PERIODA_EFEKTU                RES 1           ; DOBA PERIODY EFEKTU
r_JAS_EFEKTU                    RES 1           ; JAS PRO LED

r_INDEX_VARIACE_PRIMARNI        RES 1           ;
r_INDEX_VARIACE_SEKUNDARNI      RES 1           ;

; _________
; KONSTANTY
          
#DEFINE      w                   0               ; CIL ->(W)
#DEFINE      f                   1               ; CIL ->(REGISTR)
#DEFINE      BANK_1              STATUS,RP0      ; PREPINANI BANK 0<->1

#DEFINE      k_FLG_STA_EFEKT     r_FLG,0         ; START KONTROLY / ERASE SPI EEPROM
#DEFINE      k_FLG_SMER    r_FLG,1         ; SMER JASU SILICI/SLABNOUCI

#DEFINE      k_PERIODA_EFEKTU    .8              ; 262ms PERIOD KROKU EFEKTU
#DEFINE      k_POCET_KOMBINACI   .24             ; SEKUNDARNI SADA BAREV JE O 3 KRACENA

;___________________________________________________________________________________________________
;###################################################################################################
;#                                                                                                 #
;#                                 S T A R T   P O   Z A P N U T I                                 #
;#_________________________________________________________________________________________________#
;###################################################################################################

CODE_0x000      CODE    0x000

        GOTO    _I_N_I_T_        
    
        DB      0x00, k_YY, 0x00, k_mm, 0x00, k_dd  ; DATUM AKTUALIZACE

;___________________________________________________________________________________________________
;###################################################################################################
;#                                                                                                #
;#              #####   #####   #####  #####   ##  ##   ####   ######  ##   ##   ##                #
;#              ##  ##  ##  ##  ##     ##  ##  ##  ##  ##      ##      ###  ##   ##                #
;#              #####   ####    ####   ####    ##  ##    ####  #####   ## # ##   ##                #
;#              ##      ## ##   ##     ## ##   ##  ##  #    ## ##      ##  ###   ##                #
;#              ##      ##  ##  #####  ##  ##   ####    ####   ######  ##   ##   ##                #
;#_________________________________________________________________________________________________#
;###################################################################################################

CODE_0x004      CODE    0x004

_P_R_E_R_U_S_E_N_I_:

    MOVWF   r_SAVE__W                           ; USCHOVANI 'W'
    SWAPF   STATUS,w                            ; USCHOVANI REGISTRU 'STATUS'
    MOVWF   r_SAVE__STATUS                      ; <-'
    MOVF    PCLATH,w                            ; USCHOVANI STRANKY PROGRAMU
    MOVWF   r_SAVE__PCLATH                      ; <-'
    MOVF    FSR,w                               ; USCHOVANI ADRESY REGISTRU
    MOVWF   r_SAVE__FSR                         ; <-' CLRF PCLATH ; PREPNUTI STRANKY PROGRAMU -> 0x000 ~ 0x0FF

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

_P_R_E_R_U_S_E_N_I_.Tmr0:

    BTFSS   INTCON,T0IF                         ; ?? OBSLOUZIT PWM SVIT RGB LED DIOD ??
    GOTO    _P_R_E_R_U_S_E_N_I_.Tmr1            ; 'NE'

    ; --- PWM LED ---

    CALL    _PWM_LED_MPX                        ; PWM KROK

    BCF     INTCON,T0IF                         ; VYP: PRIZNAK TMR0

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

_P_R_E_R_U_S_E_N_I_.Tmr1:

    BTFSS   PIR1,TMR1IF                         ; ?? KROK EFEKTU BAREV ??
    GOTO    _P_R_E_R_U_S_E_N_I_.Zakonceni       ; 'NE'

    BCF     PIR1,TMR1IF                         ; VYP: PRIZNAK TMR1

    DECFSZ  r_PERIODA_EFEKTU                    ; ?? DALSI KROK EFEKTU ??
    GOTO    _P_R_E_R_U_S_E_N_I_.Zakonceni       ; 'NE'

    MOVLW   k_PERIODA_EFEKTU                    ; DOBA PERIODY EFEKTU
    MOVWF   r_PERIODA_EFEKTU

    BSF  k_FLG_STA_EFEKT                         ; ZAP: START KROKU EFEKTU

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

_P_R_E_R_U_S_E_N_I_.Zakonceni:

    MOVF  r_SAVE__FSR,w                       ; OBNOVENI  ADRESY REGISTRU
    MOVWF  FSR                                 ; <-'
    MOVF  r_SAVE__PCLATH,w                    ; OBNOVENI STRANKY PROGRAMU
    MOVWF  PCLATH                              ; <-'
    SWAPF  r_SAVE__STATUS,w                    ; OBNOVENI REGISTRU 'STATUS'
    MOVWF  STATUS                              ; <-'
    SWAPF  r_SAVE__W,f                         ; OBNOVENI REGISTRU 'W'
    SWAPF  r_SAVE__W,w                         ; <-'  

    RETFIE

;___________________________________________________________________________________________________
;###################################################################################################
;#                                                                                                 #
;#    #####   ####  ##                                                                             #
;#    ##  ## ##     ##    ##                                                                       #
;#    #####  ##     ##                                                                             #
;#    ##     ##     ##    ##                                                                       #
;#    ##      ####  #####       ##    ##    ##                                                     #
;#_________________________________________________________________________________________________#
;###################################################################################################

;###################################################################################################
; PCL VARIACE PRIMARNICH BAREV
;---------------------------------------------------------------------------------------------------
_PCL_SADA_VARIACI_PRIMARNI:

        ADDWF   r_INDEX_VARIACE_PRIMARNI,w  ; + OFEST KROKU VARIACE PO TROJICICH

        ADDWF   PCL,f

        ; --- I. VARIACE ---

        RETLW   r_LED1_G  
        RETLW   r_LED2_B
        RETLW   r_LED3_R

        ; --- POSUN ---

        RETLW   r_LED1_R
        RETLW   r_LED2_B 
        RETLW   r_LED3_B 

        ; --- POSUN ---

        RETLW   r_LED1_B
        RETLW   r_LED2_B
        RETLW   r_LED3_G

        ; --- II. VARIACE ---

        RETLW   r_LED1_G  
  RETLW   r_LED2_R
  RETLW   r_LED3_R

        ; --- POSUN ---

        RETLW   r_LED1_R
        RETLW   r_LED2_R
        RETLW   r_LED3_B 

        ; --- POSUN ---

        RETLW   r_LED1_B
        RETLW   r_LED2_R
        RETLW   r_LED3_G

        ; --- III. VARIACE ---

        RETLW   r_LED1_R  
        RETLW   r_LED2_G
        RETLW   r_LED3_R

        ; --- POSUN ---

        RETLW   r_LED1_G
        RETLW   r_LED2_R
        RETLW   r_LED3_G 

        ; --- POSUN ---

        RETLW   r_LED1_B
        RETLW   r_LED2_G
        RETLW   r_LED3_R

;###################################################################################################
; PCL VARIACE SEKUNDARNICH BAREV
;---------------------------------------------------------------------------------------------------
_PCL_SADA_VARIACI_SEKUNDARNI:

        ADDWF   r_INDEX_VARIACE_SEKUNDARNI,w    ; + OFEST KROKU VARIACE PO TROJICICH

        ADDWF   PCL,f

        ; --- I. VARIACE ---

        RETLW   r_LED1_R
        RETLW   r_LED2_G
        RETLW   r_LED3_B

        ; --- POSUN ---

        RETLW   r_LED1_B
        RETLW   r_LED2_R
        RETLW   r_LED3_G

        ; --- POSUN ---

        RETLW   r_LED1_G
        RETLW   r_LED2_G
        RETLW   r_LED3_R

        ; --- II. VARIACE ---

        RETLW   r_LED1_R
        RETLW   r_LED2_G
        RETLW   r_LED3_B

        ; --- POSUN ---

        RETLW   r_LED1_B
        RETLW   r_LED2_G
        RETLW   r_LED3_G

        ; --- POSUN ---

        RETLW   r_LED1_G
        RETLW   r_LED2_G
        RETLW   r_LED3_R

        ; --- III. VARIACE ---

        RETLW   r_LED1_G
        RETLW   r_LED2_R
        RETLW   r_LED3_G

        ; --- POSUN ---

        RETLW   r_LED1_R
        RETLW   r_LED2_G
        RETLW   r_LED3_R

        ; --- POSUN ---
        ; --- OMEZENO K PROSTRIDANI S PRIMARNIMI BRAVAMI NA LICHY POCET ---

;___________________________________________________________________________________________________
;###################################################################################################
;#                                                                                                 #
;#                                     ##   ##   ##   ##  ######                                   #
;#                                     ##   ###  ##   ##    ##                                     #
;#                                     ##   ## # ##   ##    ##                                     #
;#                                     ##   ##  ###   ##    ##                                     #
;#                                     ##   ##   ##   ##    ##                                     #
;#_________________________________________________________________________________________________#
;###################################################################################################

_I_N_I_T_:

        BCF     INTCON,GIE                      ; VYP: PRERUSENI

        ; --- VYNULOVANI DATOVYCH REGISTRU ---
  
        MOVLW   0x80                            ; NASTAVENI NA ADRESU POSLEDNIHO REGISTRU
        MOVWF   FSR

_I_N_I_T_.Smycka:

        DECF  FSR,f                           ; -1 Z ADRESY REGISTRU
        CLRF  INDF                            ; VYNULOVANI REGISTRU

        MOVLW   0x20                            ; ADRESA PRVNIHO REGISTRU
        XORWF   FSR,w                           ; PROROVNANI S FSR
        BTFSS   STATUS,Z                        ; ?? VSE VYNULOVANO ??
        GOTO    _I_N_I_T_.Smycka                ; 'NE'

        ; --- A/D PORTY JAKO DIGITALNI ---

        BSF     BANK_1                          ; BANKA 1

        MOVLW   0x06                            ; PREPNUTI ANALOG VSTUPU NA DIGITALNI
        MOVWF   ADCON1
  
        MOVLW   b'00000111'                     ; PULL-UP:ON, RB0/INT:FALL, 
        MOVWF   OPTION_REG                      ; TMR0:1/256      

        BCF     BANK_1                          ; BANKA 0

        ; --- PWM LED ---

        CALL    _PWM_LED_INIT                   ; PORTY & TMR0 & PULL-UP & INT

        ; --- TMR1 ---

        BSF     BANK_1                          ; BANKA 1

        BSF     PIE1,TMR1IE

        BCF     BANK_1                          ; BANKA 0

        MOVLW   B'00000001'                     ; T1CKPS:1/1, TMR1ZAP:ON
        MOVWF   T1CON

        ; --- APLIKACE ---

        MOVLW   k_PERIODA_EFEKTU                ; NASTAVENI DOBY PERIODY EFEKTU
        MOVWF   r_PERIODA_EFEKTU

        CLRF    r_FLG                           ; VYNULOVANI CITACE PERIOD EFEKTU
        CLRF    r_JAS_EFEKTU                    ; VYNULOVANI JASU

        ; --- PRERUSENI ---

        MOVLW   B'11100000'                     ; GIE:ON, PEIE:ON, TMR0IE:ON, INTE:OFF, RBIE:OFF
        MOVWF   INTCON

;___________________________________________________________________________________________________
;###################################################################################################
;#                                                                                                 #
;#                   #####   #####     ###     ####   #####    #####   ##   ##                     #
;#                   ##  ##  ##  ##  ##   ##  ##      ##  ##  ##   ##  ### ###                     #
;#                   #####   ####    ##   ##  ##      ####    #######  ## # ##                     #
;#                   ##      ## ##   ##   ##  ##  ##  ## ##   ##   ##  ##   ##                     #
;#                   ##      ##  ##    ###     #####  ##  ##  ##   ##  ##   ##                     #
;#_________________________________________________________________________________________________#
;###################################################################################################

_P_R_O_G_R_A_M_:

        BTFSC   k_FLG_STA_EFEKT                 ; ?? DALSI KROK RGB LED EFEKTU ??
        CALL    _EFEKT                          ; 'ANO' 

        GOTO    _P_R_O_G_R_A_M_  

;___________________________________________________________________________________________________
;###################################################################################################
;#                                                                                                 #
;#   #####     ###    #####    #####   #####     ###     ####   #####    #####   ##   ##  ##  ##   #
;#   ##  ##  ##   ##  ##   ##  ##  ##  ##  ##  ##   ##  ##      ##  ##  ##   ##  ### ###  ##  ##   #
;#   #####   ##   ##  ##   ##  #####   ####    ##   ##  ##      ####    #######  ## # ##    ##     #
;#   ##      ##   ##  ##   ##  ##      ## ##   ##   ##  ##  ##  ## ##   ##   ##  ##   ##    ##     #
;#   ##        ###    #####    ##      ##  ##    ###     #####  ##  ##  ##   ##  ##   ##    ##     #
;#_________________________________________________________________________________________________#
;###################################################################################################

;###################################################################################################
; EFEKT PROLINANI BAREV RGB LED DIOD
;---------------------------------------------------------------------------------------------------
_EFEKT:

        BCF     k_FLG_STA_EFEKT                 ; VYP: START KROKU EFEKTU

        BCF     INTCON,GIE                      ; VYP: PRERUSENI

        ; --- JAS PRO VSECHNY RGB LED ---

_EFEKT.Jas:

        BTFSS   k_FLG_SMER                      ; ?? SILICI JAS ??
        INCF    r_JAS_EFEKTU,f                  ; 'ANO'
  
        BTFSC   r_JAS_EFEKTU,6                  ; ?? OBRATIT JAS NA SLABNOUCI ??
        BSF     k_FLG_SMER                      ; 'ANO'
  

        BTFSC   k_FLG_SMER                      ; ?? SLABNOUCI JAS ??
        DECF    r_JAS_EFEKTU,f                  ; 'ANO'

        BTFSC   STATUS,Z                        ; ?? OBRATIT JAS NA SILICI ??
        BCF     k_FLG_SMER                      ; 'ANO'

        ; --- PREDNASTAVENI ZHASNUTI VSECH RGB LED ---

        CLRF    r_LED1_R
        CLRF    r_LED1_G
        CLRF    r_LED1_B

        CLRF    r_LED2_R
        CLRF    r_LED2_G
        CLRF    r_LED2_B

        CLRF    r_LED3_R
        CLRF    r_LED3_G
        CLRF    r_LED3_B

        ; --- PRIMARNI RGB LED BARVY ---

        MOVLW   0x00                            ; INDEX RGB LED 1
        CALL    _PCL_SADA_VARIACI_PRIMARNI      ; PREDVOLBA BARVY RGB LED 1
        MOVWF   FSR                             ; <-'
        MOVF    r_JAS_EFEKTU,w                  ; UROVEN JASU
        MOVWF   INDF                            ; PRIDELENI JASU

        MOVLW   0x01                            ; INDEX RGB LED 2
        CALL    _PCL_SADA_VARIACI_PRIMARNI      ; PREDVOLBA BARVY RGB LED 2
        MOVWF   FSR                             ; <-'
        MOVF    r_JAS_EFEKTU,w                  ; UROVEN JASU
        MOVWF   INDF                            ; PRIDELENI JASU

        MOVLW   0x02                            ; INDEX RGB LED 3
        CALL    _PCL_SADA_VARIACI_PRIMARNI      ; PREDVOLBA BARVY RGB LED 3
        MOVWF   FSR                             ; <-'
        MOVF    r_JAS_EFEKTU,w                  ; UROVEN JASU
        MOVWF   INDF                            ; PRIDELENI JASU

        ; --- SEKUNDARNI RGB LED BARVY S NEGACI JASU A 'OR' PRIDELENIM ---

        MOVLW   0x00                            ; INDEX RGB LED 1
        CALL    _PCL_SADA_VARIACI_SEKUNDARNI    ; PREDVOLBA BARVY RGB LED 1
        MOVWF   FSR                             ; <-'
        MOVF    r_JAS_EFEKTU,w                  ; UROVEN JASU
        XORLW   B'00111111'                     ; NEGACE JASU
        IORWF   INDF                            ; 'OR' PRIDELENI JASU

        MOVLW   0x01                            ; INDEX RGB LED 2
        CALL    _PCL_SADA_VARIACI_SEKUNDARNI    ; PREDVOLBA BARVY RGB LED 2
        MOVWF   FSR                             ; <-'
        MOVF    r_JAS_EFEKTU,w                  ; UROVEN JASU
        XORLW   B'00111111'                     ; NEGACE JASU
        IORWF   INDF                            ; 'OR' PRIDELENI JASU

        MOVLW   0x02                            ; INDEX RGB LED 3
        CALL    _PCL_SADA_VARIACI_SEKUNDARNI    ; PREDVOLBA BARVY RGB LED 3
        MOVWF   FSR                             ; <-'
        MOVF    r_JAS_EFEKTU,w                  ; UROVEN JASU
        XORLW   B'00111111'                     ; NEGACE JASU
        IORWF   INDF                            ; 'OR' PRIDELENI JASU

        ; --- ZMENA PRIDELENI BAREV PRI ZHASNUTI ---

        MOVF    r_JAS_EFEKTU,w
        ANDLW   B'00111111'
        BTFSS   STATUS,Z                        ; ?? ZHASNUTE PRIMARNI BARVY ??
        GOTO    _EFEKT.Sada_II                  ; 'NE'

        ; --- PREPNUTI NA DALSI VARIACI PRIMARNICH BAREV ---

        MOVLW   0x03                            ; OFESET NA DALSI RGB LED
        ADDWF   r_INDEX_VARIACE_PRIMARNI,f

        MOVF    r_INDEX_VARIACE_PRIMARNI,w
        XORLW   k_POCET_KOMBINACI
        BTFSC   STATUS,Z                        ; ?? DOSAZEN STROP PRIMARNICH VARIACI ??
        CLRF    r_INDEX_VARIACE_PRIMARNI        ; 'ANO'  POINTR NA ZPET NA ZACATEK

_EFEKT.Sada_II:
    
        MOVF    r_JAS_EFEKTU,w
        XORLW   B'00111111'
        BTFSS   STATUS,Z                        ; ?? ZHASNUTE SEKUNDARNI BARVY ??
        GOTO    _EFEKT.Konec                    ; 'NE'

        ; --- PREPNUTI NA DALSI VARIACI SEKUNDARNICH BAREV ---

        MOVLW   0x03                            ; OFESET NA DALSI RGB LED
        ADDWF   r_INDEX_VARIACE_SEKUNDARNI,f

        MOVF    r_INDEX_VARIACE_SEKUNDARNI,w
        XORLW   k_POCET_KOMBINACI -3            ; LIMITACE KOMBINACI NA LICHY POCET O 3 MENE 

        BTFSC   STATUS,Z                        ; ?? DOSAZEN STROP SEKUNDARNICH VARIACI ??
        CLRF    r_INDEX_VARIACE_SEKUNDARNI      ; 'ANO'  POINTR ZPET NA ZACATEK

_EFEKT.Konec:

        BSF     INTCON,GIE                      ; ZAP: PRERUSENI

    RETURN

;###################################################################################################
    END

 

RGB-LED-EFEKT-16F73_PWM.asm

#ASM###########################################################################################MCH#
;#                                                                                                 #
;# RGB-LED-EFEKT-16F73_PWM.asm                                                                     #
;# ```````````````````````````                                                                     #
;#  PWM ROZLISENI 6 BIT, 64 PWM DILKU -1. 
;#

; ________
; PROCESOR

    LIST P=16F73

; _______
; SDILENO

    INCLUDE     <P16F73.INC>

    GLOBAL      r_LED1_R, r_LED1_G, r_LED1_B, r_LED2_R, r_LED2_G, r_LED2_B
    GLOBAL      r_LED3_R, r_LED3_G, r_LED3_B, _PWM_LED_INIT, _PWM_LED_MPX

; ________
; REGISTRY

MEM_PWM_LED     UDATA_SHR                       ; V BANCE 0

r_PWM_IX        RES 1                           ; PRO PWM INDEX 0~31

r_LED1_R        RES 1                           ; JAS LED1_R
r_LED1_G        RES 1                           ; JAS LED1_G
r_LED1_B        RES 1                           ; JAS LED1_B

r_LED2_R        RES 1                           ; JAS LED2_R
r_LED2_G        RES 1                           ; JAS LED2_G
r_LED2_B        RES 1                           ; JAS LED2_B

r_LED3_R        RES 1                           ; JAS LED3_R
r_LED3_G        RES 1                           ; JAS LED3_G
r_LED3_B        RES 1                           ; JAS LED3_B

; _________
; KONSTANTY

#DEFINE     w               0                   ; CIL ->(W)
#DEFINE     f               1                   ; CIL ->(REGISTR)
#DEFINE     BANK_1          STATUS,RP0          ; PREPINANI BANK 0<->1

#DEFINE     k_TRIS_LED1_R   TRISC,1
#DEFINE     k_TRIS_LED1_G   TRISC,0
#DEFINE     k_TRIS_LED1_B   TRISC,2

#DEFINE     k_PORT_LED1_R   PORTC,1
#DEFINE     k_PORT_LED1_G   PORTC,0
#DEFINE     k_PORT_LED1_B   PORTC,2

#DEFINE     k_TRIS_LED2_R   TRISC,3
#DEFINE     k_TRIS_LED2_G   TRISC,4
#DEFINE     k_TRIS_LED2_B   TRISC,5

#DEFINE     k_PORT_LED2_R   PORTC,3
#DEFINE     k_PORT_LED2_G   PORTC,4
#DEFINE     k_PORT_LED2_B   PORTC,5

#DEFINE     k_TRIS_LED3_R   TRISA,1
#DEFINE     k_TRIS_LED3_G   TRISA,2
#DEFINE     k_TRIS_LED3_B   TRISA,0

#DEFINE     k_PORT_LED3_R   PORTA,1
#DEFINE     k_PORT_LED3_G   PORTA,2
#DEFINE     k_PORT_LED3_B   PORTA,0

#DEFINE     k_PWM_IX            B'00111111'     ; PWM ROZLISENI -1
#DEFINE     k_PWM_PERIODA       .161            ; PWM PERIODDA PRO 200uS

CODE_PWM        CODE      

;###################################################################################################
; INICIALIZACE PWM LED ZOBRAZENI
;---------------------------------------------------------------------------------------------------
_PWM_LED_INIT:           

        BSF     k_PORT_LED1_R                   ; VYP: LED1_R
        BSF     k_PORT_LED1_G                   ; VYP: LED1_G
        BSF     k_PORT_LED1_B                   ; VYP: LED1_B

        BSF     k_PORT_LED2_R                   ; VYP: LED2_R
        BSF     k_PORT_LED2_G                   ; VYP: LED2_G
        BSF     k_PORT_LED2_B                   ; VYP: LED2_B

        BSF     k_PORT_LED3_R                   ; VYP: LED3_R
        BSF     k_PORT_LED3_G                   ; VYP: LED3_G
        BSF     k_PORT_LED3_B                   ; VYP: LED3_B

        BSF     BANK_1                          ; BANKA 1

        BCF     k_TRIS_LED1_R                   ; OUTPUT PRO LED1_R
        BCF     k_TRIS_LED1_G                   ; OUTPUT PRO LED1_G
        BCF     k_TRIS_LED1_B                   ; OUTPUT PRO LED1_B

        BCF     k_TRIS_LED2_R                   ; OUTPUT PRO LED2_R
        BCF     k_TRIS_LED2_G                   ; OUTPUT PRO LED2_G
        BCF     k_TRIS_LED2_B                   ; OUTPUT PRO LED2_B

        BCF     k_TRIS_LED3_R                   ; OUTPUT PRO LED3_R
        BCF     k_TRIS_LED3_G                   ; OUTPUT PRO LED3_G
        BCF     k_TRIS_LED3_B                   ; OUTPUT PRO LED3_B

        MOVLW   b'00000001'                     ; pull-ups:ON, Interrupt RB0/INT:FALL, 
        MOVWF   OPTION_REG                      ; TMR0 Rate:1/4      

        BCF     BANK_1                          ; BANKA 0
    

  ; --- INICIALIZACE PWM INDEXU ---

        MOVLW   k_PWM_IX
        MOVWF   r_PWM_IX

    RETURN

;###################################################################################################
; ZOBRAZOVANI LED SAD V PWM MULTIPLEXU  (SPOLECNA ADNODA)
;---------------------------------------------------------------------------------------------------
_PWM_LED_MPX:  

        ; --- INICIALIZACE PERIODY TMR0 ---

        MOVLW   k_PWM_PERIODA
        MOVWF   TMR0

        ; --- MPX LED1_... ---

        MOVF    r_PWM_IX,w                      ; INDEX DILKU PWM r_LED1_R
        SUBWF   r_LED1_R,w                      ; JAS
        BTFSC   STATUS,C                        ; ?? AKTIVACE PWM DILKU ??
        BCF     k_PORT_LED1_R                   ; 'ANO'
        BTFSS   STATUS,C                        ; ?? DEAKTIVACE PWM DILKU ??
        BSF     k_PORT_LED1_R                   ; 'ANO'

        MOVF    r_PWM_IX,w                      ; INDEX DILKU PWM r_LED1_G
        SUBWF   r_LED1_G,w                      ; JAS
        BTFSC   STATUS,C                        ; ?? AKTIVACE PWM DILKU ??
        BCF     k_PORT_LED1_G                   ; 'ANO'
        BTFSS   STATUS,C                        ; ?? DEAKTIVACE PWM DILKU ??
        BSF     k_PORT_LED1_G                   ; 'ANO'

        MOVF    r_PWM_IX,w                      ; INDEX DILKU PWM r_LED1_B
        SUBWF   r_LED1_B,w                      ; JAS
        BTFSC   STATUS,C                        ; ?? AKTIVACE PWM DILKU ??
        BCF     k_PORT_LED1_B                   ; 'ANO'
        BTFSS   STATUS,C                        ; ?? DEAKTIVACE PWM DILKU ??
        BSF     k_PORT_LED1_B                   ; 'ANO'

        ; --- MPX LED2_... ---

        MOVF    r_PWM_IX,w                      ; INDEX DILKU PWM r_LED2_R
        SUBWF   r_LED2_R,w                      ; JAS
        BTFSC   STATUS,C                        ; ?? AKTIVACE PWM DILKU ??
        BCF     k_PORT_LED2_R                   ; 'ANO'
        BTFSS   STATUS,C                        ; ?? DEAKTIVACE PWM DILKU ??
        BSF     k_PORT_LED2_R                   ; 'ANO'

        MOVF    r_PWM_IX,w                      ; INDEX DILKU PWM r_LED2_G
        SUBWF   r_LED2_G,w                      ; JAS
        BTFSC   STATUS,C                        ; ?? AKTIVACE PWM DILKU ??
        BCF     k_PORT_LED2_G                   ; 'ANO'
        BTFSS   STATUS,C                        ; ?? DEAKTIVACE PWM DILKU ??
        BSF     k_PORT_LED2_G                   ; 'ANO'

        MOVF    r_PWM_IX,w                      ; INDEX DILKU PWM r_LED2_B
        SUBWF   r_LED2_B,w                      ; JAS
        BTFSC   STATUS,C                        ; ?? AKTIVACE PWM DILKU ??
        BCF     k_PORT_LED2_B                   ; 'ANO'
        BTFSS   STATUS,C                        ; ?? DEAKTIVACE PWM DILKU ??
        BSF     k_PORT_LED2_B                   ; 'ANO'

        ; --- MPX LED3_... ---

        MOVF    r_PWM_IX,w                      ; INDEX DILKU PWM r_LED3_R
        SUBWF   r_LED3_R,w                      ; JAS
        BTFSC   STATUS,C                        ; ?? AKTIVACE PWM DILKU ??
        BCF     k_PORT_LED3_R                   ; 'ANO'
        BTFSS   STATUS,C                        ; ?? DEAKTIVACE PWM DILKU ??
        BSF     k_PORT_LED3_R                   ; 'ANO'

        MOVF    r_PWM_IX,w                      ; INDEX DILKU PWM r_LED3_G
        SUBWF   r_LED3_G,w                      ; JAS
        BTFSC   STATUS,C                        ; ?? AKTIVACE PWM DILKU ??
        BCF     k_PORT_LED3_G                   ; 'ANO'
        BTFSS   STATUS,C                        ; ?? DEAKTIVACE PWM DILKU ??
        BSF     k_PORT_LED3_G                   ; 'ANO'

        MOVF    r_PWM_IX,w                      ; INDEX DILKU PWM r_LED3_B
        SUBWF   r_LED3_B,w                      ; JAS
        BTFSC   STATUS,C                        ; ?? AKTIVACE PWM DILKU ??
        BCF     k_PORT_LED3_B                   ; 'ANO'
        BTFSS   STATUS,C                        ; ?? DEAKTIVACE PWM DILKU ??
        BSF     k_PORT_LED3_B                   ; 'ANO'

        ; --- MPX IX -1 ---

        DECFSZ  r_PWM_IX,f                      ; ?? CELA PWM PERIODA ??
    RETURN                                      ; 'NE'

        ; --- INICIALIZACE PWM INDEXU ---

        MOVLW   k_PWM_IX   
        MOVWF   r_PWM_IX
  
    RETURN

;###################################################################################################
    END

 

P16F73.INC

        LIST
; P16C73.INC  Standard Header File, Version 1.01    Microchip Technology, Inc.
        NOLIST

; This header file defines configurations, registers, and other useful bits of
; information for the PIC16C73 microcontroller.  These names are taken to match 
; the data sheets as closely as possible.  

; Note that the processor must be selected before this file is 
; included.  The processor may be selected the following ways:

;       1. Command line switch:
;               C:\ MPASM MYFILE.ASM /PIC16C73
;       2. LIST directive in the source file
;               LIST   P=PIC16C73
;       3. Processor Type entry in the MPASM full-screen interface

;==========================================================================
;
;       Revision History
;
;==========================================================================

;Rev:   Date:    ReasZAP:

;1.01   05/17/96 Updated BADRAM map
;1.00   10/31/95 Initial Release

;==========================================================================
;
;       Verify Processor
;
;==========================================================================

        IFNDEF __16F73
           MESSG "Processor-header file mismatch.  Verify selected processor."
        ENDIF

;==========================================================================
;
;       Register Definitions
;
;==========================================================================

W                            EQU     H'0000'
F                            EQU     H'0001'

;----- Register Files------------------------------------------------------

INDF                         EQU     H'0000'
TMR0                         EQU     H'0001'
PCL                          EQU     H'0002'
STATUS                       EQU     H'0003'
FSR                          EQU     H'0004'
PORTA                        EQU     H'0005'
PORTB                        EQU     H'0006'
PORTC                        EQU     H'0007'
PCLATH                       EQU     H'000A'
INTCON                       EQU     H'000B'
PIR1                         EQU     H'000C'
PIR2                         EQU     H'000D'
TMR1L                        EQU     H'000E'
TMR1H                        EQU     H'000F'
T1CON                        EQU     H'0010'
TMR2                         EQU     H'0011'
T2CON                        EQU     H'0012'
SSPBUF                       EQU     H'0013'
SSPCON                       EQU     H'0014'
CCPR1L                       EQU     H'0015'
CCPR1H                       EQU     H'0016'
CCP1CON                      EQU     H'0017'
RCSTA                        EQU     H'0018'
TXREG                        EQU     H'0019'
RCREG                        EQU     H'001A'
CCPR2L                       EQU     H'001B'
CCPR2H                       EQU     H'001C'
CCP2CON                      EQU     H'001D'
ADRES                        EQU     H'001E'
ADCON0                       EQU     H'001F'

OPTION_REG                   EQU     H'0081'
TRISA                        EQU     H'0085'
TRISB                        EQU     H'0086'
TRISC                        EQU     H'0087'
PIE1                         EQU     H'008C'
PIE2                         EQU     H'008D'
PCON                         EQU     H'008E'
PR2                          EQU     H'0092'
SSPADD                       EQU     H'0093'
SSPSTAT                      EQU     H'0094'
TXSTA                        EQU     H'0098'
SPBRG                        EQU     H'0099'
ADCON1                       EQU     H'009F'

;----- STATUS Bits --------------------------------------------------------

IRP                          EQU     H'0007'
RP1                          EQU     H'0006'
RP0                          EQU     H'0005'
NOT_TO                       EQU     H'0004'
NOT_PD                       EQU     H'0003'
Z                            EQU     H'0002'
DC                           EQU     H'0001'
C                            EQU     H'0000'

;----- INTCON Bits --------------------------------------------------------

GIE                          EQU     H'0007'
PEIE                         EQU     H'0006'
T0IE                         EQU     H'0005'
INTE                         EQU     H'0004'
RBIE                         EQU     H'0003'
T0IF                         EQU     H'0002'
INTF                         EQU     H'0001'
RBIF                         EQU     H'0000'

;----- PIR1 Bits ----------------------------------------------------------

ADIF                         EQU     H'0006'
RCIF                         EQU     H'0005'
TXIF                         EQU     H'0004'
SSPIF                        EQU     H'0003'
CCP1IF                       EQU     H'0002'
TMR2IF                       EQU     H'0001'
TMR1IF                       EQU     H'0000'

;----- PIR2 Bits ----------------------------------------------------------

CCP2IF                       EQU     H'0000'

;----- T1CON Bits ---------------------------------------------------------

T1CKPS1                      EQU     H'0005'
T1CKPS0                      EQU     H'0004'
T1OSCEN                      EQU     H'0003'
NOT_T1SYNC                   EQU     H'0002'
T1INSYNC                     EQU     H'0002'    ; Backward compatibility only
TMR1CS                       EQU     H'0001'
TMR1ON                       EQU     H'0000'

;----- T2CON Bits ---------------------------------------------------------

TOUTPS3                      EQU     H'0006'
TOUTPS2                      EQU     H'0005'
TOUTPS1                      EQU     H'0004'
TOUTPS0                      EQU     H'0003'
TMR2ON                       EQU     H'0002'
T2CKPS1                      EQU     H'0001'
T2CKPS0                      EQU     H'0000'

;----- SSPCON Bits --------------------------------------------------------

WCOL                         EQU     H'0007'
SSPOV                        EQU     H'0006'
SSPEN                        EQU     H'0005'
CKP                          EQU     H'0004'
SSPM3                        EQU     H'0003'
SSPM2                        EQU     H'0002'
SSPM1                        EQU     H'0001'
SSPM0                        EQU     H'0000'

;----- CCP1CON Bits -------------------------------------------------------

CCP1X                        EQU     H'0005'
CCP1Y                        EQU     H'0004'
CCP1M3                       EQU     H'0003'
CCP1M2                       EQU     H'0002'
CCP1M1                       EQU     H'0001'
CCP1M0                       EQU     H'0000'

;----- RCSTA Bits ---------------------------------------------------------

SPEN                         EQU     H'0007'
RX9                          EQU     H'0006'
RC9                          EQU     H'0006'    ; Backward compatibility only
NOT_RC8                      EQU     H'0006'    ; Backward compatibility only
RC8_9                        EQU     H'0006'    ; Backward compatibility only
SREN                         EQU     H'0005'
CREN                         EQU     H'0004'
FERR                         EQU     H'0002'
OERR                         EQU     H'0001'
RX9D                         EQU     H'0000'
RCD8                         EQU     H'0000'    ; Backward compatibility only

;----- CCP2CON Bits -------------------------------------------------------

CCP2X                        EQU     H'0005'
CCP2Y                        EQU     H'0004'
CCP2M3                       EQU     H'0003'
CCP2M2                       EQU     H'0002'
CCP2M1                       EQU     H'0001'
CCP2M0                       EQU     H'0000'

;----- ADCON0 Bits --------------------------------------------------------

ADCS1                     EQU     H'0007'
ADCS0                     EQU     H'0006'
CHS2                      EQU     H'0005'
CHS1                      EQU     H'0004'
CHS0                      EQU     H'0003'
GO                        EQU     H'0002'
NOT_DONE                  EQU     H'0002'
GO_DONE                   EQU     H'0002'
ADON                      EQU     H'0000'

;----- OPTION Bits --------------------------------------------------------

NOT_RBPU                     EQU     H'0007'
INTEDG                       EQU     H'0006'
T0CS                         EQU     H'0005'
T0SE                         EQU     H'0004'
PSA                          EQU     H'0003'
PS2                          EQU     H'0002'
PS1                          EQU     H'0001'
PS0                          EQU     H'0000'

;----- PIE1 Bits ----------------------------------------------------------

ADIE                         EQU     H'0006'
RCIE                         EQU     H'0005'
TXIE                         EQU     H'0004'
SSPIE                        EQU     H'0003'
CCP1IE                       EQU     H'0002'
TMR2IE                       EQU     H'0001'
TMR1IE                       EQU     H'0000'

;----- PIE2 Bits ----------------------------------------------------------

CCP2IE                       EQU     H'0000'

;----- PCON Bits ----------------------------------------------------------

NOT_POR                      EQU     H'0001'

;----- SSPSTAT Bits -------------------------------------------------------

D                            EQU     H'0005'
I2C_DATA                     EQU     H'0005'
NOT_A                        EQU     H'0005'
NOT_ADDRESS                  EQU     H'0005'
D_A                          EQU     H'0005'
DATA_ADDRESS                 EQU     H'0005'
P                            EQU     H'0004'
I2C_STOP                     EQU     H'0004'
S                            EQU     H'0003'
I2C_START                    EQU     H'0003'
R                            EQU     H'0002'
I2C_READ                     EQU     H'0002'
NOT_W                        EQU     H'0002'
NOT_WRITE                    EQU     H'0002'
R_W                          EQU     H'0002'
READ_WRITE                   EQU     H'0002'
UA                           EQU     H'0001'
BF                           EQU     H'0000'

;----- TXSTA Bits ---------------------------------------------------------

CSRC                         EQU     H'0007'
TX9                          EQU     H'0006'
NOT_TX8                      EQU     H'0006'    ; Backward compatibility only
TX8_9                        EQU     H'0006'    ; Backward compatibility only
TXEN                         EQU     H'0005'
SYNC                         EQU     H'0004'
BRGH                         EQU     H'0002'
TRMT                         EQU     H'0001'
TX9D                         EQU     H'0000'
TXD8                         EQU     H'0000'    ; Backward compatibility only

;----- ADCON1 Bits --------------------------------------------------------

PCFG2                     EQU     H'0002'
PCFG1                     EQU     H'0001'
PCFG0                     EQU     H'0000'

;==========================================================================
;
;       RAM Definition
;
;==========================================================================

        __MAXRAM H'FF'
        __BADRAM H'08'-H'09'
        __BADRAM H'88'-H'89', H'8F'-H'91', H'95'-H'97', H'9A'-H'9E'

;==========================================================================
;
;       Configuration Bits
;
;==========================================================================

_CP_ALL                      EQU     H'3F8F'
_CP_75                       EQU     H'3F9F'
_CP_50                       EQU     H'3FAF'
_CP_OFF                      EQU     H'3FBF'
_PWRTE_ON                    EQU     H'3FBF'
_PWRTE_OFF                   EQU     H'3FB7'
_WDT_ON                      EQU     H'3FBF'
_WDT_OFF                     EQU     H'3FBB'
_LP_OSC                      EQU     H'3FBC'
_XT_OSC                      EQU     H'3FBD'
_HS_OSC                      EQU     H'3FBE'
_RC_OSC                      EQU     H'3FBF'

        LIST