Need help with Traffic Light Controller

Discussion in 'The Projects Forum' started by jose2529, Apr 28, 2013.

  1. jose2529

    Thread Starter New Member

    Apr 28, 2013
    4
    0
    Hello,

    I need help building the actual circuit on my breadboard for this project. The following is my code:

    Code ( (Unknown Language)):
    1.  
    2.      list    p=12F609        ; list directive to define processor
    3. #include <p12F609.inc>      ; processor specific
    4.  
    5.      __CONFIG    _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTOSCIO &_IOSCFS_4MHZ
    6.     ; _MCLRE_ON enables external Reset
    7.     ; _CP_OFF turns off "Code Protection"
    8.     ; _WDT_OFF disables the Watchdog Timer
    9.     ; _INTOSCIO selects the internal RC oscillator as the time base
    10.  
    11. ; Variable Definitions
    12.      UDATA    ; Beginning of Uninitialized Data
    13.  
    14. dc1        RES    1    ; delay loop counter
    15. dc2        RES    1    ; delay loop counter
    16. dc3        RES    1
    17.  
    18. ; Code section
    19. RESET    CODE    0x000    ; Processor resets to start of program memory
    20.  
    21.  
    22. ; MAIN
    23.  
    24. start
    25.     banksel TRISIO;
    26.     movlw b'001000';
    27.     movwf TRISIO;            Setting GP0, GP1, GP2, GP4 and GP5 as inputs
    28.  
    29.     lights_cycle
    30.  
    31.         banksel GPIO;
    32.         movlw b'100001';        
    33.         movwf GPIO;                GNS, REW ON (Figure3)
    34.         call delay;        2s
    35.         call delay;        2s
    36.         call delay;        2s
    37.         call delay;        2s
    38.  
    39.            
    40.  
    41.         banksel GPIO;
    42.         movlw b'100011';        
    43.         movwf GPIO;                GaNS, REW ON (Figure4)
    44.         call delay;        2s
    45.         call delay;        2s
    46.         call delay;        2s
    47.            
    48.  
    49.         banksel GPIO;
    50.         movlw b'100111';
    51.         movwf GPIO;                YNS, REW ON (Figure5)
    52.         call delay;        2s
    53.         call delay;        2s
    54.             ;4s delay
    55.  
    56.         banksel GPIO;
    57.         movlw b'010110';            
    58.         movwf GPIO;                GEW, RNS ON (Figure6)
    59.         call delay;        2s
    60.         call delay;        2s
    61.         call delay;        2s
    62.         call delay;        2s
    63.  
    64.         banksel GPIO;
    65.         movlw b'010100';        
    66.         movwf GPIO;                GaEW, RNS ON (Figure7)
    67.         call delay;        2s
    68.         call delay;        2s
    69.         call delay;        2s
    70.        
    71.         banksel GPIO;
    72.         movlw b'010000';        
    73.         movwf GPIO;                YEW, RNS ON (Figure8)
    74.         call delay;        2s
    75.         call delay;        2s
    76.    
    77.     goto lights_cycle
    78.  
    79.         delay
    80.             movlw     .100;
    81.             movwf     dc1;
    82.             movlw   .200;
    83.             movwf    dc2;
    84.             movlw    .07;
    85.             movwf    dc3;
    86.  
    87.            
    88.             dly1    nop         ;
    89.             decfsz    dc1,f;
    90.             goto     dly1;
    91.             decfsz    dc2,f;
    92.             goto     dly1;    
    93.             decfsz    dc3,f;
    94.             goto     dly1;
    95.    
    96.         return
    97.  
    98.     END
    99.  
    My design should meet the following:
    The order of lights should be East-West Green (8 seconds), Green Arrow (6
    seconds, flashing 2 times per second, 50% duty cycle), Yellow (4 seconds),
    and then Red. The North-South lights should follow in the appropriate
    sequence with the same timing parameters.

    Can anyone please help me with actually building the circuit please?
     
    Last edited by a moderator: Apr 29, 2013
  2. roys

    New Member

    Apr 5, 2013
    1
    0
    What does your load look like:

    How many watts is the light bulb?

    Are you powering the lights with the AC line?
     
  3. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
  4. jose2529

    Thread Starter New Member

    Apr 28, 2013
    4
    0
    Sorry I forgot to mention what I'm working with.
    I have 4 LEDS: Red, Yellow, Green and White(using as flashing green arrow)
    1 PIC12F609 and a PICkit3 to program the PIC12F609. I have the resistors for the LEDs. Also I am planning to power the circuit with the PICkit3 itself, if not then just a 5 volt power source and ground.
    Thanks again in advance.
     
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    How can you write a whole program in assembly and yet not know what goes where?:confused::confused:

    This smacks of copied code...
     
  6. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    What is then that you need? Are you going to use a solderless breadboard or perfboard or what?
     
  7. jose2529

    Thread Starter New Member

    Apr 28, 2013
    4
    0
    I'm using a solderless breadboard. I've been studying the datasheets for a while, yet I don't really know how to wire the thing, i.e. the I/O.
     
  8. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    What color LED is supposed to go on each output pin?

    Do you know how to connect the PICkit3?
     
  9. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    You have eight LEDs and only five output pins. What does that mean?
     
  10. jose2529

    Thread Starter New Member

    Apr 28, 2013
    4
    0
  11. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I haven't done this exercise, and in fact, I can't read ASM code, so I couldn't do it if I wanted to. But in the absence of any other help, my suggestion is as follows.

    You need to make a timing chart that shows what lights are on at exactly the same time, and what lights are never on at the same time as any other. That will tell you which lights can be connected to a single pin and which lights must have their own unique pin, and thus how many pins you need. Then, read your code and see which pins provide the timing you need. That will tell you which LEDs go on which pins.

    I can't stay up any longer. Good luck.
     
  12. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Did anyone notice that the device in that video was not a 12F609?
     
Loading...