Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Traffic Light for pic 16f874a not working

Status
Not open for further replies.

henrock

New Member
list p=16f874a
#include <p16f874a.inc> ;

__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
 
this is the schematic
tradd-jpg.48413
 
You should make it a habit of putting
Code:
 tags around your program code so that the spaces and tabs are intact.
Highlight your code and select the [B]#[/B] button just above the message box.

You should also mention what the code is [I]supposed[/I] to do as well as what it [I]currently[/I] does.

[CODE]list      p=16f874a          
	#include <p16f874a.inc>        ;

	__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


What's the purpose of the interrupt? It looks like this was some sort of learning exorcise about interrupts and context saving.

The rest of the code just toggles two outputs HIGH and LOW really fast since it has no delay.
 
Last edited:
Thats the default code from the template or example files.

Code:
        bsf  PORTB,0  ;turn on the red light
        //ADD DELAY
        bsf  PORTB,1  ;turn on the green light
        //ADD DELAY
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top