Shortcut to Sumo

PIC Home Previous Page Next Page PIC Home

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14

You are ready to program

Copy and Pastable code


Be sure to create a new project first.
For a review of creating projects please go here
Paste BELOW your program name!
PROGRAM NAME CREATED VIA NEW PROJECT!!
COPY AND PASTE FROM NEXT LINE DOWN
'*************************
Dim Value as Integer
'*************************
Sub Procedure GetValue1
   TrisA = %00001100      ' Set the pulsing ports to output
   Value = 1              ' Start Value at 1
   PortA = %00000001      ' Pulse the capacitor to fill it
   Delay_ms(5)            ' Charge up the capacitor
   TrisA = %00001101      ' Set the port to collect data
   While TestBit(PortA,0) > 0   ' Loop till the capacitor
         Value = Value + 1      ' runs out of juice
   Wend
   PortB = Value         ' Display the data
   If value > 255 Then   ' If it goes over 255 then
   PortB = 255           ' Light up all the lights
   End If
End Sub
'*************************
Sub Procedure GetValue2
   TrisA = %00001100      ' Set the pulsing ports to output
   Value = 1              ' Start Value at 1
   PortA = %00000010      ' Pulse the capacitor to fill it
   Delay_ms(5)            ' Charge up the capacitor
   TrisA = %00001110      ' Set the port to collect data
   While TestBit(PortA,1) > 0   ' Loop till the capacitor
         Value = Value + 1      ' runs out of juice
   Wend
   PortB = Value         ' Display the data
   If value > 255 Then   ' If it goes over 255 then
   PortB = 255           ' Light up all the lights
   End If
End Sub
'*************************
Main:
  TrisB = %00000000
  TrisA = %00001100      ' Need two inputs for switches
  CMCON = %00000111

  While True
     While TestBit(PortA,2) = 0  ' Check left switch
         GetValue1               ' Get left data
     Wend
     While TestBit(PortA,3) = 0  ' Check right switch
         GetValue2               ' Get right Data
     Wend
   PortB = 0                     ' Clear the Port
  Wend
End.
Click here to see a Quicktime movie (.mov) of the buttercups being tested.
PIC Home Previous Page Next Page PIC Home