PIC16F84電子遊戯(67)サブページ
最終更新日:2002年3月23日
サーミスター温度計 (1ページ)へ (2ページ)へ (3ページ)へ

サーミスター温度計の全ソースリスト
;**********************************************************************
;    Filename:	    newondo2.asm                                           *
;    Date:          2002/2/19                                         *
;    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	0x15		;wait data ram
d_offset	EQU	0x16		;suji data offset
taihi		EQU	0x17		;taihi data
out_data	EQU	0x18		;out data
fugo		EQU	0x19		;+/- fugo
suji_1		EQU	0x1a		;10do suji
suji_2		EQU	0x1b		;1do suji
taihi2		EQU	0x1c		;taihi2 data
d_count		EQU	0x1d		;hyouji count data
count		EQU	0x1e		;warikomi count data

line10		EQU	0x20		;line10 disp data
line11		EQU	0x21		;line11	disp data
line12		EQU	0x22		;line12 disp data
line13		EQU	0x23		;line13 disp data
line14		EQU	0x24		;line14 disp data
line15		EQU	0x25		;line15 disp data
line20		EQU	0x26		;line20 disp data
line21		EQU	0x27		;line21 disp data
line22		EQU	0x28		;line22 disp data
line23		EQU	0x29		;line23 disp data
line24		EQU	0x2a		;line24 disp data
line25		EQU	0x2b		;line25 disp data
line26		EQU	0x2c		;line26 disp data
line27		EQU	0x2d		;line27 disp data
line28		EQU	0x2e		;line28 disp data
line29		EQU	0x2f		;line29 disp data
line30		EQU	0x30		;line30 disp data
line31		EQU	0x31		;line31 disp data
line32		EQU	0x32		;line32 disp data
line33		EQU	0x33		;line33 disp data
line34		EQU	0x34		;line34 disp data
line35		EQU	0x35		;line35 disp data
line36		EQU	0x36		;line36 disp data
line37		EQU	0x37		;line37 disp data
line38		EQU	0x38		;line38 disp data
line39		EQU	0x39		;line39 disp data

tm0_setdata	EQU	0xdf		;FFH-DFH=32 32*2=64usec
;**********************************************************************
		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

		incf	count,1
		;---------------------------------------------------------------
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	0f0h
		movwf	PORTB

		call	set_dcount

		call	timer0_set

		call	suji_shoki
		call	suji_tenso
;--------------------------------------
main_loop
		decf	d_count,1
		btfss	STATUS,2
		goto	main_led
		call	set_dcount
		call	keisoku
		call	fugo_henkan
		movwf	fugo
		call	ondo_henkan
		call	suji_henkan
		call	suji_tenso

main_led
		;----------------------	0
		movlw	0x10
		call	sub_1
		movlw	0xff
		call	data_out
		movlw	0xff	
		call	data_out
		call	sub_2
		;----------------------	1
		movlw	0x11
		call	sub_1
		movf	line10,0
		call	data_out
		movf	line11,0	
		call	data_out
		call	sub_2
		;----------------------	2
		movlw	0x12
		call	sub_1
		movf	line12,0
		call	data_out
		movf	line13,0	
		call	data_out
		call	sub_2
		;----------------------	3
		movlw	0x13
		call	sub_1
		movf	line14,0
		call	data_out
		movf	line15,0	
		call	data_out
		call	sub_2
		;----------------------	4
		movlw	0x14
		call	sub_1
		movlw	0xff
		call	data_out
		movlw	0xff	
		call	data_out
		call	sub_2
		;----------------------	5
		movlw	0x15
		call	sub_1
		movf	line20,0	
		call	data_out
		movf	line21,0
		call	data_out
		call	sub_2
		;----------------------	6
		movlw	0x16
		call	sub_1
		movf	line22,0	
		call	data_out
		movf	line23,0
		call	data_out
		call	sub_2
		;----------------------	7
		movlw	0x17
		call	sub_1
		movf	line24,0	
		call	data_out
		movf	line25,0
		call	data_out
		call	sub_2
		;----------------------	8
		movlw	0x18
		call	sub_1
		movf	line26,0	
		call	data_out
		movf	line27,0
		call	data_out
		call	sub_2
		;----------------------	9
		movlw	0x19
		call	sub_1
		movf	line28,0	
		call	data_out
		movf	line29,0
		call	data_out
		call	sub_2
		;----------------------	10
		movlw	0x1a
		call	sub_1
		movlw	0xff	
		call	data_out
		movlw	0xff	
		call	data_out
		call	sub_2
		;----------------------	11
		movlw	0x1b
		call	sub_1
		movf	line30,0
		call	data_out
		movf	line31,0
		call	data_out
		call	sub_2
		;----------------------	12
		movlw	0x1c
		call	sub_1
		movf	line32,0
		call	data_out
		movf	line33,0
		call	data_out
		call	sub_2
		;----------------------	13
		movlw	0x1d
		call	sub_1
		movf	line34,0
		call	data_out
		movf	line35,0
		call	data_out
		call	sub_2
		;----------------------	14
		movlw	0x1e
		call	sub_1
		movf	line36,0
		call	data_out
		movf	line37,0
		call	data_out
		call	sub_2
		;----------------------	15
		movlw	0x1f
		call	sub_1
		movf	line38,0
		call	data_out
		movf	line39,0
		call	data_out
		call	sub_2
