Device 16F876A
Symbol SDA_PORT = PORTC.4
SDA_PIN = PORTC.4
Symbol SCL_PORT = PORTC.3
SCL_PIN = PORTC.3
ALL_DIGITAL = true
LCD_DTPIN = PORTB.4'lcd pins DB4-DB7
LCD_RSPIN = PORTA.1 'lcd pin 4 RS
LCD_WRPIN = PORTA.2
LCD_ENPIN = PORTA.3 'lcd pin 6 EN
LCD_INTERFACE = 8 '4 'pins portb4 - portb7
LCD_LINES = 2
LCD_TYPE = 0
SLOW_BUS = On
Dim light As Byte
Dim rango As Word
Symbol srf1 = $FE
Symbol srf081 = srf1
Symbol srf2 = $E0
Symbol srf082 = srf2
Symbol cmdreg=0
Symbol lightreg=1
Dim posicion As Byte
Dim pos1 As Word
Dim pos2 As Word
Dim pos3 As Word
posicion = 0
pos1 = 1000
pos2 = 1500
pos3 = 2000
Symbol pin PORTC.0
DelayMS 200
Cls
While 1=1
BusOut $FE,$00,[$51]
BusOut srf1,cmdreg,[81]
DelayMS 80 '66
BusIn $FE,$01,[light,rango]
BusIn srf081,lightreg,[light,rango]
Print At 1,1, "Med1=" ,Dec rango, "cm ", DEC2 light,"lux "
DelayMS 100
Wend
Case 1:
If range = 10 Then
Servo pin , pos1
Cls
Print At 2,1,"Estas en frente"
DelayMS 190
Case 2:
If range = 12 Then
Servo pin,pos2
Cls
Print At 2,1,"Estas a la izq"
DelayMS 190
Case :
If range = 8 Then
Servo pin ,pos3
Cls
Print At 2,1,"Estas a la dcha"
DelayMS 190
EndIf
EndIf
EndIf
End Case