JOEYTRONICS.COM

Joey's Electronics Site    

 
 | Home | Ohm's Law | Resistors | Capacitors | Inductors | Op Amps |
 | Diodes | Transistors | The 555 Timer | Logic Gates | Pspice Tutorials | Projects |  DataSheets |
 | E-Mail |

          This circuit was constructed using a PIC16F84 microcontroller.

                                     Schematic

      

 

                                                              Breadboard Prototype

              

        

       The actual traffic lights were constructed with plastics from a local plastics store.

                              The car was added just for fun.

 

              

 

                                                 PIC Assembly Code

 

;                     Title "Traffic Lights"

;                     list P=16F84A
;JHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJ
;JH                                                              HJ
;JH                        TRAFFIC LIGHTS                        HJ
;JH                BY JOEY HERNANDEZ - TCI86508                  HJ
;JH                                                              HJ
;JH                                                              HJ
;JHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJHJ
; ------------------
; CONFIGURATION FUSE
; ------------------
;
; __CONFIG 0x3FFB

;
; This program simulates two traffic lights
; The Light Emmiting Diodes are connected to PortB, pins RB2 - RB7
;
;
;
STATUS equ 0x03
RP0 equ 0x05
PORTA equ 0x05
PORTB equ 0x06
TRISA equ 0x85
TRISB equ 0x86

DelayA equ 0x0C ; delay register
DelayB equ 0x0D ; delay register
DelayC equ 0x0E ; delay register
DelayD equ 0x1C ; delay register
DelayE equ 0x2D ; delay register
DelayF equ 0x3E ; delay register
;
;
; START
;
;
                  org 0h ; startup address = 0000


                  movlw b'00000000'
                  movwf PORTA ; all PORTA pins = 0
                  movlw b'11111111'
                  movwf PORTB ; all PORTB pins = 1
                  bsf STATUS,RP0 ; set RP0 for RAM page 1
                  movlw b'00000000' ; all PortA = outputs
                  movwf TRISA
                  movlw b'00000000' ; all PortB = outputs
                  movwf TRISB
                  bcf STATUS,RP0 ; set RP0 for RAM page 0




MainLoop

                  movlw b'10111011' ; yellow red
                  movwf PORTB
                  call Delay2 ; execute a 4 Second delay

                  movlw b'11011011' ; red red
                  movwf PORTB
                  call Delay2 ; execute a 4 Second delay

                  movlw b'11001111' ; red green
                  movwf PORTB
                  call Delay1 ; execute a 24 Second delay

                  movlw b'11010111' ; red yellow
                  movwf PORTB
                  call Delay2 ; execute a 4 Second delay

                  movlw b'11011011' ; red red
                  movwf PORTB
                  call Delay2 ; execute a 4 Second delay

                  movlw b'01111011' ; green red
                  movwf PORTB
                  call Delay1 ; execute a 24 Second delay
                  goto MainLoop ; do this loop forever
;
; --------------------------------
; SUBROUTINE: waste time for 500mS
; --------------------------------
;
Delay1            clrf DelayA ; clear DelayL to 0
                  clrf DelayB ; clear DelayM to 0
                  movlw 99h ; set DelayC to 3
                  movwf DelayC
Wait1             decfsz DelayA ; subtract 1 from DelayA
                  goto Wait1 ; if not 0, goto Wait1
                  decfsz DelayB ; subtract 1 from DelayB
                  goto Wait1 ; if not 0, goto Wait1
                  decfsz DelayC ; subtract 1 from DelayC
                  goto Wait1 ; if not 0, goto Wait1
                  return ; finished the delay



Delay2            clrf DelayD ; clear DelayL to 0
                  clrf DelayE ; clear DelayM to 0
                  movlw 21h ; set DelayF to 3
                  movwf DelayF
Wait2             decfsz DelayD ; subtract 1 from DelayD
                  goto Wait2 ; if not 0, goto Wait1
                  decfsz DelayE ; subtract 1 from DelayE
                  goto Wait2 ; if not 0, goto Wait1
                  decfsz DelayF ; subtract 1 from DelayF
                  goto Wait2 ; if not 0, goto Wait1
                  return ; finished the delay


                  end  

end