;---------------------------------------
		goto	main_loop
;-------------------------------------------------------------------------------
sub_1
		movwf	PORTA
		bsf	PORTB,2
		nop
		return
;------------------------------------
sub_2
		bcf	PORTB,2
		nop
		bcf	PORTA,4
		nop
		call	wait_1
		bsf	PORTA,4
		nop
		return
;-------------------------------------------------------------------------------
wait_0
		movlw	0ffh
		movwf	wait_data
		goto	wait_2
wait_1		
		movlw	0ffh
		movwf	wait_data
wait_2
		nop
		decfsz	wait_data,1
		goto	wait_2
		return
;-------------------------------------------------------------------------------
keisoku
		movlw	00h
		movwf	count
		bsf	PORTB,4
		nop
		call	wait_1
		bcf	PORTB,4
		nop
		bsf	INTCON,T0IE
keisoku2	nop
		btfsc	PORTB,7
		goto	keisoku2
		bcf	INTCON,T0IE
		return	
;------------------------------------------------------------------------------
suji_henkan
		movwf	count
		movf	count,0
		andlw	0fh
		movwf	suji_2
		swapf	count,0
		andlw	0fh
		movwf	suji_1
		return	
;-------------------------------------------------------------------------------
data_out
		movwf	out_data
		bcf	PORTB,1
		btfsc	out_data,0
		bsf	PORTB,1
		call	clk

		bcf	PORTB,1
		btfsc	out_data,1
		bsf	PORTB,1
		call	clk

		bcf	PORTB,1
		btfsc	out_data,2
		bsf	PORTB,1
		call	clk

		bcf	PORTB,1
		btfsc	out_data,3
		bsf	PORTB,1
		call	clk

		bcf	PORTB,1
		btfsc	out_data,4
		bsf	PORTB,1
		call	clk

		bcf	PORTB,1
		btfsc	out_data,5
		bsf	PORTB,1
		call	clk

		bcf	PORTB,1
		btfsc	out_data,6
		bsf	PORTB,1
		call	clk

		bcf	PORTB,1
		btfsc	out_data,7
		bsf	PORTB,1
		call	clk
		return
;--------------------------------------------------------------------------------
clk
		bsf	PORTB,0
		nop
		bcf	PORTB,0
		nop
		return
;--------------------------------------------------------------------------------
suji_shoki	movlw	0x00		;test
		movwf	fugo
		movlw	0x00		;test
		movwf	suji_1
		movlw	0x00		;test
		movwf	suji_2
		return
;--------------------------------------------------------------------------------
offset_shoki
		movlw	0x00
		movwf	d_offset
		return
;--------------------------------------------------------------------------------
set_dcount
		movlw	0x10
		movwf	d_count
		return
;--------------------------------------------------------------------------------
suji_tenso

		call	offset_shoki
suji_tenso_f
		movlw	line10
		addwf	d_offset,0
		movwf	FSR
		movf	fugo,0
		call	fugo_data
		movwf	INDF
		incf	d_offset,1
		movf	d_offset,0
		sublw	0x06
		btfss	STATUS,2
		goto	suji_tenso_f

		call	offset_shoki
suji_tenso_0
		movlw	line20
		addwf	d_offset,0
		movwf	FSR
		movf	suji_1,0
		call	suji_data
		movwf	INDF
		incf	d_offset,1
		movf	d_offset,0
		sublw	0x0a
		btfss	STATUS,2
		goto	suji_tenso_0

		call	offset_shoki
suji_tenso_1
		movlw	line30
		addwf	d_offset,0
		movwf	FSR
		movf	suji_2,0
		call	suji_data
		movwf	INDF
		incf	d_offset,1
		movf	d_offset,0
		sublw	0x0a
		btfss	STATUS,2
		goto	suji_tenso_1

		return
