Wednesday, October 20, 2004

PIC Shoe Code

input portc.7
INPUT portb.7
output portc.6
inputVar VAR byte
pot1 VAR WORD ' Create variable to store result
pot2 VAR WORD
buttonVar VAR WORD


' POTENTIOMETER SETUP
' 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 result
PAUSE 500 ' Wait .5 second


'-------------------------------------------------------


main:
ADCIN 0, pot1 'potentiometer variable
ADCIN 1, pot2 'potentiometer variable
pot1 = pot1/4 'divide the value because it's too big
pot2 = pot2/4


'----------------------
' THE LISTENING CODE - puts message into inputVar
serin2 portc.7, 16468, [inputVar] 'listening for potentiometer value
if portb.7 = 1 then
    buttonVar = 1
else
    buttonVar = 0
endif


if inputVar=65 then ' if received message is 65, then respond to processing


'usage: serout2 dataPin, mode, [data]
serout2 portc.6, 16468, [pot1,pot2,buttonVar] 'talk to processing
ENDif


goto main


nodata:
return

0 Comments:

Post a Comment

<< Home