Traffic Light

Status
Not open for further replies.
Hello!
can any one help me. I dont see why my circuit does not work. I am expecting a red light from the first trafic light to be on and the green light from the second traffic light to be on.
below is my code
Code:
   list        P=16F877a
   include    "P16F877a.inc"
                __config _RC_OSC & _WDT_OFF & _CP_OFF

;Declarations:

	
    portb  equ   06
            org       1FF
            goto      Start
            org       0
		

;Subroutines:

Init 
        clrw                             ; Zero.
        movwf   portb	           ;resets input/output ports
        bsf     STATUS,RP0      ; Select Bank 1
        movlw   b'00000000'      ; Set port B bits as outputs
        tris	portb                  ; Set TRISB register. 
        bcf  STATUS,RP0      ; Select Bank 0  
        retlw 0
	
;Program Start:

Start
		call Init

Main
        bsf  portb,0  ;turn on the red light
        bsf  portb,1  ;turn on the green light
        goto Main
        END
I have attached the hex file and my traffic design of proteus
 

Attachments

  • traffic.zip
    12.2 KB · Views: 233
  • circuit.jpg
    181.6 KB · Views: 533
Last edited:
When do the lights turn off? I do not see any code that makes the lights turn off!

Code:
Main
        bsf  portb,0  ;turn on the red light
        bsf  portb,1  ;turn on the green light
        goto Main
        END

They should be in a different order, well at-least here in the USA.
Green, then Yellow, then Red (then start over again) for USA traffic lights

Pardon me, but I haven't done any PIC programming yet, but I have done Arduino programming. Don't know how much different it is.
 
Last edited:
yeah I would come to reality, I just wanted to test the lights. If the lights could be on then I would be able to finish this project

You will need to have a delay, and then turn the lights off, and then another delay. You can fiddle around and have them turn on and off in any order if you like.

Can your PIC communicate with your computer?
Does your PIC even have power?
Did you double-check/triple check your connections?

I am just trying to find the problem, but if it is a code problem Mikebits, 3v0, or some of the others will be able to help you.
 
Go here on your PC: C:\Program Files\Microchip\MPASM Suite\Template\Code
Be aware this code is not tested and i havent played with ASM in a long long long time.

You will find examples in ASM... take a example for that PIC and place your code in it.
Code:
	list      p=16f877            ; list directive to define processor
	#include <p16f877.inc>        ; processor specific variable definitions

	__CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _RC_OSC & _WRT_ENABLE_ON & _LVP_ON & _DEBUG_OFF & _CPD_OFF


;***** VARIABLE DEFINITIONS
w_temp        EQU     0x7E        ; variable used for context saving
status_temp   EQU     0x7F        ; variable used for context saving

;**********************************************************************
		ORG     0x000             ; processor reset vector
		clrf    PCLATH            ; ensure page bits are cleared
  		goto    Main              ; go to beginning of program


		ORG     0x004             ; interrupt vector location
		movwf   w_temp            ; save off current W register contents
		movf	STATUS,w          ; move status register into W register
		movwf	status_temp       ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


		movf    status_temp,w     ; retrieve copy of STATUS register
		movwf	STATUS            ; restore pre-isr STATUS register contents
		swapf   w_temp,f
		swapf   w_temp,w          ; restore pre-isr W register contents
		retfie                    ; return from interrupt
Init 
        clrw                 ; Zero.
        movwf   PORTB        ; resets input/output ports
        bsf     STATUS,RP0   ; Select Bank 1
        movlw   b'00000000'  ; Set port B bits as outputs
        movwf   TRISB        ; Set TRISB register.
        bcf  STATUS,RP0      ; Select Bank 0
        retlw 0
Main
        call Init
loop
        bsf  PORTB,0  ;turn on the red light
        bsf  PORTB,1  ;turn on the green light
        goto loop
        END

Code tested and works:
 

Attachments

  • tradd.jpg
    73.3 KB · Views: 2,078
Last edited:
Where did you get that traffic light symbol? it has no DLL for it. Thats why its not working and your code also....

This image is with my HEX with the above code i told you about.

 

Attachments

  • traff.jpg
    67.5 KB · Views: 922
Last edited:
thanks guys and AtmoSoft, I have been playing around with your circuits Until I realised that my circuit was wrong, the traffic lights needed to be grounded. and after I start my program at 0X00. Then it works fine. now Im gonna build a complete real time traffic light.
 

Attachments

  • traffic.jpg
    68.8 KB · Views: 380
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…