;--------------------------------------------------------------------------------
fugo_data	movwf	taihi
		bcf	STATUS,0
		rlf	taihi,1
		rlf	taihi,1
		rlf	taihi,1
		movf	taihi,0
		addwf	d_offset,0
		movwf	taihi
		movlw	low(fugo_table)
		addwf	taihi,1
		movlw	high(fugo_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
fugo_table	;----------- 0(+)
		retlw	07f	
		retlw	0fe	
		retlw	01f	
		retlw	0f8	
		retlw	07f
		retlw	0fe
		retlw	0ff
		retlw	0ff
		;----------- 1(-)
		retlw	07f	
		retlw	0fe
		retlw	07f
		retlw	0fe
		retlw	07f
		retlw	0fe
		retlw	0ff
		retlw	0ff
		;----------- 2(HEX)
		retlw	024
		retlw	008
		retlw	0bb
		retlw	0da
		retlw	0a4
		retlw	00b
		retlw	0ff
		retlw	0ff
		;----------- 3(space)
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
;--------------------------------------------------------------------------------
suji_data	movwf	taihi
		movwf	taihi2
		bcf	STATUS,0
		rlf	taihi,1
		rlf	taihi,1
		rlf	taihi,1
		rlf	taihi2,1
		movf	taihi2,0
		addwf	taihi,0
		addwf	d_offset,0
		movwf	taihi
		movlw	low(suji_table)
		addwf	taihi,1
		movlw	high(suji_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
suji_table	;----------- 0
		retlw	007	
		retlw	0E0	
		retlw	0F9	
		retlw	09F	
		retlw	0F9
		retlw	09f
		retlw	0f9
		retlw	09f
		retlw	007
		retlw	0e0
		;----------- 1
		retlw	0FF	
		retlw	0Ff
		retlw	0ff
		retlw	0e7
		retlw	0ff
		retlw	0e7
		retlw	001
		retlw	080
		retlw	0ff
		retlw	0ff
		;----------- 2
		retlw	0e1	
		retlw	0e7
		retlw	099
		retlw	09f
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	0f9
		retlw	0e1
		;----------- 3
		retlw	0e7
		retlw	0e7
		retlw	0f9
		retlw	09f
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	087
		retlw	0e1
		;----------- 4
		retlw	01f	
		retlw	0fe
		retlw	09f
		retlw	0f9
		retlw	09f
		retlw	0e7
		retlw	001
		retlw	080
		retlw	09f
		retlw	0ff
		;----------- 5
		retlw	0e7
		retlw	081
		retlw	0f9
		retlw	099
		retlw	0f9
		retlw	099
		retlw	0f9
		retlw	099
		retlw	007
		retlw	09e
		;----------- 6
		retlw	007	
		retlw	0f8
		retlw	079
		retlw	0e6
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	087
		retlw	0ff
		;----------- 7
		retlw	0ff	
		retlw	09f
		retlw	0ff
		retlw	09f
		retlw	081
		retlw	09f
		retlw	07f
		retlw	098
		retlw	0ff
		retlw	087
		;----------- 8
		retlw	087
		retlw	0e1
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	087
		retlw	0e1
		;----------- 9
		retlw	0ff	
		retlw	0e1
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	067
		retlw	09e
		retlw	01f
		retlw	0e0
		;----------- A
		retlw	001	
		retlw	0e0
		retlw	07f
		retlw	09e
		retlw	07f
		retlw	09e
		retlw	07f
		retlw	09e
		retlw	001
		retlw	0e0
		;----------- B
		retlw	001	
		retlw	080
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	087
		retlw	0e1
		;----------- C
		retlw	007	
		retlw	0e0
		retlw	0f9
		retlw	09f
		retlw	0f9
		retlw	09f
		retlw	0f9
		retlw	09f
		retlw	0e7
		retlw	0e7
		;----------- D
		retlw	001	
		retlw	080
		retlw	0f9
		retlw	09f
		retlw	0f9
		retlw	09f
		retlw	0f9
		retlw	09f
		retlw	007
		retlw	0e0
		;----------- E
		retlw	001	
		retlw	080
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	079
		retlw	09e
		retlw	0f9
		retlw	09f
		;----------- F
		retlw	001	
		retlw	080
		retlw	07f
		retlw	09e
		retlw	07f
		retlw	09e
		retlw	07f
		retlw	09e
		retlw	0ff
		retlw	09f
		;----------- (space)
		retlw	0ff	
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		;------------ (sita)
		retlw	09f
		retlw	0ff
		retlw	007
		retlw	080
		retlw	001
		retlw	080
		retlw	007
		retlw	080
		retlw	09f
		retlw	0ff
		;------------(ue)
		retlw	0ff
		retlw	0f9
		retlw	001
		retlw	0e0
		retlw	001
		retlw	080
		retlw	001
		retlw	0e0
		retlw	0ff
		retlw	0f9
;------------------------------------------------------------------------------
ondo_henkan	movf	count,0
		movwf	taihi
		movlw	low(ondo_table)
		addwf	taihi,1
		movlw	high(ondo_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
ondo_table	;----------- 00
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		;----------- 10	
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		retlw	0ff
		;----------- 20
		retlw	0ff
		retlw	0ff
		retlw	020
		retlw	019
		retlw	018
		retlw	018
		retlw	017
		retlw	016
		retlw	016
		retlw	015
		retlw	014
		retlw	014
		retlw	013
		retlw	012
		retlw	012
		retlw	011
		;----------- 30
		retlw	011
		retlw	010
		retlw	009
		retlw	009
		retlw	008
		retlw	008
		retlw	007
		retlw	006
		retlw	006
		retlw	005
		retlw	005
		retlw	004
		retlw	004
		retlw	003
		retlw	003
		retlw	002
		;----------- 40
		retlw	001
		retlw	000
		retlw	000
		retlw	001
		retlw	001
		retlw	002
		retlw	002
		retlw	003
		retlw	003
		retlw	004
		retlw	005
		retlw	005
		retlw	006
		retlw	006
		retlw	007
		retlw	007
		;----------- 50
		retlw	008
		retlw	008
		retlw	009
		retlw	009
		retlw	010
		retlw	010
		retlw	011
		retlw	011
		retlw	012
		retlw	012
		retlw	013
		retlw	013
		retlw	014
		retlw	015
		retlw	015
		retlw	016
		;------------ 60
		retlw	016
		retlw	017
		retlw	017
		retlw	018
		retlw	018
		retlw	019
		retlw	020
		retlw	020
		retlw	021
		retlw	021
		retlw	022
		retlw	022
		retlw	023
		retlw	023
		retlw	024
		retlw	025
		;------------ 70
		retlw	025
		retlw	026
		retlw	026
		retlw	027
		retlw	028
		retlw	028
		retlw	029
		retlw	029
		retlw	030
		retlw	031
		retlw	031
		retlw	032
		retlw	033
		retlw	033
		retlw	034
		retlw	035
		;----------- 80
		retlw	035
		retlw	036
		retlw	037
		retlw	037
		retlw	038
		retlw	039
		retlw	040
		retlw	041
		retlw	042
		retlw	042
		retlw	043
		retlw	044
		retlw	045
		retlw	046
		retlw	046
		retlw	047
		;----------- 90
		retlw	048
		retlw	049
		retlw	050
		retlw	051
		retlw	052
		retlw	053
		retlw	054
		retlw	055
		retlw	056
		retlw	057
		retlw	058
		retlw	059
		retlw	061
		retlw	062
		retlw	063
		retlw	064
		;----------- A0
		retlw	066
		retlw	067
		retlw	068
		retlw	070
		retlw	071
		retlw	073
		retlw	075
		retlw	076
		retlw	078
		retlw	080
		retlw	082
		retlw	084
		retlw	086
		retlw	089
		retlw	091
		retlw	094
		;----------- B0
		retlw	097
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe
		retlw	0fe

;------------------------------------------------------------------------------
fugo_henkan	movf	count,0
		movwf	taihi
		movlw	low(fugoh_table)
		addwf	taihi,1
		movlw	high(fugoh_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
fugoh_table	;----------- 00
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		;----------- 10	
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		;----------- 20
		retlw	003
		retlw	003
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		;----------- 30
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		retlw	001
		;----------- 40
		retlw	001
		retlw	001
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		;----------- 50
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		;------------ 60
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		;------------ 70
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		;----------- 80
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		;----------- 90
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		;----------- A0
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		retlw	000
		;----------- B0
		retlw	000
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
		retlw	003
;-------------------------------------------------------------------------------
port_set				;RA0,RA1,RA2,RA3,RA4(OUT)
					;RB0,RB1,RB2,RB3,RB4,RB5,RB6(OUT)
					;RB7(IN)
		bsf	STATUS,RP0
		clrf	TRISA
		clrf	TRISB
		bsf	TRISB,7
		nop
		bcf	STATUS,RP0
		return

timer0_set

		bsf	STATUS,RP0
		movlw	080h		;(1)PORTB NOT PULLUP
					;(0)INTEDG
					;(0)TOCS
					;(0)TOSE
					;(0)PSA
					;(000)1/2
		movwf	OPTION_REG
		bcf	STATUS,RP0

		movlw	tm0_setdata
		movwf	TMR0
		bsf	INTCON,T0IE
		bsf	INTCON,GIE
		return


		END                     ; directive 'end of program'

不明点などあればメールお願いいたします。nonchansoft@nifty.com