Controlador para semáforos
Autor:
Me gusta:
Motivado por un reporte sobre las señales del tránsito aparecido en la sección “Cuba dice”, del Noticiero Nacional de Televisión, donde un ingeniero explica que un control para semáforos le cuesta a Cuba adquirirlo en China unos cuatro mil dólares, el autor, vecino del poblado pesquero de Punta Alegre, municipio de Chambas en la provincia de Ciego de Ávila, pone a disposición de los interesados un circuito que permitirá hacerlos, utilizando apenas unos cuantos diodos led de alto brillo.
Figura 1: (Esquema eléctrico)
Código ASM
LIST p=16F84 ; PIC16F844 is the target processor
#include "P16F84.INC" ; Include header file
CBLOCK 0x10 ; Temporary storage
state
l1,l2
ENDC
org 0 ; Start up vector.
goto setports ; Go to start up code.
org 4 ; Interrupt vector.
halt goto halt ; Sit in endless loop and do nothing.
setports clrw ; Zero in to W.
movwf PORTA ; Ensure PORTA is zero before we enable it.
movwf PORTB ; Ensure PORTB is zero before we enable it.
bsf STATUS,RP0 ; Select Bank 1
clrw ; Mask for all bits as outputs.
movwf TRISB ; Set TRISB register.
bcf STATUS,RP0 ; Reselect Bank 0.
initialise clrw ; Initial state.
movwf state ; Set it.
loop call getmask ; Convert state to bitmask.
movwf PORTB ; Write it to port.
incf state,W ; Increment state in to W.
andlw 0x04 ; Wrap it around.
movwf state ; Put it back in to memory.
call wait ; Wait :-)
goto loop ; And loop :-)
; Function to return bitmask for output port for current state.
; The top nibble contains the bits for one set of lights and the
; lower nibble the bits for the other set. Bit 1 is red, 2 is amber
; and bit three is green. Bit four is not used.
getmask movf state,W ; Get state in to W.
addwf PCL,F ; Add offset in W to PCL to calc. goto.
retlw 0x41 ; state==0 is Green and Red.
retlw 0x23 ; state==1 is Amber and Red/Amber
retlw 0x14 ; state==3 is Red and Green
retlw 0x32 ; state==4 is Red/Amber and Amber.
; Function using two loops to achieve a delay.
wait movlw 5
movwf l1
w1 call wait2
decfsz l1
goto w1
return
wait2 clrf l2
w2 decfsz l2
goto w2
return
END
Programación en hexadecimal para el microcontrolador Pic 16f84 (componente electrónico que se necesita para la fabricación)
:020000040000FA
:020000000528D1
:08000800610003018500860080
:1000100083160301860083120301900015208600D9
:10002000100A043990001B200E2810088207413462
:10003000233414343234053091002120910B1D28D3
:0A00400008009201920B222808002C
:00000001FF
Añadir nuevo comentario