View Single Post
  #2   Spotlight this post!  
Unread 11-06-2008, 15:56
dtengineering's Avatar
dtengineering dtengineering is offline
Teaching Teachers to Teach Tech
AKA: Jason Brett
no team (British Columbia FRC teams)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Vancouver, BC
Posts: 1,829
dtengineering has a reputation beyond reputedtengineering has a reputation beyond reputedtengineering has a reputation beyond reputedtengineering has a reputation beyond reputedtengineering has a reputation beyond reputedtengineering has a reputation beyond reputedtengineering has a reputation beyond reputedtengineering has a reputation beyond reputedtengineering has a reputation beyond reputedtengineering has a reputation beyond reputedtengineering has a reputation beyond repute
Re: PIC16F877 not executing?

The MCLR statement may be meaningful. It sounds like you are pretty familiar with PICs and stuff, so if I over-simplify this response, it is only to make it useful for those less familiar with the chips.

MCLR is a master reset switch, it stands for "Master Clear Reset" or something like that. If you connect it to ground, then the whole chip resets. You will note that on many PICs it is located next the the ground pin, making it easy to short the two out using a screwdriver tip, thus making it very easy to reset the PIC.

The catch is that if you don't connect the MCLR pin to something, then the voltage just kind of "floats"... in other words, it is fairly random. Yesterday it might have been high, today it might be low. To solve this problem, MCLR is typically connected to the +5 line (or whatever voltage is supplying your PIC) with a resistor. The value of the resistor doesn't really matter that much... all you are doing is making sure that the MCLR pin stays "high" except when you short it to ground.

Now, to compound things just a little bit, the PIC uses many pins for many different functions... the MCLR pin, for instance, can also be used as an I/O line (although on many PICs it can only be used as an input, I believe). If you choose to use it as an input, you cannot use it as a reset... and vice versa. You have to let the PIC know whether you want to use the MCLR pin as an input or as a reset when you download your program code. You do this by toggling a configuration bit called "MCLR Reset Enable". You can either write your configuration settings into your code (overwriting your complier/assembler's default settings), or just set them via the configuration menu of your programming software. Just make sure that if you do the setting in you programming software that if you have a "reload code before programming" option that it is turned off, or you will get the default settings back again!

So, my first suggestion is to connect the MCLR pin to your +5 supply with a resistor. Try that and see if it works. Otherwise turn off the MCLR Enable bit in your programming software and re-download your code to the PIC.

No guarantees that this is what is causing you grief, but just a couple of things that spring to mind that might be worth checking.

Jason

Edit: And if that isn't enough already, the MCLR pin is also often used to set the PIC into high-voltage programming mode... your programming device quite likely pops MCLR up to 12v at the beginning of your code download. Something to keep in mind when doing in-circuit (where you don't take the chip off the board) programming!

Last edited by dtengineering : 11-06-2008 at 15:59.