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.

pic16f877 gone crazzy

Status
Not open for further replies.

jcd2diablo

New Member
i am beginner in programming pics the pic i want to programe is 16f877
the programmer i am using is pickit 2,

i successfully programmed my first led blink program and avery thing went well,
but when i wanted to do a led scorrling programe the 16f877 didint work, so i returned to the led blink programe and it didnt work also there is no output at all on the port b pins.....instead there is 5 volts on pin 32 vdd+

someone told me to turn of mclr ...but how ?
i can read and write to the microcontroller from pickit 2 with out problem

i even bought another 16f877 but no use the same problem

i am using 4mhz crystal

4.7k resistor on pin 1. and 5 volt supply
 
We'll need a schematic or a good clear macro photo of your circuit. And your code.

Use code tags when posting code. Just click the # in the Advanced posting menu just before you paste your code.
 
here is my code

symbol LED = 0

TRISB =%11111110

main:
high LED
Pause 1000
low led
pause 1000
goto main
end
 

Attachments

  • DSC09342.JPG
    DSC09342.JPG
    400.9 KB · Views: 165
Judging by the blurry pic it looks like the crystal might be on pins 13/15 instead of the required 13/14. You might have to plug it in diagonally to hit the right pins. With no oscillator the chip won't work.

I usually put the crystal just past the 20 pin and run a couple short wires down to it. But if you can fit it in there diagonally and still fit your caps then that's perfect. The closer the better.

Where are your programmer connections?
 
Last edited:
On the other hand, would the PICkit2 even see the chip if the oscillator wasn't working? Probably not.
[EDIT] Yes it will.

Is this PICBasic? Is this all the code? What tells the compiler what speed/type of oscillator you're using?
Code:
symbol LED = 0

TRISB =%11111110

main:
high LED
Pause 1000
low led
pause 1000
goto main
end
Is "symbol LED = 0" enough to tell the compiler that you want LED defined as RB0? I would think it would need more than just a "0" there. I don't use PICBasic, so I don't know.

Is PICBasic not case sensitive? You define "LED" as 0, but later refer to it as "led".

Someone told me to turn off MCLR... but how?
Leave MCLR enabled. Use a pullup resistor of anywhere from 4.7K to 33K (I like 33K) from it to VDD. Plug VPP from the PICkit2 into MCLR too.

Connect the PICkit2's 5V and Gnd to the power rails of your breadboard. And connect PGD and PGC to the corresponding PGD/PGC pins on the 877 (Pins 40 and 39). That's it.

As long as your circuit doesn't draw too much current, the PICkit2 is capable of feeding it with power (up to around 300ma is no problem). You don't need that power supply and regulator you have there for just a few LEDs.
 
Last edited:
Is the LED plugged in the right way? Is the limiting resistor too large? Try 560 Ohms to 1K Ohm.

As for MCLR, pin 1, also called RESET, you have a pullup resistor on it, so that shouldn't be a problem. You can RESET your processor by turning the power on and off, or plug a wire into ground and touch the other end to the pullup resistor lead going to pin 1.

Have you checked your power supply voltage? Is it putting out 5V, give or take a quarter Volt? That's 4.75V to 5.25V.

Does the 16F876 get really hot within a minute or less after you power up? This indicates something is VERY wrong, like the voltage is too high, but could be other things.
You name your MAIN routine MAIN: first thing, but do a GOTO MAIN (no ":"). Make sure every name, whether a variable, routine name, pin name or whatever is consistent. Of course, if this is the original program you wrote that worked at first, then carry on as normal.

Good luck on your project.
kenjj
 
nothing

my code

symbol led = 0

TRISB = %00000000 'setting all portb to out puts

main:
high led
pause 1000
low led
pause 1000
goto main
end

i doubled checked th oscillator connection but no results
this code is one of the samples provided by the compiler its also mentioned in some books.

can u explain why the led glows when i connect it to pin 32 is it supposed to give 5 volts ? ? ? ?
 
jcd2diablo said:
can u explain why the led glows when i connect it to pin 32 is it supposed to give 5 volts ? ? ? ?
Yes, I can explain that. Pin 32 is VDD. You're supposed to have it connected to your 5V power rail. Pin 31 is ground and should be connected to the ground rail.

