View Single Post
Old 12-01-2006, 07:29 AM   #11
anzuus
Nhập môn đệ tử
 
Tham gia ngày: Dec 2005
Bài gửi: 7
:
Smile

Em chao anh, Xmas rồi nhà em có việc nên em phải về, ko ghé forum.

Em đã tiến hành làm đề tài, phần điều khiển Unipolar Stepper Motor em làm cũng được khá nhiều, về phần em đã hỏi anh - Polaroid Ultrasonic Ranging System thì em đang trong giai đoạn hoàn thành. Em đã down form của anh về, tuần tới em bắt đầu viết báo cáo.

Em cũng tham khảo nhiều chỗ, em post cái schematic voi đoạn chương trình của em, vẫn chưa đc, anh góp ý hộ em. Tuần tới em cũng phải báo cáo phần này.



Sơ đồ này em chưa điền giá trị của linh kiện, cái SW2 thi chi là cái khóa thôi ạ.

Đây là code ạ

Code:
list p=16F628A
;
;**************Progaram Equates*****************
;
pc		equ	0x02
status		equ	0x03
trisa		equ	0x05
porta		equ	0x05
trisb		equ	0x06
portb		equ	0x06
counter		equ	0x0c
maxvalue	equ	0x0d
minvalue	equ	0x0e
loop		equ	0x0f
timerctr1	equ	0x10
finaltime	equ	0x11
buzztime	equ	0x12
temp1		equ	0x13
temp2		equ	0x14
temp3		equ	0x15
range		equ	0x16
retvalue	equ	0x17
rp0		equ	5
w		equ	0
f		equ	1
carry		equ	0
zero		equ	2
;
;
;****************Main Program*******************
;
start		clrf	timerctr1	;Clear sleep timer
		clrf	finaltime	
		bcf	portb,1
		bcf	portb,2
		bcf	portb,3

		bsf	status,rp0	;select bank1
		movlw	b'01110000'	;select I/O pin
		movwf	trisb		;of port b
		movlw	b'00011111'	;select I/O pin
		movwf	trisa		;of port a
		bcf	status,rp0	;bank 0
;
;******************Check for Start Swiitch*******
poll		btfsc	porta,0	;check start
		goto	poll	

;******************Measure distance************
;
begin
		call	delay_40ms
		call	delay_40ms	;call delay 80ms
		movlw	0x00		;reset counter
		movwf	counter
		bsf	portb,0		;set INIT
		
;
again		call	delay_30us	;call delay 30 us
		incf	counter		;increase cointer by 1
;
		btfss	portb,4		;check echo coming
		goto	again		;back
		bcf	portb,0		; reset INIT
;
		call	delay_40ms
		call	delay_40ms
;
;****************Read User Set Range************
;
		movf	porta,w		;read maximum range value
		call	getmax
		movwf	maxvalue	
		movf	porta,w		;read minimum range value
		call	getmin
		movwf	minvalue
;
;***********Compare User Set Range With Measure Value********
;
		movf	minvalue,w	;compare minimum value
		subwf	counter,w	;with counter
		btfsc	status,carry	;if counter > minimum value
		goto	compmax		;compare with maximum value
		goto	light_red	;if couter < minimum value
;
compmax		movf	maxvalue,w	;compare maximum value
		subwf	counter,w	
		btfss	status,carry
		goto	light_green
		goto	light_yellow
;
;******************LED************************************
light_red	             bcf        portb,3		;off yellow led
		bcf	portb,2		; off green led
		bsf	portb,1		;on red led
		clrf	timerctr1
		clrf	finaltime	
		goto	begin
light_green	bcf	portb,3		;off yellow led
		bcf	portb,1		; off green led
		bsf	portb,2		;on red led
		clrf	timerctr1
		clrf	finaltime	
		goto	begin	
light_yellow	bcf	portb,2		;off yellow led
		bcf	portb,1		; off green led
		bsf	portb,3		;on red led
;
;********************Sleep timer************************
		incfsz	timerctr1
		goto	begin
		incf	finaltime
		movlw	.6
		subwf	finaltime,w
		btfss	status,zero
		goto	begin
		bcf	portb,3
		sleep
		goto	start
;
;********************* Delay Subroutine******************
;
delay_5ms	movlw	.10
		movwf	temp1
;
outer1		movlw	.167
		movwf	temp2
;
inner1		decfsz	temp2
		goto	inner1
		decfsz	temp1
		goto	outer1
		return
;
;
delay_30us	movlw	.7
		movwf	loop
go		decfsz	loop
		goto	go
		nop
		nop
		return
delay_40ms	clrf	temp1
		clrf	temp2
		movlw	.40
		movwf	temp1
;
outer2		movlw	.167
		movwf	temp2
;
inner2		decfsz	temp2
		goto	inner2
		decfsz	temp1
		goto	outer2
;
		return
;
;*********************Look up table****************
getmin		addwf	pc,f
		retlw	.96
		retlw	.100
		retlw	.114
		retlw	.128
		retlw	.142	
		retlw	.158
		retlw	.172
		retlw	.186
		retlw	.200
		retlw	.216	
		retlw	.230
		retlw	.244
;
getmax		addwf	pc,f
		retlw	.100
		retlw	.114
		retlw	.128
		retlw	.142	
		retlw	.158
		retlw	.172
		retlw	.186
		retlw	.200
		retlw	.216
		retlw	.230
		retlw	.244
		retlw	.252
;
		end
;
;*****************************************************************************
anh xem rồi góp ý sửa chữa hộ em với, em đặt tên cũng hơi lung tung

Cảm ơn anh

thay đổi nội dung bởi: anzuus, 12-01-2006 lúc 08:07 AM.
anzuus vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn