« PIC Motor Code 1 | Main | Friday Code »

December 03, 2004

Thursday Code - Motor Code, first if statement attempt

Acting funny. I hate if satements in PIC Basic

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : Carlyn Maw
'* 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:
T
TRISB = %00000000
TRISD = %00000000
' ----------------------------------------------------- CONSTANTS

' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)

getIR var BYTE 'getIR is the IR reading
readMotion var BYTE 'normalized IR reading

getSonic var BYTE 'getSonic is the Ultrasonic reading


' ----------------------------------------------------- FAKEDATA

' ----------------------------------------------------- START MAIN

'startup sequence
HIGH PORTD.2
Pause 1000
LOW PORTD.2
Pause 1000
HIGH PORTD.2


main:

'get values
'ADCIN 0, GETSONIC ' get the ADC value from the IR on pin A0
'ADCIN 1, getIR ' get the ADC value of Ultrasonic reading from pin A1
'readMotion = ((1024 - getIR) / 8)

If 300 > getSonic > 200 then leftBackward
if 400 > getSonic >= 300 Then leftForward
if getSonic < 200 then fullStop

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html


goto main

fullForward:
PORTB = %01010000
Pause 5000
goto main

fullBackward:
PORTB = %10100000
Pause 5000
goto main

fullStop:
PORTB = %00000000
Pause 5000
goto main

leftForward:
PORTB = %01000000
Pause 5000
goto main

leftBackward:
PORTB = %10000000
Pause 5000
goto rightForward

rightForward:
PORTB = %00010000
Pause 5000
goto main

rightBackward:
PORTB = %00100000
Pause 5000
goto main

standStillLeft:
PORTB = %01100000
Pause 5000
goto main

standStillRight:
PORTB = %10010000
Pause 5000
goto main

Posted by cm1002 at December 3, 2004 08:45 PM

Comments

Post a comment




Remember Me?