1. You can now buy finished microcontroller project from us, Check out the Store for the complete list of projects.
  2. Need a custom project, Send us some details about your project. So that we can quote the price for it.

PIC Traffic Light Controller using PIC microcontroller 1.0

Traffic Light Controller using PIC microcontroller

  1. Indira
    Traffic Light Controller using PIC microcontroller. The download contains the PIC asm code and the proteus simulation file.

    Sponsored Links

    Circuit Diagram
    Project Pic.gif
    Code
    Code (Text):
    1.           LIST    p=16F84 ; PIC16F844 is the target processor
    2.  
    3.           #include "P16F84.INC" ; Include header file
    4.  
    5.           CBLOCK 0x10  ; Temporary storage
    6.               state
    7.               l1,l2
    8.           ENDC
    9.  
    10.           org    0              ; Start up vector.
    11.           goto    setports        ; Go to start up code.
    12.  
    13.       org    4              ; Interrupt vector.
    14. halt      goto    halt            ; Sit in endless loop and do nothing.
    15.  
    16. setports  clrw                    ; Zero in to W.
    17.           movwf  PORTA          ; Ensure PORTA is zero before we enable it.
    18.           movwf  PORTB          ; Ensure PORTB is zero before we enable it.
    19.           bsf    STATUS,RP0      ; Select Bank 1
    20.           clrw                    ; Mask for all bits as outputs.
    21.           movwf  TRISB          ; Set TRISB register.
    22.           bcf    STATUS,RP0      ; Reselect Bank 0.
    23.  
    24. initialise clrw                    ; Initial state.
    25.           movwf  state          ; Set it.
    26.  
    27. loop      call    getmask        ; Convert state to bitmask.
    28.           movwf  PORTB          ; Write it to port.
    29.           incf    state,W        ; Increment state in to W.
    30.           andlw  0x03            ; Wrap it around.
    31.           movwf  state          ; Put it back in to memory.
    32.           call    wait            ; Wait :-)
    33.           goto    loop            ; And loop :-)
    34.  
    35.           ; Function to return bitmask for output port for current state.
    36.           ; The top nibble contains the bits for one set of lights and the
    37.           ; lower nibble the bits for the other set. Bit 1 is red, 2 is amber
    38.           ; and bit three is green. Bit four is not used.
    39. getmask    movf    state,W        ; Get state in to W.
    40.           addwf  PCL,F          ; Add offset in W to PCL to calc. goto.
    41.           retlw  0x41            ; state==0 is Green and Red.
    42.           retlw  0x23            ; state==1 is Amber and Red/Amber
    43.           retlw  0x14            ; state==3 is Red  and Green
    44.           retlw  0x32            ; state==4 is Red/Amber and Amber.
    45.  
    46.           ; Function using two loops to achieve a delay.
    47. wait      movlw  5
    48.           movwf  l1
    49.  
    50. w1        call    wait2
    51.           decfsz  l1
    52.           goto    w1
    53.  
    54.           return
    55.  
    56.  
    57. wait2      clrf    l2
    58. w2        decfsz  l2
    59.           goto    w2
    60.           return
    61.           END
    62.  

Recent Reviews

  1. Dionisio
    Dionisio
    5/5,
    Version: 1.0
    good job ...
Loading...