PDA

View Full Version : light sensor program pls help....



ajak
- 8th March 2008, 00:48
code:

b0 var byte
b1 var byte
b2 var byte

start:
LOW 3
LOW 4
pot 1, 255,b0 'Read CdS cell # 1
pot 2, 255,b1 'Read CdS cell # 2
If b0 = b1 then straight
if b0 > b1 then left
if b1 > b0 then right

straight:
high 3
high 4
goto start

left:
b2 = b0 - b1 'Compare numerical values +/15
if b2 > 15 then left1 'If greater than 15 turn left
goto straight 'If not go to straight subroutine

left1: 'Turn left
high 3
low 4 'Motor control
goto start

right: 'Compare numerical values +/15
b2 = b1 - b0 'If greater then 15 points
if b2 > 15 then right1 'Turn toward the right
goto straight 'If not go straight

right1: 'Turn right
high 4
low 3 'Motor control
goto start 'Do again

-------------------

i used a pic16f84a and xt oscillator. everyone please help me with this program. i try to compile it and it works and program succesfully. but it wont work when i try to build it in the breadboard. please help.

Kamikaze47
- 9th March 2008, 05:19
it looks like you are controlling the outputs of "3" and "4", but as soon as u tell your program what to set them to, you are restarting the program, and the 1st thing u do is set them both low. So they will only go high for a very very very small amount of time.

e.g. straight:

straight:
high 3
high 4
goto start

start:
LOW 3
LOW 4
...

they will only be high for as long as it take the program to goto start.

skimask
- 9th March 2008, 06:23
That's the same program that you were given in the other thread back in January.
If it didn't work then, it's probably not going to work now.
Just because it compiles, assembles, and programs without errors doesn't mean it's going to work the way you want it to work.

Get rid of the motors, get rid of the neato/nifty stuff.

Start working from nothing and work your way up.

How do you know the POT command is actually responding the way you want them to respond?

In the POT command, you have the 'scale' set at 255. Are you sure this is correct?
Have you 'calibrated' the 'scale' the way that the PBP manual tells you to set it up?
How can you be sure that your CDS cells are connected correctly?
How do you know that the PIC is actually running and executing the code?