Hi
I translated the code.
The Sensor IR works but I canīt read the Result.
Has anybody ever tested this Code ?
I see the result by the blinking of a LED.
Even with the oscilloscope I got no Result.
Martin
Here is what I translated
Code:@ DEVICE INTRC_OSC_NOCLKOUT, MCLR_OFF DEFINE OSC 4 ' Set receive register to receiver enabled DEFINE HSER_RCSTA 90h ' Set transmit register to transmitter enabled DEFINE HSER_TXSTA 20h ' Set baud rate DEFINE HSER_BAUD 9600 ' Set SPBRG directly (normally set by HSER_BAUD) DEFINE HSER_SPBRG 25 Vo VAR PORTB.6 ' ---->sensor Input Vin VAR PORTB.7 ' <----sensor Output SERVO VAR PORTB.5 ' Servo Motor LED VAR PORTB.0 ' LED control i VAR BYTE ' loop variable Dist VAR BYTE ' result of measurement ' -----[ Initialization ]--------------------------------------------- ' init: TRISB = %10000001 ' designate portb as output PORTB = 0 ' clear portb Dist = 0 Input Vin High LED ' -----[ Main Loop ]-------------------------------------------------- ' start: GoSub sensor_control GoSub LED_Distance GoTo start ' -----[ Subroutines ]------------------------------------------------ ' sensor_control: Dist = 0 Low Vo Pause 72 For i = 0 TO 7 PulsOut Vo,15 Dist = Dist * 2 + Vin 'HSerout [DEC Dist] Next i High Vo Pause 3 Low Vo Return LED_Distance: IF (Dist > 147) Then PWM LED, 13,2 >10 5% IF (Dist < 147) AND (Dist > 119) Then PWM LED, 26,2 '10-15 10% IF (Dist < 118) AND (Dist > 91) Then PWM LED, 38,2 '15-20 15% IF (Dist < 90) AND (Dist > 81) Then PWM LED, 51,2 '20-25 20% IF (Dist < 80) AND (Dist > 71) Then PWM LED, 64,2 '25-30 25% IF (Dist < 70) AND (Dist > 65) Then PWM LED, 77,2 '30-35 30% IF (Dist < 64) AND (Dist > 55) Then PWM LED, 89,2 '35-40 35% IF (Dist < 54) AND (Dist > 50) Then PWM LED,102,2 '40-45 40% IF (Dist < 49) AND (Dist > 47) Then PWM LED,115,2 '45-50 45% IF (Dist < 46) AND (Dist > 44) Then PWM LED,140,2 '50-60 55% IF (Dist < 43) AND (Dist > 42) Then PWM LED,166,2 '60-70 65% IF (Dist < 41) AND (Dist > 40) Then PWM LED,191,2 '70-80 75% IF (Dist < 40) Then PWM LED,217,2 '>80 85% Return




Bookmarks