« possible parts | Main | PIC Transistor test code »
December 01, 2004
Stripped Down PIC code: Nov 24
Last working PIC code stripped down due to strange shifting behavior on the B Port pins. Take it away codefrau!
BeGoodNow « PIC Test 2 - Dam Robot | Main November 25, 2004 PIC Test 3 - goddam robot'****************************************************************
'* Name : robot_code1.BAS *
'* Author : BX by C.Goodness, modified by Carlyn Maw and Christina Goodness *
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
'needed for serin and serout
include "modedefs.bas"
DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'SET PORT A TO INPUT
TRISA = %11111111
'set port b and c to output:
TRISB = %00000000
TRISC = %00000000
' ----------------------------------------------------- CONSTANTS
'movement constant
basicSpeed con 100
' ----------------------------------------------------- VARIABLES
'-- ir and ultrasonic vars (words or ints I'm not sure...)
readMotion var BYTE 'FORMULA TO GET THE IR READINGS INTO NORMAL RANGE
getDistance var BYTE 'getDistance is the IR reading
getSonic var BYTE 'getSonic is the Ultrasonic reading
' ----------------------------------------------------- START MAIN
main:
'ADCIN 0, GETDISTANCE ' get the ADC value from the IR on pin A0
ADCIN 1, GETSONIC ' get the ADC value of Ultrasonic reading from pin A1
readMotion = ((1024 - getDistance) / 8)
serout2 portc.6, 16468, [DEC getSonic, 10, 13]
HIGH PORTB.0
LOW PORTB.1
HIGH PORTB.2
LOW PORTB.3
'serout2 portc.6, 16468, [DEC readMotion, 10, 13]
'pause 1000
'GOTO MOTORCONTROL
PAUSE 50
goto main
'-----------------------------------MOTORCONTROL:
IF GETSONIC < 100 THEN
HIGH PORTB.0
LOW PORTB.1
ELSE
IF GETSONIC > 100 THEN
HIGH PORTB.1
LOW PORTB.0
ENDIF
ENDIF
IF READMOTION > 100 THEN
HIGH PORTB.2
LOW PORTB.3
ELSE
IF READMOTION < 100 THEN
HIGH PORTB.3
ENDIF
ENDIF
RETURN
Posted by christina at December 1, 2004 08:42 PM