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

📄 gp16lf84.asm

📁 pic得电机控制程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	movwf	_action
	return
;
;--------------------------------
;
Mtr1cw	movfw	_mt1time	; for this long
M1cw	bcf	m1		; start motor 1 moving CW
	movwf	tmr0		;_/
	bcf	_t0if		; clear TMR0 overflow flag

mt1loop	btfss	limit0		; return early if
	b	mt1xit		;  limit switch is hit

	btfss	_t0if		; wait for overflow flag to activate
	b	mt1loop		; forever ?
	bcf	_t0if		; yes, it flipped, now clear it
mt1xit	bsf	m1		; all done, so turn motor off
	return			;_/
;
;--------------------------------
;
Mtr1ccw	movfw	_mt2time	; for this long
M1ccw	bcf	m2		; start motor 1 moving CCW
	movwf	tmr0		;_/
	bcf	_t0if		; clear TMR0 overflow flag

mt2loop	btfss	limit1		; return early if
	b	mt2xit		;  limit switch is hit

	btfss	_t0if		; wait for overflow flag to activate
	b	mt2loop		; forever ?
	bcf	_t0if		; yes, it flipped, now clear it
mt2xit	bsf	m2		; all done, so turn motor off
	return			;_/
;
;--------------------------------
;
Mtr2cw	movfw	_mt3time
M2cw	bcf	m3		; start motor 2 moving CW
	movwf	tmr0
	bcf	_t0if

mt3loop	btfss	limit2
	b	mt3xit

	btfss	_t0if
	b	mt3loop
	bcf	_t0if
mt3xit	bsf	m3
	return
;
;--------------------------------
;
Mtr2ccw	movfw	_mt4time
M2ccw	bcf	m4		; start motor 2 moving CCW
	movwf	tmr0
	bcf	_t0if

mt4loop	btfss	limit3
	b	mt4xit

	btfss	_t0if
	b	mt4loop
	bcf	_t0if
mt4xit	bsf	m4
	return
;
;--------------------------------
; Flash lights & do a dance
;
Wigl	movlw	.4		; initialize
	movwf	_wiggle		;_/

lpmore	movlw	b'00001110'	; flash lights alternately
	movwf	porta		; 74ac245 on, hold motors
	call	OneBlip

	movlw	b'00001101'	; flash lights alternately
	movwf	porta		; 74ac245 on, hold motors
	call	OneBlip

	movlw	b'00001011'	; flash lights alternately
	movwf	porta		; 74ac245 on, hold motors
	call	OneBlip

	movlw	b'00000111'	; flash lights alternately
	movwf	porta		; 74ac245 on, hold motors
	call	OneBlip

	decfsz	_wiggle,f	; this many times around
	b	lpmore		;_/

	movlw	b'00001111'	; all lights & motors, out & off
	movwf	porta		;_/
	movfw	portb		; read & clear edge flags
	return
;
;--------------------------------
	org	0x100
;
; Center the front legs
;
C_Front	movlw	.0		; pseudo-forever
	call	M1cw		; find switch
	rrf	tmr0,w		; save the TMR0 leftover, DIV 2
	andlw	0x7f		; mask rotated bit0
	sublw	.255		; TMR0 counts up
	call	M1ccw		; move halfway back ?
	return
;
;--------------------------------
; Center the back legs
;
C_Back	movlw	.0		; pseudo-forever
	call	M2cw		; find switch
	rrf	tmr0,w		; save the TMR0 leftover, DIV 2
	andlw	0x7f		; mask rotated bit0
	sublw	.255		; TMR0 counts up
	call	M2ccw		; move halfway back ?
	return
;
;--------------------------------
;
FPause	movlw	pz2tim
	b	paus2
;-------
Pause	movlw	pauztim		; update up-counter
paus2	movwf	tmr0		; start timer
	bcf	_t0if		; make sure flag not set
	nop			;_/
p1	btfss	_t0if		; is bit clear ?
	b	p1
	return
;
;--------------------------------
;
Beep	movlw	.50		; frequency
	movwf	_sqkvar3	;_/
	movlw	.20		; length
	movwf	_sqkvar2	;_/
	movlw	.5		; cycles per step
	movwf	_count		;_/

UpLoop	bsf	piezo		; piezo cycle, high
	call	SweepUp		; piezo cycle, high
	nop
	nop
	bcf	piezo		; piezo cycle, low
	call	SweepUp		; piezo cycle, low
	decfsz	_sqkvar2,f	; decrement #_cycles counter
	b	UpLoop		; until #_cycles done
	return
;
;--------------------------------
;
SweepUp	movfw	_sqkvar3	; cycles per step
	movwf	_sqkvar		;_/
Sweep2	decfsz	_sqkvar,f	; update cycles per step
	b	Sweep2		;_/
	decfsz	_count,f	; update cycle counter
	b	Sweep3

;when _count goes to 0, change frequency:
;
	movlw	.5		; reset cycles per step
	movwf	_count		;_/
	decf	_sqkvar3,f	; raise frequency
Sweep3	return
;
;--------------------------------
;
BeepDn	movlw	.50		; frequency
	movwf	_sqkvar3	;_/
	movlw	.20		; length
	movwf	_sqkvar2	;_/
	movlw	.5		; cycles per step
	movwf	_count		;_/

DnLoop	bsf	piezo		; piezo cycle, high
	call	SweepDn		; piezo cycle, high
	nop
	nop
	bcf	piezo		; piezo cycle, low
	call	SweepDn		; piezo cycle, low
	decfsz	_sqkvar2,f	; decrement #_cycles counter
	b	DnLoop		; until #_cycles done
	return
