;**********************************************************************
; Filename: miracle.asm *
; Date: 2001/3/26 *
; File Version: *
;**********************************************************************
list p=16F84 ; list directive to define processor
#include <p16F84.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
;***** VARIABLE DEFINITIONS
w_temp EQU 0x0C ; variable used for context saving
status_temp EQU 0x0D ; variable used for context saving
led_data EQU 0x11 ;LED set data
;led_data,0 RED LED
;led_data,1 GREEN LED
;led_data,2 BLUE LED
led_mode EQU 0x12 ;LED mode ram
;led_mode,0 manual/auto select
acount1 EQU 0x13 ;LED auto count ram1
acount2 EQU 0x14 ;LED auto count ram2
wait_data EQU 0x15 ;wait data ram
key_count EQU 0x16 ;key count ram
key_sub EQU 0x17 ;key count sub ram
auto_sub EQU 0x18 ;auto sub ram
red_count EQU 0x19 ;RED LED count ram
green_count EQU 0x1a ;GREEN LED count ram
blue_count EQU 0x1b ;BLUE LED count ram
red_on EQU 0x20 ;RED LED ON data ram
red_off EQU 0x21 ;RED LED OFF data ram
green_on EQU 0x22 ;GREEN LED ON data ram
green_off EQU 0x23 ;GREEN LED OFF data ram
blue_on EQU 0x24 ;BLUE LED ON data ram
blue_off EQU 0x25 ;BLUE LED OFF data ram
tm0_setdata EQU 0f3h ;FFH-F3H=12 12*16=192usec
time0 EQU 00h ;LED time0
time1 EQU 70h ;LED time1
time2 EQU 20h ;LED time2
time3 EQU 50h ;LED time3
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
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
movlw tm0_setdata
movwf TMR0
btfss led_mode,0
goto red_leds
;---------------------------------
movlw 01h ;LED mode auto shori
addwf acount1,1
btfsc STATUS,0
incf acount2
btfsc auto_sub,0
goto auto4
btfsc auto_sub,1
goto auto5
btfsc auto_sub,2
goto auto6
goto auto7
auto4 btfss acount2,3
goto red_leds
goto autoe
auto5 btfss acount2,4
goto red_leds
goto autoe
auto6 btfss acount2,5
goto red_leds
goto autoe
auto7 btfss acount2,6
goto red_leds
autoe call led_change
call led_set
movlw 00h ;LED auto count clear
movwf acount1
movwf acount2
;----------------------- RED
red_leds decfsz red_count,1
goto green_leds
btfsc led_data,0 ;RED OFF?
goto red_leds_2
red_leds_3 bsf led_data,0 ;RED ON
movf red_on,0
movwf red_count
movf red_count,0
btfsc STATUS,2
goto red_leds_2
goto green_leds
red_leds_2 bcf led_data,0 ;RED OFF
movf red_off,0
movwf red_count
movf red_count,0
btfsc STATUS,2
goto red_leds_3
;----------------------- GREEN
green_leds decfsz green_count,1
goto blue_leds
btfsc led_data,1 ;GREEN OFF?
goto green_leds_2
green_leds_3 bsf led_data,1 ;GREEN ON
movf green_on,0
movwf green_count
movf green_count,0
btfsc STATUS,2
goto green_leds_2
goto blue_leds
green_leds_2 bcf led_data,1 ;GREEN OFF
movf green_off,0
movwf green_count
movf green_count,0
btfsc STATUS,2
goto green_leds_3
;---------------------- BLUE
blue_leds decfsz blue_count,1
goto next_leds
btfsc led_data,2 ;BLUE OFF?
goto blue_leds_2
blue_leds_3 bsf led_data,2 ;BLUE ON
movf blue_on,0
movwf blue_count
movf blue_count,0
btfsc STATUS,2
goto blue_leds_2
goto next_leds
blue_leds_2 bcf led_data,2 ;BLUE OFF
movf blue_off,0
movwf blue_count
movf blue_count,0
btfsc STATUS,2
goto blue_leds_3
;----------------------------------
next_leds
;----------------------------------
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
main
call port_set
movlw 0ffh
movwf PORTA
movlw 00h
movwf PORTB
call timer0_set
movlw 00h
movwf key_count
movwf key_sub
movwf led_mode ;LED mode=manual
call auto_clear
movlw 04h
movwf auto_sub ;auto time = 3sec
movlw 00h
movwf led_data ;RED OFF,GREEN OFF,BLUE OFF
call set_lo_red
call set_lo_green
call set_lo_blue
movf red_on,0
movwf red_count ;RED count data set
movf green_on,0
movwf green_count ;GREEN count data set
movf blue_on,0
movwf blue_count ;BLUE count data set
main_loop
;-------------------------------------- key scan
sw1_key btfsc PORTA,3
goto sw2_key
call wait_1
btfsc PORTA,3
goto sw2_key
;sw1 on
btfsc led_mode,0
call auto_time
bcf INTCON,GIE
call led_change
call led_set
bsf INTCON,GIE
sw1_end movf led_data,0
movwf PORTB
btfss PORTA,3
goto sw1_end
;-------------------------------------
sw2_key btfsc PORTA,4
goto next_key
call wait_1
btfsc PORTA,4
goto next_key
;sw2 on
btfsc led_mode,0
goto sw2_key2
bsf led_mode,0 ;LED mode=auto
call auto_clear
goto sw2_key3
sw2_key2 bcf led_mode,0 ;LED mode=manual
sw2_key3 btfss PORTA,4
goto sw2_key3
;--------------------------------------
next_key
;-------------------------------------- led tentou
movf led_data,0
movwf PORTB
goto main_loop
;-------------------------------------------------------------------------------
wait_1
movlw 0ffh
movwf wait_data
wait_2
decfsz wait_data,1
goto wait_2
return
;-------------------------------------------------------------------------------
auto_clear movlw 00h
movwf acount1 ;LED auto count clear
movwf acount2
return
;-------------------------------------------------------------------------------
auto_time btfss auto_sub,3
goto auto_time2
movlw 01h
movwf auto_sub
return
auto_time2 rlf auto_sub,1
bcf auto_sub,0
return
;-------------------------------------------------------------------------------
led_change movf key_count,0
btfsc STATUS,2
goto led_change1
btfss key_count,7
goto led_change2
incf key_sub,1
led_change1 movlw 01h
movwf key_count
return
led_change2 rlf key_count,1
bcf key_count,0
return
;-------------------------------------------------------------------------------
led_set btfsc key_count,0
goto miracle0
btfsc key_count,1
goto miracle1
btfsc key_count,2
goto miracle2
btfsc key_count,3
goto miracle3
btfsc key_count,4
goto miracle4
btfsc key_count,5
goto miracle5
btfsc key_count,6
goto miracle6
btfsc key_count,7
goto miracle7
return
miracle0 btfsc key_sub,0
goto miracle10
call set_hi_red
call set_lo_green
call set_lo_blue
return
miracle1 btfsc key_sub,0
goto miracle11
call set_lo_red
call set_hi_green
call set_lo_blue
return
miracle2 btfsc key_sub,0
goto miracle12
call set_lo_red
call set_lo_green
call set_hi_blue
return
miracle3 btfsc key_sub,0
goto miracle13
call set_hi_red
call set_hi_green
call set_lo_blue
return
miracle4 btfsc key_sub,0
goto miracle14
call set_lo_red
call set_hi_green
call set_hi_blue
return
miracle5 btfsc key_sub,0
goto miracle15
call set_hi_red
call set_lo_green
call set_hi_blue
return
miracle6 btfsc key_sub,0
goto miracle16
call set_hi_red
call set_hi_green
call set_hi_blue
return
miracle7 btfsc key_sub,0
goto miracle17
call set_hi_red
call set_mid_green
call set_lo_blue
return
miracle10 call set_hi_red
call set_lo_green
call set_mid_blue
return
miracle11 call set_mid_red
call set_hi_green
call set_lo_blue
return
miracle12 call set_lo_red
call set_hi_green
call set_mid_blue
return
miracle13 call set_mid_red
call set_lo_green
call set_hi_blue
return
miracle14 call set_lo_red
call set_mid_green
call set_hi_blue
return
miracle15 call set_mid_red
call set_mid_green
call set_lo_blue
return
miracle16 call set_lo_red
call set_mid_green
call set_mid_blue
return
miracle17 call set_mid_red
call set_lo_green
call set_mid_blue
return
;-------------------------------------------------------------------------------
set_hi_red movlw time1
movwf red_on
movlw time0
movwf red_off
return
set_mid_red movlw time2
movwf red_on
movlw time3
movwf red_off
return
set_lo_red movlw time0
movwf red_on
movlw time1
movwf red_off
return
;-------------------------------------------------------------------------------
set_hi_green movlw time1
movwf green_on
movlw time0
movwf green_off
return
set_mid_green movlw time2
movwf green_on
movlw time3
movwf green_off
return
set_lo_green movlw time0
movwf green_on
movlw time1
movwf green_off
return
;-------------------------------------------------------------------------------
set_hi_blue movlw time1
movwf blue_on
movlw time0
movwf blue_off
return
set_mid_blue movlw time2
movwf blue_on
movlw time3
movwf blue_off
return
set_lo_blue movlw time0
movwf blue_on
movlw time1
movwf blue_off
return
;-------------------------------------------------------------------------------
port_set ;RA0,RA1,RA2(OUT)
;RA3,RA4(IN)
;RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7(OUT)
bsf STATUS,RP0
clrf TRISA
bsf TRISA,3
nop
bsf TRISA,4
clrf TRISB
bcf STATUS,RP0
return
timer0_set
bsf STATUS,RP0
movlw 083h ;(1)PORTB NOT PULLUP
;(0)INTEDG
;(0)TOCS
;(0)TOSE
;(0)PSA
;(011)1/16
movwf OPTION_REG
bcf STATUS,RP0
movlw tm0_setdata
movwf TMR0
bsf INTCON,T0IE
bsf INTCON,GIE
return
END ; directive 'end of program'
|