« Rockin kick ass begining of everything code | Main | The final parts list »
December 08, 2004
The final code
for class anyway:
some last minute sdvice: put capacitors and change the resistors, change the power source to keep the phototrans from overloading the circuit.
- use the 29 suummmathin 05 instead of the TIP 7805 (the 8 stands for the min. number of volts you can put into it... who knew)
- remember for the pic, 25 miliamps/pin max over a 3 pin max
- 1000 ohm normal LED - 220 superb
'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : robotGroup
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:
TRISB = %00000000
TRISD = %00000000
'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in
'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify
' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection
' ----------------------------------------------------- VARIABLES
'-- ir and ultrasonic vars (words or ints I'm not sure...)
getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading
readMotion2 var WORD 'normalized IR reading
getSonic var WORD 'getSonic is the Ultrasonic reading
rightTransistor VAR BYTE 'getLight is Transistor the on the right
leftTransistor VAR BYTE 'getleftlight is the tranistor on the left
centerTransistor VAR BYTE 'getcenterlight is the center transistor
' ----------------------------------------------------- FAKEDATA
'getSonic = 375
' ----------------------------------------------------- START MAIN
'startup sequence
main:
HIGH PORTD.2
Pause 100
LOW PORTD.2
'get values
ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1
ADCIN 2, lefttransistor 'GET THE TRANSISTOR READING on the right
ADCIN 3, centerTRANSISTOR 'GET THE TRANSISTOR READING ON THE LEFT
ADCIN 4, rightTRANSISTOR 'GET THE READING ON THE CENTER TRANSISTOR
'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's
'debug sensor infomation
'for somereason this seems to lock up for a while
'SEROUT2 tx, inv9600, ["ir is ", dec readMotion, 13,10, "RIGHTLIGHT IS ", dec RIGHTTRANSISTOR, 13,10, "LEFTLIGHT IS ", dec LEFTTRANSISTOR, 13,10, "CENTERLIGHT IS ", dec CENTERTRANSISTOR, 13,10]
If (getIR > 400) Then fullBackward
IF (righttransistor > 150) THEN rightT
IF (lefttransistor > 150) THEN leftT
IF (CENTERTRANSISTOR > 150) THEN cenerT
IF (getIR >= 300) AND (getIR <= 400 )Then leftBackward
IF (getIR >= 250) AND (getIR <= 300 )Then rightBackward
IF (getIR >= 220) AND (getIR <= 250 )Then standStillLeft
IF (getIR >= 200) AND (getIR <= 220 )Then standStillRight
IF (getIR < 200) then fullForward
'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html
goto main
cenerT:
PORTB = %00000000
'rc4
HIGH PORTC.4
PORTB = %01010000
pause 500
LOW PORTC.4
'gosub fullForward
goto main
rightT:
PORTB = %00000000
'rc4
HIGH PORTD.3
pause 500
PORTB = %01000000
LOW PORTD.3
'GOSUB leftForward
goto main
leftT:
PORTB = %00000000
'rd3
HIGH PORTC.5
pause 100
PORTB = %00010000
LOW PORTC.5
'GOSUB rightForward
goto main
fullForward:
PORTB = %01010000
goto main
fullBackward:
PORTB = %10100000
goto main
fullStop:
PORTB = %00000000
goto main
leftForward:
PORTB = %01000000
goto main
leftBackward:
PORTB = %10000000
goto main
rightForward:
PORTB = %00010000
goto main
rightBackward:
PORTB = %00100000
goto main
standStillLeft:
PORTB = %01100000
pause 700
goto main
standStillRight:
PORTB = %10010000
pause 500
goto main
Posted by cm1002 at December 8, 2004 05:54 PM