;
;--------------------------------
;
SweepDn	movfw	_sqkvar3	; cycles per step
	movwf	_sqkvar		;_/
Sd2	decfsz	_sqkvar,f	; update cycles per step
	b	Sd2		;_/
	decfsz	_count,f	; update cycle counter
	b	Sd3

;when _count goes to 0, change frequency:
;
	movlw	.5		; reset cycles per step
	movwf	_count		;_/
	incf	_sqkvar3,f	; lower frequency
Sd3	return
;
;--------------------------------
; This works, finally - PTB - Dec-13-2001.
;   No matter what speed it is running at,
;   here it gets set to FAST, then restored
;   to original before RETURNing.
;
OneBlip	clrw

Blips	movwf	_goto2		; save entry point
	btfss	speed		; if speed = 0 then fast
	b	blfast		; 
	bcf	_speeds,0	; remember that I was going slow
	b	mbcont

blfast	bsf	_speeds,0	; remember that I was going fast
mbcont	bcf	speed		; always go fast

DoBlip	movlw	high(DoBlip)	; trashes W
	movwf	pclath		; set the PC-High
	movfw	_goto2		; get entry point back
	addwf	pcl,f		; jump into table
	b	do0		; 1 beep
	b	do1		; 2 beeps
	b	do2		; 3 beeps
	b	do3		; 4 beeps
	b	do4		; 5 beeps
	b	do5		; 6 beeps
	b	do6		; 7 beeps
	b	do7		; 8 beeps
	b	do8		; dn-up-dn-up-dn
	b	do9		; dn-up-dn
;
do7	call	Beep		; 7
	call	FPause
do6	call	Beep		; 6
	call	FPause
do5	call	Beep		; 5
	call	FPause
do4	call	Beep		; 4
	call	FPause
do3	call	Beep		; 3
	call	FPause
do2	call	Beep		; 2
	call	FPause
do1	call	Beep		; 1
	call	FPause
do0	call	Beep		; 0
	call	FPause
;
; recall what speed I was at and restore it
;
DoXit	btfsc	_speeds,0	; if _speeds,0 =0 then slow
	b	blfst		; else restore to fast
	bsf	speed		; slow
	return
blfst	bcf	speed		; fast
	return
;
;-------
;
do8	call	BeepDn
	call	FPause
	call	Beep
	call	FPause
	call	BeepDn
	call	FPause
	call	Beep
	call	FPause
	call	BeepDn
	b	DoXit
;
;--------------------------------
;
do9	call	BeepDn
	call	FPause
	call	Beep
	call	FPause
	call	BeepDn
	b	DoXit
;
;--------------------------------
;
RandNum	rlf	_random,f
	rlf	_random,f
	btfsc	_random,4
	xorlw	1
	btfsc	_random,5
	xorlw	1
	btfsc	_random,3
	xorlw	1
	movwf	_random
	return			; return with random(W)
;
;--------------------------------
;
Times	movlw	0x0c		; start of RAM
	movwf	fsr		; clear pointer

	clrf	_eeadr
	movlw	.18		; bytes to get
	movwf	_eeloop		;_/

TLoop	call	EErbyte		; get one byte from internal EEPROM
	movwf	indf		; save byte into local RAM
	incf	fsr		; next RAM byte location
	incf	_eeadr		; next EEPROM byte
	decfsz	_eeloop,f	; update down-counter
	b	TLoop		; go back if not done, >0
	return
;
;--------------------------------
;
EErbyte	movfw	_eeadr	; get preset address
	movwf	eeadr	; write to eeprom address register
	bsf	bank1	; bank 1
	bsf	_rd	; enable read byte
	bcf	bank0	; bank 0
	movfw	eedata	; read data from eedata register
	return
;
;--------------------------------
;
EEwbyte	movfw	_eeadr	; get pre-set address
	movwf	eeadr	; write to eeprom address register
	movfw	_eedata	; get pre-set data byte
	movwf	eedata	; write data to ee data register
;-------
EEwrite	bsf	bank1	; bank 1
	bsf	_wren	; enable write byte
	movlw	0x55	; do this sequence for every byte
	movwf	eecon2	;____/
	movlw	0xaa	;___/
	movwf	eecon2	;__/
	bsf	_wr	;_/
	return
;
;--------------------------------
;
; CODEPAGE   NAME=eedata   START=0x2100   END=0x213F
; 64 bytes of onboard EEPROM
;
; (.255-decimal_number_wanted) for upcounter, TMR0.
;
	org	0x2100

	de	.255-.210	;  1, front motor CW
	de	.255-.210	;  2, front motor CCW
	de	.255-.210	;  3, rear motor CW
	de	.255-.210	;  4, rear motor CCW

	de	.255-.120	;  5, reverse front motor CW
	de	.255-.120	;  6, reverse front motor CCW
	de	.255-.180	;  7, reverse rear motor CW
	de	.255-.180	;  8, reverse rear motor CCW

	de	.255-.254	;  9, fast front motor CW
	de	.255-.254	; 10, fast front motor CCW
	de	.255-.245	; 11, fast rear motor CW
	de	.255-.245	; 12, fast rear motor CCW

	de	.255-.210	; 13, front motor CW
	de	.255-.210	; 14, front motor CCW
	de	.255-.210	; 15, rear motor CW
	de	.255-.210	; 16, rear motor CCW

	de	.0		; 17, action
	de	.6		; 18, _loops update
;
;--------------------------------
;
	END

⌨️ 快捷键说明

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