$20 says that even when Bruce does finish the book, we'll still be answering the same questions over and over and over...and not because of a lack of information from the book.
Maybe Bruce can include a couple of hands with each book.. ya know, for the user to hold while messing around with the PICs.
I am working with the following code using the lcd to display distance with the Ping sensor.
I am using the QL200 development board, so my DEFINE statements may be different or un-needed for you. My problem is that the ping sensor works,( I can see it on my oscilloscope),
but I cannot get a reading on my lcd. Only 0.
Any help would be appreciated!.
' File......sonar1.pbp
' Microcontroller used: Microchip Technology 16F887
'--------Program Desciption--------
' Using the ping ultrasonic range finder,
' the distance from the range finder to an object
' is displayed on an LCD screen in inches.
' rb0 is signal in/out
define osc 4
adcon1 = %00000000
define lcd_dreg portd
define lcd_dbit 4
define lcd_ereg porta
define lcd_ebit 3
dist var byte
range var word
inches CON 15 'Assigns the value 15 conversion
pause 2000
sonar 'Pulse Width
pulsout 0,20
pauseus 100
pulsin 0,10,range
dist = range/inches 'Converts raw sonar reading to inches
LCDOUT $FE,1,"Distance"
LCDOUT $FE,$14,#range
PAUSE 2000
GOTO sonar
END
Tried capitalizing Define's but to no avail, you're right though they are supposed to be in capitol. Any other ideas??
Last edited by Picstar; - 22nd September 2008 at 14:25.
You're right missing : in sonar label. According to the specs on the ping unit, there is a 750us pause called a "holdoff?". At any rate, I have tried it without a pause and have changed timing in the pulsin and pulsout commands, but still no luck. Using PBP 2.50b. heres the latest code:
' File......sonar1.pbp
' Microcontroller used: Microchip Technology 16F887
'--------Program Desciption--------
' Using the ping ultrasonic range finder,
' the distance from the range finder to an object
' is displayed on an LCD screen in inches.
' rb0 is signal in/out
adcon1 = %00000000
define LCD_DREG PORTD
define LCD_DBIT 4
define LCD_EREG PORTA
define LCD_EBIT 3
dist var byte
range var byte
inches CON 15 'Assigns the value 15 conversion
pause 2000
sonar: 'Pulse Width
pulsout portb.0,20
pulsin portb.0,100,range
'dist = range/inches 'Converts raw sonar reading to inches
LCDOUT $FE,1,"Distance"
LCDOUT $FE,$14,#range
PAUSE 2000
GOTO sonar
END
Last edited by Picstar; - 22nd September 2008 at 14:28.
Re-read the manual on the use of the pulsin statement.
You say the unit has a 'holdoff' of 750us, and yet you originally used a pauseus of 100. What's up with that?
The define, in this case, won't make any difference since it's define osc 4, which is PBP default...
How does that work? Is it a label? Is it a command? Is it a comment?Code:sonar 'Pulse Width
You wait for 100us instead of going straight to looking for a return pulse? How does THAT work? Shouldn't you jump directly to looking for the return pulse?Code:pulsout 0,20 pauseus 100 pulsin 0,10,range
Which version of PBP are you using?
Bookmarks