⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d.txt

📁 pic系列单片机得控制程序 主要进行温度采集和转换控制
💻 TXT
📖 第 1 页 / 共 5 页
字号:
		call	sd15x		

		call	sd12p		
		
		movlw	d'8'
		call	sdxc		
		
		call	sd4c		

		call	lcdclear2
		movlw	'2'
		call	lcdout

		call	usual
		movf	bin24_2,w
		sublw	d'7'
		btfsc	status,c
		goto	check2low
		call	set4
		goto	commonstuffr
check2low
		movf	bin24_2,w
		btfss	status,z
		goto	commonstuff
		movf	bin24_1,w
		sublw	d'16'
		btfss	status,c
		goto	commonstuff
		call	set1
		goto	commonstuffr


isit3
		
		movf	offsetx,w
		sublw	offset3_0
		btfss	status,z
		goto	its4
its3		

		call	sd15x		;sd is short for shift and drop
		call	sd15x		;sd is short for shift and drop

		call	sd12s		;sd is short for shift and drop
		
		
		movlw	d'8'
		call	sdxp		;sd is short for shift and drop
		

		call	sd4c		;sd is short for shift and drop

		
		call	lcdclear2
		movlw	'3'
		call	lcdout

		call	fourplus
		movf	bin24_2,w
		sublw	d'7'
		btfsc	status,c
		goto	check3low
		call	set4
		goto	commonstuffr
check3low
		movf	bin24_2,w
		btfss	status,z
		goto	commonstuff
		movf	bin24_1,w
		sublw	d'16'
		btfss	status,c
		goto	commonstuff
		call	set2
		goto	commonstuffr


its4		

		call	sd15x		;sd is short for shift and drop
		
		call	sd15x		
		
		call	sd15x		


		call	sd12s		
		
		
		movlw	d'8'
		call	sdxp		
		
		call	sd4c		

		
		call	lcdclear2
		movlw	'4'
		call	lcdout

		call	fourplus

check4low
		movf	bin24_2,w
		btfss	status,z
		goto	commonstuff
		movf	bin24_1,w
		sublw	d'128'
		btfss	status,c
		goto	commonstuff
		call	set3
						;now some shared stuff
commonstuffr
		bsf	autoflags,rangechange


commonstuff
		call	zerooff			;suppress useless zeros, commas, etc.
		call	dataout			;translate & display set on line 1 of lcd
		movlw	0
		call	lcdaddress
		movlw	'+'			;+/- goes in 1st position, line 1
		btfss	flags,plusminus
		movlw	'-'
		call	lcdout
		
		movlw	h'40'+d'13'		;lcdaddress 2nd row
		call	lcdaddress
		btfss	autoflags,manual
		goto	commona
		movlw	'M'			;Manual Mode
		goto	commonstar
		
commona
		movlw	'A'			;Auto Mode
commonstar
		call	lcdout
		movlw	'*'			;two ** indicates a new conversion is completed.
		call	lcdout
		call	lcdout
		call	xmillisecs
		btfss	autoflags,rangechange	;if range changed, say so
		goto	mainloop		;begin next period
		bcf	autoflags,rangechange	;update flag so we don't do this again.
		call	lcdhome2		;2nd line of lcd
		movlw	autotext-starttext	;it *might* be in auto mode
		btfsc	autoflags,manual	;or it *could* be in manual mode
		goto	mstuff
		call	textout			;if auto mode, flash "AUTORANGING"
		goto	mainloop
mstuff
		movlw	1
		call	lcdaddress
		movlw	'M'			;if manual mode, just flash an "M"
		call	lcdout
		goto	mainloop

fourplus
		movlw	fourspaces-starttext	;some ranges have four spaces first...
		call	textout
usual
		movlw	ufnfpftext-starttext	;all have the uf nf stuff
		goto	textout

;zerooff: scans current ascii contents of decimal nibbles and 
; replaces leftmost zeros and comma with spaces. stops at decimal point
; or first non-zero numeric. zero suppresion and some other stuff.

zerooff
		bcf	autoflags,stop	;start off enabled to scan
		movlw	xmsb+1		;scan from xmsb to xlsb
		movwf	fsr		;use indirect addressing
