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.

Code not working on pic 16F874A

Status
Not open for further replies.

pixelpunch

New Member
Just to give a little background, I am trying to flash all the leds on and off at a certain interval on port d. Each led is wired to the pic so that each pin sinks the current and a resistor controls the amount of current.

For some reason, the leds just stay on and do not flash.

Here is my code below:
Code:
; initialization stuff
list p=16f874A			; set the pic type
__config B'11111110111001'	; set configuration bits

include "p16f874A.inc"		

	;Using general purpose registers
	cblock 	0x20 
		temp  
		temp2
		temp3
	endc

        
         org 0x0000
         bsf STATUS,RP0	;select bank 1
         movlw 0x00
         movwf TRISD
         bcf STATUS,RP0 ; back to Register Page 0


Loop
	call Setup
	call Delay
	movlw 0xFF
   	movwf PORTD
        call Setup
        call Delay
        movlw 0x00
   	movwf PORTD
 	goto Loop

Setup   
	movlw	0xFF
	movwf	temp
 	movwf   temp2
	movwf  	temp3
	return 

Delay
	decfsz	temp, 1
	goto    $+2
        decfsz	temp2, 1
	goto  	$+2
	decfsz 	temp3, 1
	goto 	Delay
	return
  
end

Thanks
 
Your delay routine is a little long - about 2 minutes assuming you are using a 4MHz crystal! What are you using as a clock source?

You also have LVP enabled.

Mike.
 
Well, I am using a 20MHz crystal. I don't think the delay is the problem because the leds stayed lit for over an hour.

Could LVP be the probem?
 
You need a pull down on RB3 if you have LVP enabled. Easier to disable it if you don't use it.

Mike.
 
Disable the LVP, as suggested. A 20 MHz crystal is a HS oscillator, try to change the oscillator selection bits.
 
Works great now. I disabled LVP and changed the oscillator type to a HS type in the configuration register.

Thank you all again for your help.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top