;**********************************************************************
; Filename: miracle2.asm *
; Date: 2001/4/4 *
; 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
wait_data EQU 0x12 ;wait data ram
auto_count1 EQU 0x13 ;auto count 1 ram
auto_count2 EQU 0x14 ;auto count 2 ram
auto_sub EQU 0x15 ;auto sub ram
auto_sub2 EQU 0x16 ;auto sub 2 ram
red_count EQU 0x19 ;RED LED count ram
green_count EQU 0x1a ;GREE 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
;**********************************************************************
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 auto_sub,1
btfsc STATUS,0
incf auto_sub2
btfss auto_sub2,5
goto red_leds
call led_next
movlw 00h
movwf auto_sub
movwf auto_sub2
;----------------------- 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 01h
movwf auto_count2
movwf auto_count1
movlw 00h
movwf auto_sub
movwf auto_sub2
movlw 00h
movwf led_data ;RED OFF,GREEN OFF,BLUE OFF
call set_0_red
call set_0_green
call set_0_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
;-------------------------------------- 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
;-------------------------------------------------------------------------------
set_0_red movlw 00h
movwf red_on
movlw 70h
movwf red_off
return
set_1_red movlw 10h
movwf red_on
movlw 60h
movwf red_off
return
set_2_red movlw 20h
movwf red_on
movlw 50h
movwf red_off
return
set_3_red movlw 30h
movwf red_on
movlw 40h
movwf red_off
return
set_4_red movlw 40h
movwf red_on
movlw 30h
movwf red_off
return
set_5_red movlw 50h
movwf red_on
movlw 20h
movwf red_off
return
set_6_red movlw 60h
movwf red_on
movlw 10h
movwf red_off
return
set_7_red movlw 70h
movwf red_on
movlw 00h
movwf red_off
return
;-------------------------------------------------------------------------------
set_0_green movlw 00h
movwf green_on
movlw 70h
movwf green_off
return
set_1_green movlw 10h
movwf green_on
movlw 60h
movwf green_off
return
set_2_green movlw 20h
movwf green_on
movlw 50h
movwf green_off
return
set_3_green movlw 30h
movwf green_on
movlw 40h
movwf green_off
return
set_4_green movlw 40h
movwf green_on
movlw 30h
movwf green_off
return
set_5_green movlw 50h
movwf green_on
movlw 20h
movwf green_off
return
set_6_green movlw 60h
movwf green_on
movlw 10h
movwf green_off
return
set_7_green movlw 70h
movwf green_on
movlw 00h
movwf green_off
return
;-------------------------------------------------------------------------------
set_0_blue movlw 00h
movwf blue_on
movlw 70h
movwf blue_off
return
set_1_blue movlw 10h
movwf blue_on
movlw 60h
movwf blue_off
return
set_2_blue movlw 20h
movwf blue_on
movlw 50h
movwf blue_off
return
set_3_blue movlw 30h
movwf blue_on
movlw 40h
movwf blue_off
return
set_4_blue movlw 40h
movwf blue_on
movlw 30h
movwf blue_off
return
set_5_blue movlw 50h
movwf blue_on
movlw 20h
movwf blue_off
return
set_6_blue movlw 60h
movwf blue_on
movlw 10h
movwf blue_off
return
set_7_blue movlw 70h
movwf blue_on
movlw 00h
movwf blue_off
return
;-------------------------------------------------------------------------------
led_next btfss auto_count2,7
goto led_next2
btfss auto_count1,7
goto led_next3
movlw 01h
movwf auto_count2
movwf auto_count1
led_nexte call led_set
return
led_next3 rlf auto_count1,1
bcf auto_count1,0
movlw 01h
movwf auto_count2
goto led_nexte
led_next2 rlf auto_count2,1
bcf auto_count2,0
goto led_nexte
;-------------------------------------------------------------------------------
led_set btfsc auto_count1,0
goto led_set0
btfsc auto_count1,1
goto led_set1
btfsc auto_count1,2
goto led_set2
btfsc auto_count1,3
goto led_set3
btfsc auto_count1,4
goto led_set4
btfsc auto_count1,5
goto led_set5
btfsc auto_count1,6
goto led_set6
btfsc auto_count1,7
goto led_set7
return
led_set0 call led_sub0
return
led_set1 call led_sub1
return
led_set2 call led_sub2
return
led_set3 call led_sub3
return
led_set4 call led_sub4
return
led_set5 call led_sub5
return
led_set6 call led_sub6
return
led_set7 call led_sub7
return
led_sub0 btfsc auto_count2,0
goto led_sub00
btfsc auto_count2,1
goto led_sub01
btfsc auto_count2,2
goto led_sub02
btfsc auto_count2,3
goto led_sub03
btfsc auto_count2,4
goto led_sub04
btfsc auto_count2,5
goto led_sub05
btfsc auto_count2,6
goto led_sub06
btfsc auto_count2,7
goto led_sub07
return
led_sub00 call set_0_red
led_sub00e call set_0_green
call set_0_blue
return
led_sub01 call set_1_red
goto led_sub00e
led_sub02 call set_2_red
goto led_sub00e
led_sub03 call set_3_red
goto led_sub00e
led_sub04 call set_4_red
goto led_sub00e
led_sub05 call set_5_red
goto led_sub00e
led_sub06 call set_6_red
goto led_sub00e
led_sub07 call set_7_red
goto led_sub00e
led_sub1 btfsc auto_count2,0
goto led_sub10
btfsc auto_count2,1
goto led_sub11
btfsc auto_count2,2
goto led_sub12
btfsc auto_count2,3
goto led_sub13
btfsc auto_count2,4
goto led_sub14
btfsc auto_count2,5
goto led_sub15
btfsc auto_count2,6
goto led_sub16
btfsc auto_count2,7
goto led_sub17
return
led_sub10 call set_0_green
led_sub10e call set_7_red
call set_0_blue
return
led_sub11 call set_1_green
goto led_sub10e
led_sub12 call set_2_green
goto led_sub10e
led_sub13 call set_3_green
goto led_sub10e
led_sub14 call set_4_green
goto led_sub10e
led_sub15 call set_5_green
goto led_sub10e
led_sub16 call set_6_green
goto led_sub10e
led_sub17 call set_7_green
goto led_sub10e
led_sub2 btfsc auto_count2,0
goto led_sub20
btfsc auto_count2,1
goto led_sub21
btfsc auto_count2,2
goto led_sub22
btfsc auto_count2,3
goto led_sub23
btfsc auto_count2,4
goto led_sub24
btfsc auto_count2,5
goto led_sub25
btfsc auto_count2,6
goto led_sub26
btfsc auto_count2,7
goto led_sub27
return
led_sub20 call set_7_red
led_sub20e call set_7_green
call set_0_blue
return
led_sub21 call set_6_red
goto led_sub20e
led_sub22 call set_5_red
goto led_sub20e
led_sub23 call set_4_red
goto led_sub20e
led_sub24 call set_3_red
goto led_sub20e
led_sub25 call set_2_red
goto led_sub20e
led_sub26 call set_1_red
goto led_sub20e
led_sub27 call set_0_red
goto led_sub20e
led_sub3 btfsc auto_count2,0
goto led_sub30
btfsc auto_count2,1
goto led_sub31
btfsc auto_count2,2
goto led_sub32
btfsc auto_count2,3
goto led_sub33
btfsc auto_count2,4
goto led_sub34
btfsc auto_count2,5
goto led_sub35
btfsc auto_count2,6
goto led_sub36
btfsc auto_count2,7
goto led_sub37
return
led_sub30 call set_0_blue
led_sub30e call set_7_green
call set_0_red
return
led_sub31 call set_1_blue
goto led_sub30e
led_sub32 call set_2_blue
goto led_sub30e
led_sub33 call set_3_blue
goto led_sub30e
led_sub34 call set_4_blue
goto led_sub30e
led_sub35 call set_5_blue
goto led_sub30e
led_sub36 call set_6_blue
goto led_sub30e
led_sub37 call set_7_blue
goto led_sub30e
led_sub4 btfsc auto_count2,0
goto led_sub40
btfsc auto_count2,1
goto led_sub41
btfsc auto_count2,2
goto led_sub42
btfsc auto_count2,3
goto led_sub43
btfsc auto_count2,4
goto led_sub44
btfsc auto_count2,5
goto led_sub45
btfsc auto_count2,6
goto led_sub46
btfsc auto_count2,7
goto led_sub47
return
led_sub40 call set_7_green
led_sub40e call set_7_blue
call set_0_red
return
led_sub41 call set_6_green
goto led_sub40e
led_sub42 call set_5_green
goto led_sub40e
led_sub43 call set_4_green
goto led_sub40e
led_sub44 call set_3_green
goto led_sub40e
led_sub45 call set_2_green
goto led_sub40e
led_sub46 call set_1_green
goto led_sub40e
led_sub47 call set_0_green
goto led_sub40e
led_sub5 btfsc auto_count2,0
goto led_sub50
btfsc auto_count2,1
goto led_sub51
btfsc auto_count2,2
goto led_sub52
btfsc auto_count2,3
goto led_sub53
btfsc auto_count2,4
goto led_sub54
btfsc auto_count2,5
goto led_sub55
btfsc auto_count2,6
goto led_sub56
btfsc auto_count2,7
goto led_sub57
return
led_sub50 call set_0_red
led_sub50e call set_0_green
call set_7_blue
return
led_sub51 call set_1_red
goto led_sub50e
led_sub52 call set_2_red
goto led_sub50e
led_sub53 call set_3_red
goto led_sub50e
led_sub54 call set_4_red
goto led_sub50e
led_sub55 call set_5_red
goto led_sub50e
led_sub56 call set_6_red
goto led_sub50e
led_sub57 call set_7_red
goto led_sub50e
led_sub6 btfsc auto_count2,0
goto led_sub60
btfsc auto_count2,1
goto led_sub61
btfsc auto_count2,2
goto led_sub62
btfsc auto_count2,3
goto led_sub63
btfsc auto_count2,4
goto led_sub64
btfsc auto_count2,5
goto led_sub65
btfsc auto_count2,6
goto led_sub66
btfsc auto_count2,7
goto led_sub67
return
led_sub60 call set_0_green
led_sub60e call set_7_blue
call set_7_red
return
led_sub61 call set_1_green
goto led_sub60e
led_sub62 call set_2_green
goto led_sub60e
led_sub63 call set_3_green
goto led_sub60e
led_sub64 call set_4_green
goto led_sub60e
led_sub65 call set_5_green
goto led_sub60e
led_sub66 call set_6_green
goto led_sub60e
led_sub67 call set_7_green
goto led_sub60e
led_sub7 btfsc auto_count2,0
goto led_sub70
btfsc auto_count2,1
goto led_sub71
btfsc auto_count2,2
goto led_sub72
btfsc auto_count2,3
goto led_sub73
btfsc auto_count2,4
goto led_sub74
btfsc auto_count2,5
goto led_sub75
btfsc auto_count2,6
goto led_sub76
btfsc auto_count2,7
goto led_sub77
return
led_sub70 call set_7_green
call set_7_blue
call set_7_red
return
led_sub71 call set_6_green
call set_6_blue
call set_6_red
return
led_sub72 call set_5_green
call set_5_blue
call set_5_red
return
led_sub73 call set_4_green
call set_4_blue
call set_4_red
return
led_sub74 call set_3_green
call set_3_blue
call set_3_red
return
led_sub75 call set_2_green
call set_2_blue
call set_2_red
return
led_sub76 call set_1_green
call set_1_blue
call set_1_red
return
led_sub77 call set_0_green
call set_0_blue
call set_0_red
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'
|