Вы находитесь на странице: 1из 6

Forma en que se trenzan los conductores.

Conexiones "normal" y "cruzado".


Esquema eléctrico del emisor.
Diagrama del receptor.

'----- CONFIGURO PUERTOS-----


'Configuro el portA:
TRISA.0 = 0 'Salida (LED 1)
TRISA.1 = 0 'Salida (LED 2)
TRISA.2 = 1 'Entrada (Pulsador 1)
TRISA.3 = 1 'Entrada (Pulsador 2)
TRISA.4 = 0 'Salida (NO USADO)

'Configuro el portB:
TRISB.0 = 0 'Salida
TRISB.1 = 0 'Salida
TRISB.2 = 0 'Salida
TRISB.3 = 0 'Salida
TRISB.4 = 0 'Salida
TRISB.5 = 0 'Salida
TRISB.6 = 0 'Salida
TRISB.7 = 0 'Salida

'------VARIABLES Y CONSTANTES------------------

'Defino constantes:
Symbol led1 = PORTA.0 'LED 1
Symbol led2 = PORTA.1 'LED 2
Symbol p1 = PORTA.2 'Pulsador 1
Symbol p2 = PORTA.3 'Pulsador 2

'Variables
Dim aux As Word
Dim i As Byte
Dim flag As Bit
aux = 0
flag = 0
i=0

'----COMIENZA EL PROGRAMA EN SI-----


'Apago todos los leds del emisor
led1 = 0
led2 = 0

loop: 'Bucle principal del programa


'Veo si se pulso algun boton
If p1 = 1 Then 'Presionaron el pulsador 1
Gosub cablenormal
Endif

If p2 = 1 Then 'Presionaron el pulsador 2


Gosub cablecruzado
Endif

Goto loop 'Repite eternamente


End

cablenormal: 'Enciende Leds en orden 1-2-3-4-5-6-7-8

led1 = 1 'Enciendo el LED1 (indicador de funcion)


aux = 1 'Led Encendido: el 8
flag = 0 'Asumo el otro boton sin pulsar

While flag = 0 'mientras No se pulse el otro, funciona.


If aux = 1 Then 'Enciendo LED 1
PORTB = %10000000
Endif

If aux = 2 Then 'Enciendo LED 2


PORTB = %01000000
Endif

If aux = 3 Then 'Enciendo LED 3


PORTB = %00100000
Endif

If aux = 4 Then 'Enciendo LED 4


PORTB = %00010000
Endif

If aux = 5 Then 'Enciendo LED 5


PORTB = %00001000
Endif

If aux = 6 Then 'Enciendo LED 6


PORTB = %00000100
Endif

If aux = 7 Then 'Enciendo LED 7


PORTB = %00000010
Endif

If aux = 8 Then 'Enciendo LED 8


PORTB = %00000001
aux = 0 'Pongo a uno para reiniciar la cuenta
Endif

aux = aux + 1

For i = 1 To 255 '255


WaitMs 1 'espera 1/1000 de segundo.
If p2 = 1 Then 'Se pulso el otro boton
flag = 1 'Pongo el flag para salir de la rutina
PORTB = %00000000 'Apago todos los leds
led1 = 0 'Apago el led "piloto"
WaitMs 500 '500 milisegundos para darle tiempo a soltar el boton
i = 255
Endif
Next i

Wend
Return

cablecruzado: 'Enciende Leds en orden 1-2-4-3-6-5-7-8

led2 = 1 'Enciendo el LED2 (indicador de funcion)


aux = 1 'Led Encendido: el 8
flag = 0 'Asumo el otro boton sin pulsar

While flag = 0 'mientras No se pulse el otro, funciona.


If aux = 1 Then 'Enciendo LED 3
PORTB = %00100000
Endif

If aux = 2 Then 'Enciendo LED 6


PORTB = %00000100
Endif
If aux = 3 Then 'Enciendo LED 1
PORTB = %10000000
Endif

If aux = 4 Then 'Enciendo LED 4


PORTB = %00010000
Endif

If aux = 5 Then 'Enciendo LED 5


PORTB = %00001000
Endif

If aux = 6 Then 'Enciendo LED 2


PORTB = %01000000
Endif

If aux = 7 Then 'Enciendo LED 7


PORTB = %00000010
Endif

If aux = 8 Then 'Enciendo LED 8


PORTB = %00000001
aux = 0 'Pongo a uno para reiniciar la cuenta
Endif

aux = aux + 1

For i = 1 To 255 '255


WaitMs 1 'espera 1/1000 de segundo.
If p1 = 1 Then 'Se pulso el otro boton
flag = 1 'Pongo el flag para salir de la rutina
PORTB = %00000000 'Apago todos los leds
led2 = 0 'Apago el led "piloto"
WaitMs 500 '500 milisegundos para darle tiempo a soltar el boton
i = 255
Endif
Next i

Wend
Return

Вам также может понравиться