zeroloop
		decf	fsr,f		;update pointer
		movf	fsr,w
		sublw	xlsb-1		;check if past xlsb
		btfsc	status,z
		return			;if past xlsb, we is done here
		
		btfsc	autoflags,stop
		return			;done if stop is set
		
		call	leftcheck
		btfsc	autoflags,stop
		return			;done if stop is set
		call	rightcheck
		goto	zeroloop
leftcheck
		movf	indf,w		;w has copy of byte.
		andlw	b'11110000'	;look at left nibble only
		movwf	temp1		;save original...
		swapf	temp1,w		;check nibble in byte format
		sublw	n0		;was it a leading 0?
		btfsc	status,z
		goto	spaceit		;if so, change to a space.
		
		swapf	temp1,w		;get original back into w
		sublw	ncomma		;was it a comma?
		btfsc	status,z
		goto	spaceit		;if so, change to a space.

		
		swapf	temp1,w		;get original back into w
		sublw	nspace		;was it a space?
		btfsc	status,z
		goto	spaceit		;if so, leave it a space.

		bsf	autoflags,stop	;if anything else, then stop
		return
		
spaceit
		swapf	indf,w		;get swapped version of original
		andlw	b'11110000'	;preserve right nibble (in left)
		iorlw	nspace		;sneak in nspace
		movwf	indf		;save it
		swapf	indf,f		;swap it back to correct form
		return
		


rightcheck
		btfsc	autoflags,stop
		return
		swapf	indf,f		;swap nibbles
		call	leftcheck	;and share code!
		swapf	indf,f		;restore order.
		return

; this is the main synchronization section. It is responsible for assuring that we sync in the
; shortest possible time. After syncing to the period's edge we sort of twiddle our thumbs
; and watch for the flags being set by the interrupt handler. when the flags tell us
; something, we handle it. we handle things like taking excessively long, actually getting
; a flag that says we have a bin24 count accumulated, etc. we also occasionally check
; to see if anyone has pushed any buttons. notice that pushed puttons will terminate
; regular program flow and cause (among other things) a new set of readings to be acquired.

periodinit
		clrf	intcon		;disable all interrupts
		call	clearalldata	;clear binary and decimal versions.
					;also clear over_x counters.
					;data on lcd remains intact.
		btfss	autoflags,toolong	;did interrupt routine say "toolong"?
		goto	periodinit2		;if not, continue...
		call	lcdclear2		;if it *was* toolong, then tell the world!
		movlw	autotext-starttext	; well, it might be in maual or auto modes,
		btfsc	autoflags,manual	; so use different messages for first line
		movlw	manual2text-starttext
		call	textout
		call	delay400
		call	lcdclear2
		movlw	commontext-starttext	;and use some shared text for the rest.
		call	textout

		
periodinit2
		bcf	autoflags,toolong	;if we got here we have handled any toolong,
		bcf	flags,intoverflow	; and any overflow, so clear those flags now!
		btfsc	portb,periodin		;read periodin to find current state of sync
		goto	sync1			;highs go one place, lows another...
		goto	sync2
sync1
		bsf     status,rp0		;allow access to page 1 stuff!

		bcf     option_reg,intedg	;intedg 0=inc on falling 1=inc on rising
						; <<note: intedg and t0se use opposite definition!>>
						;we are incrementing on falling edge
						; because initial sync is on falling edge
						; and we want full period
		bcf     status,rp0		;allow access to page 0 stuff again. (normal)

		btfsc	portb,periodin		;read periodin
		goto	synconlow1
synconhigh1
		call	gethit			;allow buttons
		incf	over_0,f		;twiddle thumbs, but not for *too* long!
		btfss	status,z
		goto	synconhigh1b
		incf	over_1,f
		btfss	status,z
		goto	synconhigh1b
		incf	over_2,f
		btfss	over_2,2
		goto	synconhigh1b
		bsf	autoflags,toolong	;darn! too long! flag it!
		call	set4			;attempt to autorange to highest range.
		goto	periodinit
synconhigh1b
		btfss	portb,periodin		;read periodin
		goto	synconhigh1		;loop until high
