;**********************************************************************
; Filename: shitudo.asm *
; Date: 2001/2/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
wait_data EQU 0x10 ;wait data
shitu1_data EQU 0x11 ;shitudo(1) LED data ram
shitu2_data EQU 0x12 ;shitudo(10) LED data ram
adin_data EQU 0x14 ;ad input data ram
count_data EQU 0x15 ;0.5sec keisoku count ram
adsub_data EQU 0x16 ;ad keisanyou ram
sub2_data EQU 0x17 ;sub(1) data ram
sub3_data EQU 0x18 ;sub(10) data ram
tm0_setdata EQU 63h ;255-156=99=63H 156*128=19.968msec
cnt_setdata EQU 19h ;19.968*25=0.4992sec
data10 EQU 14h ;henkanyou data 1
data1 EQU 2h ;henkanyou data 2
;**********************************************************************
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
decfsz count_data,1
goto next_int
time_up movlw cnt_setdata
movwf count_data
;-------------------------------- data henkan
movf adin_data,0
movwf adsub_data
movlw 00h
movwf sub2_data
movwf sub3_data
next10
movlw data10
subwf adsub_data,0
btfsc STATUS,0
goto next20
goto next21
next20
movwf adsub_data
incf sub3_data,1
goto next10
next21
movlw data1
subwf adsub_data,0
btfsc STATUS,0
goto next30
goto next31
next30
movwf adsub_data
incf sub2_data,1
goto next21
next31
movf sub2_data,0
movwf shitu1_data
movf sub3_data,0
movwf shitu2_data
;---------------------------------
next_int
;----------------------------------
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 porta_set_out
call portb_set_out
movlw 0ffh ;port initial set
movwf PORTA
movlw 00h
movwf PORTB
movlw 00h
movwf shitu1_data
movwf shitu2_data
movwf adin_data
call timer0_set
movlw cnt_setdata
movwf count_data
main_loop
;--------------------------------------- led7_disp
bcf INTCON,GIE
call portb_set_out
bsf INTCON,GIE
movf shitu1_data,0
movwf PORTB
bcf PORTA,0
call wait_1
bsf PORTA,0
movf shitu2_data,0
movwf PORTB
bcf PORTA,1
call wait_1
bsf PORTA,1
;--------------------------------------- ad input
bcf INTCON,GIE
call portb_set_in
bcf PORTA,3
nop
nop
nop
bcf PORTA,4
nop
nop
nop
bsf PORTA,4
nop
nop
nop
movf PORTB,0
movwf adin_data
nop
nop
bsf PORTA,3
bsf INTCON,GIE
;---------------------------------------
main_next
goto main_loop
;-------------------------------------------------------------------------------
wait_1
movlw 0ffh
movwf wait_data
wait_2
decfsz wait_data,1
goto wait_2
return
;-------------------------------------------------------------------------------
porta_set_out ;RA0,RA1,RA2,RA3,RA4(OUT)
bsf STATUS,RP0
clrf TRISA
bcf STATUS,RP0
return
;-------------------------------------------------------------------------------
portb_set_out ;RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7(OUT)
bsf STATUS,RP0
clrf TRISB
bcf STATUS,RP0
return
;-------------------------------------------------------------------------------
portb_set_in ;RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7(IN)
bsf STATUS,RP0
clrf TRISB
comf TRISB,1
bcf STATUS,RP0
return
;-------------------------------------------------------------------------------
timer0_set
bsf STATUS,RP0
movlw 086h ;(1)PORTB NOT PULLUP
;(0)INTEDG
;(0)TOCS
;(0)TOSE
;(0)PSA
;(110)1/128
movwf OPTION_REG
bcf STATUS,RP0
movlw tm0_setdata
movwf TMR0
bsf INTCON,T0IE
bsf INTCON,GIE
return
;-----------------------------------------------------------------------------
END ; directive 'end of program'
|