;**********************************************************************
; Filename: valtan.asm *
; Date: 2001/8/20 *
; 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
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
push_key EQU 0x1e ;push key
;push_key,0 REC_KEY
;push_key,1 PLAY_KEY
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
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 ;LED mode auto shori
addwf acount1,1
btfsc STATUS,0
incf acount2,1
btfss acount2,0 ;
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 next_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 next_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
;----------------------------------
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 0efh
movwf PORTB
call timer0_set
movlw 1Ch
movwf color_count
call auto_clear
movlw 00h
movwf led_data ;RED OFF,GREEN 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
main_sleep
bcf INTCON,GIE
nop
bcf INTCON,T0IE
nop
bcf INTCON,T0IF
nop
bcf INTCON,RBIF
nop
bsf INTCON,RBIE
nop
movlw 0efh
movwf PORTB
movlw 00h
movwf push_key
nop
sleep
nop
bcf INTCON,RBIE
nop
bsf INTCON,GIE
nop
bsf INTCON,T0IE
nop
;--------------------------------------- REC KEY
main_key1
btfsc PORTB,5
goto main_key2
call wait_1
btfsc PORTB,5
goto main_key2
bsf push_key,0
main_key1p btfss PORTB,5
goto main_key1p
bcf PORTA,1 ;PD L
nop
bcf PORTA,2 ;REC MODE
nop
bcf PORTA,0 ;CE L(REC START)
nop
bsf PORTA,0 ;CE H
goto main_loop
;--------------------------------------- PLAY KEY
main_key2
btfsc PORTB,6
goto main_key3
call wait_1
btfsc PORTB,6
goto main_key3
bsf push_key,1
main_key2p btfss PORTB,6
goto main_key2p
bcf PORTA,1 ;PD L
nop
bsf PORTA,2 ;PLAY MODE
nop
bcf PORTA,0 ;CE L(PLAY START)
nop
bsf PORTA,0 ;CE H
goto main_loop
;---------------------------------------
main_key3
;--------------------------------------
main_loop
btfsc push_key,0
goto blue_led
btfsc push_key,1
goto red_led
;--------------------------------------
goto main_sleep
;--------------------------------------
blue_led
btfss led_data,0
goto blue_led_next
bsf PORTB,4
nop
goto main_next
blue_led_next
btfss led_data,1
goto blue_led_off
bsf PORTB,4
nop
goto main_next
blue_led_off
bcf PORTB,4
nop
goto main_next
;--------------------------------------
red_led
btfss led_data,0
goto red_led_off
bcf PORTB,1
nop
bcf PORTB,3
nop
goto green_led
red_led_off
bsf PORTB,1
nop
bsf PORTB,3
nop
green_led
btfss led_data,1
goto green_led_off
bcf PORTB,0
nop
bcf PORTB,2
nop
goto main_next
green_led_off
bsf PORTB,0
nop
bsf PORTB,2
nop
;---------------------------------------
main_next
;--------------------------------------- REC KEY
main_key4
btfsc PORTB,5
goto main_key5
call wait_1
btfsc PORTB,5
goto main_key5
btfss push_key,0
goto main_key5
bcf push_key,0
main_key4p btfss PORTB,5
goto main_key4p
goto main_nexte1s
;--------------------------------------- PLAY KEY
main_key5
btfsc PORTB,6
goto main_key6
call wait_1
btfsc PORTB,6
goto main_key6
btfss push_key,1
goto main_key6
bcf push_key,1
main_key5p btfss PORTB,6
goto main_key5p
goto main_nexte2s
;---------------------------------------
main_key6
;---------------------------------------
main_nexte
btfsc PORTA,3 ;EOM=L
goto main_loop
;---------------------------------------
main_nexte1
btfss push_key,0
goto main_nexte2
main_nexte1s
bcf PORTA,0 ;CE L(REC STOP)
nop
bsf PORTA,0 ;CE H
nop
bsf PORTA,1 ;PD H
goto main_sleep
;--------------------------------------
main_nexte2
btfss push_key,1
goto main_nexte3
main_nexte2s
bcf PORTA,0 ;CE L(PLAY STOP)
nop
bsf PORTA,0 ;CE H
nop
bsf PORTA,1 ;PD H
goto main_sleep
;--------------------------------------
main_nexte3
goto main_sleep
;-------------------------------------------------------------------------------
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_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
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 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_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 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
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
;--------------------------------------------------------------------------------
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 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_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 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
retlw 00h
retlw 10h
retlw 20h
retlw 30h
retlw 40h
retlw 50h
retlw 60h
;-------------------------------------------------------------------------------
set_lo_leds movlw 00h
movwf red_on
movwf green_on
movlw 70h
movwf red_off
movwf green_off
return
;-------------------------------------------------------------------------------
port_set ;RA0,RA1,RA2,RA4(OUT)
;RA3(IN)
;RB0,RB1,RB2,RB3,RB4(OUT)
;RB5,RB6,RB7(IN)
bsf STATUS,RP0
clrf TRISA
bsf TRISA,3
nop
clrf TRISB
bsf TRISB,7
nop
bsf TRISB,6
nop
bsf TRISB,5
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'
|