PDA

View Full Version : Need help with RC car code



rey1867
- 6th June 2006, 23:38
Before I start, Id just like to clarify that the only programming experience I have had is with VB. As such, I found picbasic's programming protocol rather easy. However, I have had no luck in getting my microcontroller to function.

My plan is :

1) Whenever the user presses a button on the controller, a signal is sent to any of the inputs which in turn causes an output to pulse.

2) The pulses for movement differ and are transmitted to the car using an infrared transmitter.

3) When they reach the car, these pulses are decoded and the proper output becomes active high and the car runs in the proper direction.

Im sorry if Im asking a bit too much, but I really need this to get to work as my project is due by friday.

thx

'************************************************* *****************************
'This is the code for the transmitter in the remote
Device = 16F84A

XTAL = 4 'Dont know clock frequency

Input PortA

Output PortB

If PortA.2 = 1 Then 'RA2 is input, Forward
PulsOut PortB.7 , 50 'RB7 = output, Pulse = 0.5 ms long

ElseIf PortA.3 = 1 Then 'RA3 is input, Reverse
PulsOut PortB.6, 100 'RB6 = output, Pulse = 100 ms long

ElseIf PortA.1 = 1 Then 'RA1 is input, Right
PulsOut PortB.5, 150 'RB5 = output, Pulse = 150 ms long

ElseIf PortA.0 = 1 Then 'RA0 is input, Left
PulsOut PortB.4, 200 'RB4 = output, Pulse = 200 ms long

End If

'************************************************* *****************************

'************************************************* *****************************
'This is the code for the reciever in the car

Device = 16F84A

XTAL = 4

Input PortA

Output PortB

Dim Move as Byte

Loop:

Move = PulsIn PortA.2, 1 'RA2 = input

If Move = 200 Then 'Left
PortB.7 = 1 'RB7 = output

ElseIf Move = 150 Then 'Right
PortB.6 = 1 'RB6 = output

ElseIf Move = 100 Then 'Reverse
PortB.5 = 1 'RB5 = output

ElseIf Move = 50 Then 'Forward
PortB.4 = 1 'RB4 = output
End If

GoTo Loop

'************************************************* *****************************

Melanie
- 6th June 2006, 23:45
Your code appears to contain non PICBasic statements. Are you using MeLabs PICBasic Pro Compiler? If not, you've landed in the wrong forum.

Looks like the Academic year end is fast approaching... and Beer and Girls in excess during the early semester means projects just ain't finished...

rey1867
- 6th June 2006, 23:49
thx for your speedy reply melanie

I am pretty sure I am using the correct compiler, but just to check I have uploaded an image.

http://img478.imageshack.us/img478/2985/picbasic9ip.th.jpg (http://img478.imageshack.us/my.php?image=picbasic9ip.jpg)

mister_e
- 6th June 2006, 23:59
Miiiip! you're not on the right forum, Here it's Melabs PicBasic... Not PROTON PicBasic.

You have to go at www.picbasic.org/forum

rey1867
- 7th June 2006, 00:00
Miiiip! you're not on the right forum, Here it's Melabs PicBasic... Not PROTON PicBasic.

You have to go at www.picbasic.org/forum

my apologies

thank you for directing me to the correct forum

mister_e
- 7th June 2006, 00:18
My pleasure Sir!