***********************************
org 0x0000
goto INIT
NOP
NOP
NOP
org 0x0004
GOTO ISR
org 0x0005
INIT
BSF STATUS,RP0 ;selects memory Bank 1
MOVLW b'01000001'
MOVWF OSCCON ;sets oscillator to 1MHz
MOVLW b'00000000'
MOVWF OPTION_REG ;enables Timer0, 1:4 PS (1.024ms/overflow)
MOVLW b'10100000'
MOVWF INTCON ;enable GIE, Timer0 interrupt
MOVLW b'00000111'
MOVWF CMCON0 ;disables comparator
BCF STATUS,RP0 ;selects memory Bank 0
CLRF GPIO
BSF STATUS,RP0 ;Bank 1 selected
MOVLW b'00011000' ;GP0,1,2,5 as outputs, GP3,4 as inputs.
MOVWF TRISIO ;GP3,5 are for future add-ons.
MOVLW b'00010000' ;GP4 analog input enable, FOSC/2
MOVWF ANSEL
MOVLW b'10001101' ;right justify, VDD ref, AN0, ADON
MOVWF ADCON0
BCF STATUS,RP0 ;Bank 0 selected
MOVLW h'0009'
MOVWF Delay
START
CLRF TMR0
; BSF ADCON0,ADON
; BSF ADCON0,GO ;get A/D data for "Delay" variable
; BTFSC ADCON0,GO
; GOTO $-1
; MOVF ADRESL,W
; MOVWF Delay
; BCF ADCON0,ADON ;disables A/D till next use.
;==================RED=========================
RedON
BCF Done,h'0000'
MOVLW red
MOVWF GPIO ;turns red LED on.
BTFSC Done,h'0000' ;tests for decrementing complete
GOTO WhtON ;executed when complete
GOTO $-2 ;executed when not complete
;==================WHITE========================
WhtON
BCF Done,h'0000'
MOVLW wht
MOVWF GPIO ;turns white LED on.
BTFSC Done,h'0000'
GOTO BlueON
GOTO $-2
;==================BLUE=========================
BlueON
BCF Done,h'0000'
MOVLW blue
MOVWF GPIO ;turns blue LED on.
BTFSC Done,h'0000'
GOTO START
GOTO $-2
;*********************ISR************************
ISR
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
BCF INTCON,T0IF
DECFSZ Delay,F
GOTO CONTEXT ;If not done decrementing, returns to current loop
MOVLW h'0001'
MOVWF Done ;done decrementing, places h'1' in "Done" register
GOTO CONTEXT
CONTEXT
movf status_temp,w ;retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
END