;**********************************************************************
; Filename: miracle3.asm *
; Date: 2001/7/14 *
; 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
acount1 EQU 0x13 ;LED auto count ram1
acount2 EQU 0x14 ;LED auto count ram2
wait_data EQU 0x15 ;wait data ram
color_count EQU 0x16 ;color count ram
taihi EQU 0x17 ;taihi data
red_count EQU 0x19 ;RED LED count ram
green_count EQU 0x1a ;GREEN LED count ram
blue_count EQU 0x1b ;BLUE LED count ram
int_count1 EQU 0x1c ;int count1
int_count2 EQU 0x1d ;int count2
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
;**********************************************************************
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
;---------------------------------
movlw 01h
addwf int_count1,1
btfsc STATUS,0
incf int_count2,1
;---------------------------------
movlw 01h ;LED mode auto shori
addwf acount1,1
btfsc STATUS,0
incf acount2,1
btfss acount2,3
goto red_leds
call led_change
call led_set
call auto_clear
;----------------------- 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
;----------------------------------
int_end
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 0c0h
movwf PORTB
call timer0_set
movlw 10h
movwf color_count
call auto_clear
movlw 00h
movwf led_data ;RED OFF,GREEN OFF,BLUE OFF
call set_lo_leds
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_sleep
bcf INTCON,GIE
nop
bcf INTCON,T0IE
nop
bcf INTCON,T0IF
nop
bcf INTCON,RBIF
nop
bsf INTCON,RBIE
nop
call icnt_clear
movlw 0c0h
movwf PORTB
nop
sleep
nop
bcf INTCON,RBIE
nop
call icnt_clear
bsf INTCON,GIE
nop
bsf INTCON,T0IE
nop
main_loop
;-------------------------------------- led tentou
movf led_data,0
iorlw 0c0h
movwf PORTB
;--------------------------------------
btfss int_count2,7
goto main_loop
goto main_sleep
;-------------------------------------------------------------------------------
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
;-------------------------------------------------------------------------------
icnt_clear movlw 00h
movwf int_count1
movwf int_count2
return
;------------------------------------------------------------------------------
led_change decf color_count,1
btfsc STATUS,2
goto led_change2
return
led_change2 movlw 10h
movwf color_count
return
;-------------------------------------------------------------------------------
led_set call set_on_red
movwf red_on
call set_off_red
movwf red_off
call set_on_green
movwf green_on
call set_off_green
movwf green_off
call set_on_blue
movwf blue_on
call set_off_blue
movwf blue_off
return
;--------------------------------------------------------------------------------
set_on_red movf color_count,0
movwf taihi
movlw low(red_on_table)
addwf taihi,1
movlw high(red_on_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
red_on_table retlw 70h
retlw 20h
retlw 00h
retlw 20h
retlw 00h
retlw 20h
retlw 00h
retlw 20h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 00h
retlw 70h
retlw 00h
retlw 00h
retlw 70h
set_off_red movf color_count,0
movwf taihi
movlw low(red_off_table)
addwf taihi,1
movlw high(red_off_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
red_off_table retlw 00h
retlw 50h
retlw 70h
retlw 50h
retlw 70h
retlw 50h
retlw 70h
retlw 50h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 70h
retlw 00h
retlw 70h
retlw 70h
retlw 00h
;--------------------------------------------------------------------------------
set_on_green movf color_count,0
movwf taihi
movlw low(green_on_table)
addwf taihi,1
movlw high(green_on_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
green_on_table retlw 70h
retlw 00h
retlw 20h
retlw 20h
retlw 20h
retlw 00h
retlw 70h
retlw 70h
retlw 00h
retlw 20h
retlw 70h
retlw 00h
retlw 70h
retlw 70h
retlw 00h
retlw 70h
retlw 00h
set_off_green movf color_count,0
movwf taihi
movlw low(green_off_table)
addwf taihi,1
movlw high(green_off_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
green_off_table retlw 00h
retlw 70h
retlw 50h
retlw 50h
retlw 50h
retlw 70h
retlw 00h
retlw 00h
retlw 70h
retlw 50h
retlw 00h
retlw 70h
retlw 00h
retlw 00h
retlw 70h
retlw 00h
retlw 70h
;--------------------------------------------------------------------------------
set_on_blue movf color_count,0
movwf taihi
movlw low(blue_on_table)
addwf taihi,1
movlw high(blue_on_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
blue_on_table retlw 70h
retlw 20h
retlw 20h
retlw 00h
retlw 70h
retlw 70h
retlw 20h
retlw 00h
retlw 20h
retlw 00h
retlw 70h
retlw 70h
retlw 70h
retlw 00h
retlw 70h
retlw 00h
retlw 00h
set_off_blue movf color_count,0
movwf taihi
movlw low(blue_off_table)
addwf taihi,1
movlw high(blue_off_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
blue_off_table retlw 00h
retlw 50h
retlw 50h
retlw 70h
retlw 00h
retlw 00h
retlw 50h
retlw 70h
retlw 50h
retlw 70h
retlw 00h
retlw 00h
retlw 00h
retlw 70h
retlw 00h
retlw 70h
retlw 70h
;-------------------------------------------------------------------------------
set_lo_leds movlw 00h
movwf red_on
movwf green_on
movwf blue_on
movlw 70h
movwf red_off
movwf green_off
movwf blue_off
return
;-------------------------------------------------------------------------------
port_set ;RA0,RA1,RA2,RA3,RA4(OUT)
;RB0,RB1,RB2,RB3,RB4,RB5(OUT)
;RB6,RB7(IN)
bsf STATUS,RP0
clrf TRISA
clrf TRISB
bsf TRISB,7
nop
bsf TRISB,6
nop
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
return
END ; directive 'end of program'
|