Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SHARP IR Range finder PIC16 program?

Status
Not open for further replies.

will3330

Newbie level 3
Joined
Jan 19, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
I'm implementing a sharp rangefinder sensor (GP2D02) with a PIC16877 clocked @ 10Mhz
This sensor sends a digital 8 bit output to 1 input PIC based on a # of clock cycles.
More information can be found here:
http://www.datasheetcatalog.org/datasheet/Sharp/mXvryzu.pdf

I was wondering how this will be implemented program-wise with assembly
I attempted to try it (see below) but it doesn't seem to work :(

If you guys could look over it that would be great :)
*************************************************

note:
-RC4 is Vout and RC3 is Vin (respective to the sensor)
-Initially Vout is low and Vin is high
-range is a variable to store the 8bit value coming in
-delay functions are correct
-this program is based on an ISR for keypad (does work)

I know the programming method is VERY inefficient but this is just testing purposes
Code:
test
		clrf		counter
		clrf		range
		clrw
		incf	counter,1
		incf	counter,1
		incf	counter,1
		incf	counter,1
		incf	counter,1
		incf	counter,1
		incf	counter,1
		incf	counter,1
		incf	counter,1 ;9 cycles to get data
		
		bcf		PORTC,3 ; Vin low to indicate to start sensor
		call 	delay10ms
		call 	delay10ms
		call 	delay10ms
		call 	delay10ms
		call 	delay10ms
		call 	delay10ms
		call 	delay10ms ;setup time for sensor
		
		btfss	PORTC,4 ; wait for Vout to go high
		goto	$-1
		call 	cycles
		movf	range,w ;copy range to working register
		movwf	PORTD ; put to PORTD for LED testing
		return
		

cycles
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop ; delay for 40 cycles or between 2us - 170us
		bcf	PORTC, 3 ; tells sensor to get bit
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop;delay for about 1us for sensor stuff
		
		rlf		range,1 ;rotate range to left by one
		swapf	PORTC,w ;sets Vout as bit 0 in w
		andlw	0x01	;gets last bit
		iorwf	range,1 ;concatenates last bit to range
		bsf		PORTC,3 ; read bit, ready for next bit
		decfsz	counter,1 ; decrement and loop
		goto cycles
		return

Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top