synconlow1
		call	gethit			;allow buttons
		incf	over_0,f		;twiddle thumbs, but not for *too* long!
		btfss	status,z
		goto	synconlow1b
		incf	over_1,f
		btfss	status,z
		goto	synconlow1b
		incf	over_2,f
		btfss	over_2,2
		goto	synconlow1b
		bsf	autoflags,toolong	;darn! too long! flag it!
		call	set4			;attempt to autorange to high range
		goto	periodinit

synconlow1b
		btfsc	portb,periodin		;read periodin
		goto	synconlow1		;loop until low
		goto	gotsync

sync2
		bsf     status,rp0		;allow access to page 1 stuff!

		bsf     option_reg,intedg	;intedg 0=inc on falling 1=inc on rising
						; <<note: intedg and t0se use opposite definition!>>
						;we are incrementing on rising edge
						; because initial sync is on rising edge
						; and we want full period
		bcf     status,rp0		;allow access to page 0 stuff again. (normal)




		btfsc	portb,periodin		;read periodin
		goto	synconhigh2
synconlow2
		call	gethit			;allow buttons
		incf	over_0,f		;twiddle thumbs, but not *too* long!
		btfss	status,z
		goto	synconlow2b
		incf	over_1,f
		btfss	status,z
		goto	synconlow2b
		incf	over_2,f
		btfss	over_2,2
		goto	synconlow2b
		bsf	autoflags,toolong	;darn! too long! flag it!
		call	set4			;attempt to autorange to high range
		goto	periodinit


synconlow2b
		btfsc	portb,periodin		;read periodin
		goto	synconlow2		;loop until low
synconhigh2
		call	gethit			;allow buttons
		incf	over_0,f		;twiddle thumbs, but not for *too* long!
		btfss	status,z
		goto	synconhigh2b
		incf	over_1,f
		btfss	status,z
		goto	synconhigh2b
		incf	over_2,f
		btfss	over_2,2
		goto	synconhigh2b
		bsf	autoflags,toolong	;darn! too long! flag it!
		call	set4			;attempt to autorange to high range
		goto	periodinit


synconhigh2b
		btfss	portb,periodin		;read periodin
		goto	synconhigh2		;loop until high
		goto	gotsync
		
gotsync	
		clrf	tmr0			;clear timer to eliminate false triggers
						;periodin just changed.
		clrf	intcon         		;clear any pending interrupt requests
						; also clears all enables including gie.
						; effectively disables all interrupts
		bsf	intcon,inte		;enable rb0/int as int
		bsf     intcon,t0ie		;enable tmr0 interrupt
		
		bcf	flags,gotit		;reset indicators
		bcf	flags,intoverflow
		bsf     intcon,gie		;enable global interrupt enable for now...
		clrf	tmr0			;clear timer now to reduce latency


waitloop
		call	gethit			;allow buttons
		movlw	h'40'+d'14'		;lcdaddress 2nd row
		call	lcdaddress
		btfss	flags,flipflop		;flip/flop black box
		goto	flop			; to indicate major thumb twiddling in progress
flip
		movlw	flipchar
		call	lcdout
		movlw	flopchar
		call	lcdout
		bcf	flags,flipflop
		goto	gotityet
		
flop
		movlw	flopchar
		call	lcdout
		movlw	flipchar
		call	lcdout
		bsf	flags,flipflop

gotityet
		call	xmillisecs		;delay .2 seconds
		btfss	flags,gotit		;is gotit flag up?
		goto	waitloop		;wait seemingly forever....
		return				;WOW! we *finally* have a valid BIN24 ready!
		


;clearalldata: clears data xlsb->xmsb and bin24_0/1/2

clearalldata
		movlw	xlsb		;fsr will point to register set
		movwf	fsr
clearloop
		clrf	indf		;clear a set
		incf	fsr,f		;point to next set
		movf	fsr,w		;copy next set address to w
		sublw	xmsb+1		;done when past xmsb
		btfss	status,z
		goto	clearloop	;clear from xlsb to xmsb

		clrf	bin24_2		;clear 24 bit binary counter
		clrf	bin24_1
		clrf	bin24_0
		
		clrf	over_0		;clear 24 bit overflow counter
		clrf	over_1
		clrf	over_2
		return
		
;shared subroutines to add decimal numbers using mantissa/exponent information
; it may not be pretty, but it works!

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -