;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
LIST P=12F683 ; list directive to define processor
#INCLUDE <P12F683.INC> ; processor specific variable definitions
;------------------------------------------------------------------------------
; CONFIGURATION WORD SETUP
;------------------------------------------------------------------------------
__CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
RESET_VECTOR CODE 0x0000 ; processor reset vector
GOTO START ; go to beginning of program
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
MAIN_PROG CODE
START
;---------------
;**** Setup ****
;---------------
;***Setup the port***
bsf STATUS,RP0
clrf TRISIO
bcf STATUS,RP0
;***Variable declaration***
RED equ 20h; Red value
GREEN equ 21h; Green value
BLUE equ 22h; Blue Value
RED2 equ 23h; ----------------
GREEN2 equ 24h; Used in workings
BLUE2 equ 25h; ----------------
COUNT equ 26h; Counter for the main loop
;***Variable Initilization***
clrf RED2 ;---------------------------
clrf GREEN2 ;Clear the working registers
clrf BLUE2 ;---------------------------
clrf COUNT ;Clear the main count register
;-------------------
;**** Main Loop ****
;-------------------
MAIN
movlw 64h
movwf COUNT ;Set Count to 100
;***Set RGB values***
movlw 14h ;RED RGB value is 20
movwf RED
movlw 51h ;GREEN RGB value is 81
movwf GREEN
movlw 12h ;BLUE RGB value is 18
movwf BLUE
SUBCALL ;--------------------------------------------------------------Calls SUB 100 times
Call SUB ;Call the RGB subroutine
decfsz COUNT ;See if count is zero, if it is go back to main, if not run SUB again
goto SUBCALL ;---------------------------------------------------------------------
goto MAIN
;------------------
;**** Sub Loop ****
;------------------
SUB
call REDFUNC
call GREENFUNC
call BLUEFUNC
RETURN
;---------------
;*** REDFUNC ***
;---------------
REDFUNC
movfw RED ;move RED into the working register
movwf RED2 ;Copy RED to RED2
incf RED2 ;Increment RED2
decf RED2 ;Decrement RED2
btfss STATUS,Z;If RED=0 then the result of this will be to skip the goto REDN0
goto REDN0 ;If RED > 0
bcf GPIO,GP0;If RED = 0 then turn off the LED
nop ;-------------------------------------------------------------
nop ; Make the RED = 0 brach the same length as the RED > 0 branch
nop ;-------------------------------------------------------------
RETURN ;return to SUB
REDN0
bsf GPIO,GP0;If RED > 0 then turn on the LED
decf RED ; Decrement the RED RGB value
RETURN ;return to SUB
;---------------
;*** GREENFUNC ***
;---------------
GREENFUNC
movfw GREEN ;move GREEN into the working register
movwf GREEN2 ;Copy GREEN to GREEN2
incf GREEN2 ;Increment GREEN2
decf GREEN2 ;Decrement GREEN2
btfss STATUS,Z;If GREEN=0 then the result of this will be to skip the goto GREENN0
goto GREENN0 ;If GREEN > 0
bcf GPIO,GP1;If GREEN = 0 then turn off the LED
nop ;-------------------------------------------------------------
nop ; Make the GREEN = 0 brach the same length as the GREEN > 0 branch
nop ;-------------------------------------------------------------
RETURN ;return to SUB
GREENN0
bsf GPIO,GP1;If GREEN > 0 then turn on the LED
decf GREEN ; Decrement the GREEN RGB value
RETURN ;return to SUB
;---------------
;*** BLUEFUNC ***
;---------------
BLUEFUNC
movfw BLUE ;move BLUE into the working register
movwf BLUE2 ;Copy BLUE to BLUE2
incf BLUE2 ;Increment BLUE2
decf BLUE2 ;Decrement BLUE2
btfss STATUS,Z;If BLUE=0 then the result of this will be to skip the goto BLUEN0
goto BLUEN0 ;If BLUE > 0
bcf GPIO,GP2;If BLUE = 0 then turn off the LED
nop ;-------------------------------------------------------------
nop ; Make the BLUE = 0 brach the same length as the BLUE > 0 branch
nop ;-------------------------------------------------------------
RETURN ;return to SUB
BLUEN0
bsf GPIO,GP2;If BLUE > 0 then turn on the LED
decf BLUE ; Decrement the BLUE RGB value
RETURN ;return to SUB
;****Program END****-----------------------------------------
END ; directive 'end of program'