will3330
Newbie level 3
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
Thanks
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