;**********************************************************************
; Filename: v32.asm *
; Date: 2001/10/7 *
; File Version: *
;**********************************************************************
list p=16F84 ; list directive to define processor
#include <p16F84.inc> ; processor specific variable definitions
LIST
; P16F84.INC Standard Header File, Version 2.00 Microchip Technology, Inc.
LIST
__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 RED1 LED
;led_data,1 GREEN1 LED
;led_data,2 RED2 LED
;led_data,3 GREEN2 LED
;led_data,4 DOUBLE RED1
;led_data,5 DOUBLE RED2
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
wait_data2 EQU 0x18 ;wait data2 ram
red1_count EQU 0x19 ;RED1 LED count ram
green1_count EQU 0x1a ;GREEN1 LED count ram
red2_count EQU 0x1b ;RED2 LED count ram
green2_count EQU 0x1c ;GREEN2 LED count ram
dred1_count EQU 0x1d ;DOUBLE RED1 count ram
dred2_count EQU 0x1e ;DOUBLE RED2 count ram
red1_on EQU 0x20 ;RED1 LED ON data ram
red1_off EQU 0x21 ;RED1 LED OFF data ram
green1_on EQU 0x22 ;GREEN1 LED ON data ram
green1_off EQU 0x23 ;GREEN1 LED OFF data ram
red2_on EQU 0x24 ;RED2 LED ON data ram
red2_off EQU 0x25 ;RED2 LED OFF data ram
green2_on EQU 0x26 ;GREEN2 LED ON data ram
green2_off EQU 0x27 ;GREEN2 LED OFF data ram
dred1_on EQU 0x28 ;DOUBLE RED1 ON data ram
dred1_off EQU 0x29 ;DOUBLE RED1 OFF data ram
dred2_on EQU 0x2a ;DOUBLE RED2 ON data ram
dred2_off EQU 0x2b ;DOUBLE RED2 OFF data ram
int_count1 EQU 0x2d ;int count1
int_count2 EQU 0x2e ;int count2
int_count3 EQU 0x2f ;int count3
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
btfss STATUS,0
goto int_next2
movlw 01h
addwf int_count2,1
btfsc STATUS,0
incf int_count3,1
;---------------------------------
int_next2
movlw 01h ;LED mode auto shori
addwf acount1,1
btfsc STATUS,0
incf acount2,1
btfss acount2,0 ;
goto red1_leds
call led_change
call led_set
call auto_clear
;----------------------- RED1
red1_leds decfsz red1_count,1
goto green1_leds
btfsc led_data,0 ;RED1 OFF?
goto red1_leds_2
red1_leds_3 bsf led_data,0 ;RED1 ON
movf red1_on,0
movwf red1_count
movf red1_count,0
btfsc STATUS,2
goto red1_leds_2
goto green1_leds
red1_leds_2 bcf led_data,0 ;RED1 OFF
movf red1_off,0
movwf red1_count
movf red1_count,0
btfsc STATUS,2
goto red1_leds_3
;----------------------- GREEN1
green1_leds decfsz green1_count,1
goto next_leds
btfsc led_data,1 ;GREEN1 OFF?
goto green1_leds_2
green1_leds_3 bsf led_data,1 ;GREEN1 ON
movf green1_on,0
movwf green1_count
movf green1_count,0
btfsc STATUS,2
goto green1_leds_2
goto next_leds
green1_leds_2 bcf led_data,1 ;GREEN1 OFF
movf green1_off,0
movwf green1_count
movf green1_count,0
btfsc STATUS,2
goto green1_leds_3
;----------------------------------
next_leds
;----------------------- RED2
red2_leds decfsz red2_count,1
goto green2_leds
btfsc led_data,2 ;RED2 OFF?
goto red2_leds_2
red2_leds_3 bsf led_data,2 ;RED2 ON
movf red2_on,0
movwf red2_count
movf red2_count,0
btfsc STATUS,2
goto red2_leds_2
goto green2_leds
red2_leds_2 bcf led_data,2 ;RED2 OFF
movf red2_off,0
movwf red2_count
movf red2_count,0
btfsc STATUS,2
goto red2_leds_3
;----------------------- GREEN2
green2_leds decfsz green2_count,1
goto next_leds_2
btfsc led_data,3 ;GREEN2 OFF?
goto green2_leds_2
green2_leds_3 bsf led_data,3 ;GREEN2 ON
movf green2_on,0
movwf green2_count
movf green2_count,0
btfsc STATUS,2
goto green2_leds_2
goto next_leds_2
green2_leds_2 bcf led_data,3 ;GREEN2 OFF
movf green2_off,0
movwf green2_count
movf green2_count,0
btfsc STATUS,2
goto green2_leds_3
;----------------------------------
next_leds_2
;----------------------- DOUBLE RED1
dred1_leds decfsz dred1_count,1
goto dred2_leds
btfsc led_data,4 ;DRED1 OFF?
goto dred1_leds_2
dred1_leds_3 bsf led_data,4 ;DRED1 ON
movf dred1_on,0
movwf dred1_count
movf dred1_count,0
btfsc STATUS,2
goto dred1_leds_2
goto dred2_leds
dred1_leds_2 bcf led_data,4 ;DRED1 OFF
movf dred1_off,0
movwf dred1_count
movf dred1_count,0
btfsc STATUS,2
goto dred1_leds_3
;----------------------- DOUBLE RED2
dred2_leds decfsz dred2_count,1
goto next_leds_3
btfsc led_data,5 ;DRED1 OFF?
goto dred2_leds_2
dred2_leds_3 bsf led_data,5 ;DRED1 ON
movf dred2_on,0
movwf dred2_count
movf dred2_count,0
btfsc STATUS,2
goto dred2_leds_2
goto next_leds_3
dred2_leds_2 bcf led_data,5 ;DRED1 OFF
movf dred2_off,0
movwf dred2_count
movf dred2_count,0
btfsc STATUS,2
goto dred2_leds_3
;----------------------------------
next_leds_3
;----------------------------------
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 00h
movwf PORTA
movlw 0cfh
movwf PORTB
call timer0_set
movlw 1Ch
movwf color_count
call auto_clear
movlw 00h
movwf led_data ;LED ALL OFF
call set_lo_leds
movf red1_on,0
movwf red1_count ;RED1 count data set
movf green1_on,0
movwf green1_count ;GREEN1 count data set
movf red2_on,0
movwf red2_count ;RED2 count data set
movf green2_on,0
movwf green2_count ;GREEN2 count data set
movf dred1_on,0
movwf dred1_count ;DOUBLE RED1 count data set
movf dred2_on,0
movwf dred2_count ;DOUBLE RED2 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 0cfh
movwf PORTB
nop
sleep
nop
bcf INTCON,RBIE
nop
bsf INTCON,GIE
nop
bsf INTCON,T0IE
nop
call out1_out
;--------------------------------------
main_loop
btfsc int_count3,1
goto main_sleep2
;--------------------------------------
red1_led
btfss led_data,0
goto red1_led_off
bcf PORTB,1
nop
goto green1_led
red1_led_off
bsf PORTB,1
nop
green1_led
btfss led_data,1
goto green1_led_off
bcf PORTB,0
nop
goto main_next
green1_led_off
bsf PORTB,0
nop
;---------------------------------------
main_next
;---------------------------------------
red2_led
btfss led_data,2
goto red2_led_off
bcf PORTB,3
nop
goto green2_led
red2_led_off
bsf PORTB,3
nop
green2_led
btfss led_data,3
goto green2_led_off
bcf PORTB,2
nop
goto main_next_2
green2_led_off
bsf PORTB,2
nop
;--------------------------------------
main_next_2
;--------------------------------------
dred1_led
btfss led_data,4
goto dred1_led_off
bsf PORTB,4
nop
goto dred2_led
dred1_led_off
bcf PORTB,4
nop
dred2_led
btfss led_data,5
goto dred2_led_off
bsf PORTB,5
nop
goto main_next_3
dred2_led_off
bcf PORTB,5
nop
;--------------------------------------
main_next_3
goto main_loop
;--------------------------------------
main_sleep2
call out2_out
goto main_sleep
;-------------------------------------------------------------------------------
out1_out
bsf PORTA,0
nop
call wait_1
call wait_1
call wait_1
bcf PORTA,0
nop
return
out2_out
bsf PORTA,1
nop
call wait_1
call wait_1
call wait_1
bcf PORTA,1
nop
return
;-------------------------------------------------------------------------------
wait_1
movlw 0ffh
movwf wait_data
wait_2
nop
decfsz wait_data,1
goto wait_2
return
;-------------------------------------------------------------------------------
auto_clear movlw 00h
movwf acount1 ;LED auto count clear
movwf acount2
return
;-------------------------------------------------------------------------------
led_change decf color_count,1
btfsc STATUS,2
goto led_change2
return
led_change2 movlw 1Ch
movwf color_count
return
;-------------------------------------------------------------------------------
led_set call set_on_red1
movwf red1_on
sublw 70h
movwf red1_off
call set_on_green1
movwf green1_on
sublw 70h
movwf green1_off
call set_on_red2
movwf red2_on
sublw 70h
movwf red2_off
call set_on_green2
movwf green2_on
sublw 70h
movwf green2_off
call set_on_dred1
movwf dred1_on
sublw 70h
movwf dred1_off
call set_on_dred2
movwf dred2_on
sublw 70h
movwf dred2_off
return
;--------------------------------------------------------------------------------
icnt_clear movlw 00h
movwf int_count1
movwf int_count2
movwf int_count3
return
;--------------------------------------------------------------------------------
set_on_red1 movf color_count,0
movwf taihi
movlw low(red1_on_table)
addwf taihi,1
movlw high(red1_on_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
red1_on_table retlw 70h
retlw 00h
retlw 10h
retlw 20h
retlw 30h
retlw 40h
retlw 50h
retlw 60h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 60h
retlw 50h
retlw 40h
retlw 30h
retlw 20h
retlw 10h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
;--------------------------------------------------------------------------------
set_on_green1 movf color_count,0
movwf taihi
movlw low(green1_on_table)
addwf taihi,1
movlw high(green1_on_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
green1_on_table retlw 70h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 10h
retlw 20h
retlw 30h
retlw 40h
retlw 50h
retlw 60h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 60h
retlw 50h
retlw 40h
retlw 30h
retlw 20h
retlw 10h
;-------------------------------------------------------------------------------
set_on_red2 movf color_count,0
movwf taihi
movlw low(red2_on_table)
addwf taihi,1
movlw high(red2_on_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
red2_on_table retlw 70h
retlw 10h
retlw 30h
retlw 50h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 60h
retlw 40h
retlw 20h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 10h
retlw 30h
retlw 50h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 60h
retlw 40h
retlw 20h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
;--------------------------------------------------------------------------------
set_on_green2 movf color_count,0
movwf taihi
movlw low(green2_on_table)
addwf taihi,1
movlw high(green2_on_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
green2_on_table retlw 70h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 20h
retlw 40h
retlw 60h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 50h
retlw 30h
retlw 10h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 20h
retlw 40h
retlw 60h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 50h
retlw 30h
retlw 10h
;-------------------------------------------------------------------------------
set_on_dred1 movf color_count,0
movwf taihi
movlw low(dred1_on_table)
addwf taihi,1
movlw high(dred1_on_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
dred1_on_table retlw 70h
retlw 10h
retlw 30h
retlw 50h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 60h
retlw 40h
retlw 20h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 10h
retlw 30h
retlw 50h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 60h
retlw 40h
retlw 20h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
;--------------------------------------------------------------------------------
set_on_dred2 movf color_count,0
movwf taihi
movlw low(dred2_on_table)
addwf taihi,1
movlw high(dred2_on_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
dred2_on_table retlw 70h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 20h
retlw 40h
retlw 60h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 50h
retlw 30h
retlw 10h
retlw 00h
retlw 00h
retlw 00h
retlw 00h
retlw 20h
retlw 40h
retlw 60h
retlw 70h
retlw 70h
retlw 70h
retlw 70h
retlw 50h
retlw 30h
retlw 10h
;-------------------------------------------------------------------------------
set_lo_leds movlw 00h
movwf red1_on
movwf green1_on
movwf red2_on
movwf green2_on
movwf dred1_on
movwf dred2_on
movlw 70h
movwf red1_off
movwf green1_off
movwf red2_off
movwf green2_off
movwf dred1_off
movwf dred2_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'
|