Yes, there are two sets of VDD/VSS pins on an 877. Connect both sets.

Do you have the datasheet? If not, GO GET IT! NOW! Then refer to it constantly while programming and wiring things. Print out the most used parts, like the pinout.
 
Last edited:
Umm... Your regulator looks like it's wired wrong. Is it a 7805? You've got one of your 5V rails wired to the ground pin of the reg.

Hmm... Oh! I see! You're using one 5V rail as ground! Red (hot) is supposed to be positive (5V typically) and Blue (cold) is supposed to be ground. How confusing! :D

You really should rewire that properly, and be consistent with power polarities. If you're sloppy with that you'll eventually make a mistake and kill a PIC. They won't survive being powered backward.
 
Last edited:
OK, I have an idea. Put your LED and current limit resistor on RA0 (Pin 2) with anode to VDD and cathode to the pin.

Program your chip with one of these two known-good programs and see if the LED blinks. One program blinks faster than the other.

View attachment pic877blink.zip

EDIT: Hold on! Those won't work right with a 4MHz crystal. They're written for 20MHz. If you have a 20MHz then plug it in and do the test. Otherwise don't bother.
 
Last edited:
futz said:
On the other hand, would the PICkit2 even see the chip if the oscillator wasn't working? Probably not.
Just checked that with an 877 here and the PICkit2 sees it fine with no crystal. The PICkit2 supplies its own clock when programming. Really check that your crystal isn't on pins 13/15. In the picture it sure looks like it is. It MUST be on 13/14.
 
Last edited:
I just breadboarded up an 877 with 4MHz clock and wrote a quicky RB0 (Pin 33) blinky program for it. Program your chip with this hex file and see if it blinks. If it does, the problem is with your program. If it doesn't, the problem is with your wiring or chip or oscillator.

View attachment blinky.zip

Here are a few pics of the circuit. It's powered by the PICkit2.
pic877blink001sm.jpgpic877blink002sm.jpgpic877blinksm.jpg

Hehehe :D And even a 4.39MB AVI movie of it.

Here's the program:
Code:
	LIST P=16F877
	#INCLUDE <P16F877.INC>
	__CONFIG _XT_OSC & _WDT_OFF & _LVP_OFF

	cblock	0x20
	d1,d2,d3
	endc

	org	0x0000
init
	banksel	TRISB		;bank 1
	movlw	0x06		;configure all pins
	movwf	ADCON1		;as digital inputs
	clrf	TRISB		;PortB all outs
	banksel	PORTA		;bank 0

main	bsf	PORTB,0		;RB0 high
	call	delay
	bcf	PORTB,0		;RB0 low
	call	delay
	goto	main		;repeat forever

delay	movlw	0x03		;0.5 second
	movwf	d1
	movlw	0x18
	movwf	d2
	movlw	0x02
	movwf	d3
delay_0	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay_0
	return

	end
 
Last edited:
kjennejohn said:
Is the limiting resistor too large? Try 560 Ohms to 1K Ohm.
I'd say more like 330:eek:hm: to 470:eek:hm: but those larger values would be ok too. The LED will just be real dim.

You name your MAIN routine MAIN: first thing, but do a GOTO MAIN (no ":")
That's normal practice in any assembler/compiler I've used that requires labels to be defined with colons. You define it with a colon but call it without. :)
 
+V and GND should go to two pins each.
 
futz said:
On the other hand, would the PICkit2 even see the chip if the oscillator wasn't working? Probably not.

Actually completely the opposite, if the oscillator is running, it's impossible to enter programming mode - in order to enter programming mode on an ICSP you have to stop the oscillator first (done by grounding MCLR).
 
Nigel Goodwin said:
Actually completely the opposite, if the oscillator is running, it's impossible to enter programming mode - in order to enter programming mode on an ICSP you have to stop the oscillator first (done by grounding MCLR).

That's why VPP before VDD is sometimes nessary, you've got to get into programming mode before the clock starts running.
 
blueroomelectronics said:
That's why VPP before VDD is sometimes nessary, you've got to get into programming mode before the clock starts running.

As long as you do it fast enough, Vdd before Vpp works fine - but too slow, and you're stuffed! :D
 
Fast as Fast can bee

Nigel,

You mean before the oscillator gets up to speed. So you pull the rug out from under it.:D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top