PDA

View Full Version : Help with simple program



mykewl
- 30th July 2008, 21:24
I'm trying to program a pic16F877A so that it would flash a LED on and off. I wrote the following program but I can't seem to get it to work. Any clues on where the problem lies or what I might have done wrong?


Thank you

Symbol LED = 0
TRISC = %11111110 'RC0 set as output
main:
High LED
Pause 1000
LOW LED
Pause 1000
goto main
End

Melanie
- 30th July 2008, 21:57
Rather than Symbol LED=0 try...

LED var PortC.0

Other common problems are...

1. You've not got a suitable Crystal or Resonator attached.
2. You've not defined a correct Oscillator setting (Config Fuses)
3. You've not handled MCLR pin properly by tying it to Vdd
4. You've forgotten to pay your electricity bill... (see also "I've got a flat Battery")
5. You've got the LED connected the wrong way around... (and might not have a suitable series resistor)

mykewl
- 30th July 2008, 22:26
Thank you for such a fast reply.

I'm sorry I did not include all the information required to make a proper assesment. So with this in mind here I go again:

I'm using a PIC development board that provides all necessary connections. I.E. MCLR tied to +5 volts via a series resistor, 4 mhz crystal prewired with proper caps and LED's cathode tied to RC0 whilst the anode is connected to a series resistor tied to 5 volts. All voltages are prewired and supplied via a 12 volts transformer and stepped down with a 7805 voltage regulator. If I run a sample program that is supplied with the development board the PIC IC and the peripherals all work properly. My guess, as per your suggestion, is that my problem is in the "config fuses" portion of the program. So my next course of action would be to read up on this topic and see how to configure this requirement. However, if it is not too much trouble, could you point me in the right direction?

Thank you for your time.

Archangel
- 31st July 2008, 02:46
<b>FAQ</b> is not a cryptic way of cussing someone out, Melaine herself wrote this one, now about 14 posts down: http://www.picbasic.co.uk/forum/showthread.php?t=543

mykewl
- 31st July 2008, 04:36
Humm, yeah, now I know what you mean. I will read the faq and become a bit more informed about the rules. Sorry.
As far as the "config fuses" setting: isn't this set when I chose the pic16f877A I.C. before compiling with picbasic pro with Microcode studio? I'm really, really new to this and I'm trying to get a steady footing (basically I'm balancing myself on a tooth pick with my big toe). Thanks for the help. I will try to hammer out the details through trial and error.

Peace.

mackrackit
- 31st July 2008, 05:58
Welcome to the world of PICs.

The fuses or configs are set once at program time. Each chip has similar settings but some have more or less. ??

Example, the type of OSC used is set here, not the speed. Settings can be anything from internal, RC, crystal, or resonator. This is where the data sheet comes in handy.

The thread that Joe pointed to tells how to set the fuses in the code. When you read the thread and get to the post from misterE you will notice the *.inc file mentioned. The *.inc is the main fuse file for PBP. You can change things there and not have to put the settings in each code. Either way has advantages.

When you post problem code, it will help if you post all of it, not just the part you think is the problem, also it helps if you tell a little how you have it connected to other parts.

Archangel
- 31st July 2008, 06:27
Humm, yeah, now I know what you mean. I will read the faq and become a bit more informed about the rules. Sorry.
As far as the "config fuses" setting: isn't this set when I chose the pic16f877A I.C. before compiling with picbasic pro with Microcode studio? I'm really, really new to this and I'm trying to get a steady footing (basically I'm balancing myself on a tooth pick with my big toe). Thanks for the help. I will try to hammer out the details through trial and error.

Peace.
No need for apology ! I was Grinnin' like the Cheshire cat when I wrote that :) The inc file Mackracket refers to has a Config setting by default, maybe not what you want. I think it is there so newbies can get their first projects going, assuming they use 4mhz resonators. You may want a 20 mhz osc, or turn WDT on or off or not use MCLR line as reset. That's why we comment them out and set them in every program, I usualy cut and paste from a prior project, only trips me up when I use a different PIC then I go look up the proper syntax. I use only MPASM not PM as assembler. Why, because most of the people here who are willing to help use MPASM and it makes my code instantly compatible, also less junk to type, and it is the OFFICIAL assembler of MICROCHIP. There is a whole bunch of good information in the FAQs, the stuff all the books out there forgot.

paul borgmeier
- 31st July 2008, 08:39
I do not know if your Configs are correct but you have additional problems ...

On the 877A

High 0

sets PortB Pin 0 high, not PortC, Pin 0. See manual section 4.11 and then implement Melanie's suggested fix above for this.

Good Luck

Melanie
- 31st July 2008, 08:58
To get you started, here's a set of Configs for the 876A (you can easilly change this for 877A) to be used with the MELABS default PM Assembler (not Microchips MPASM)...



@ DEVICE pic16F876A, HS_OSC ' System Clock Options
@ DEVICE pic16F876A, WDT_ON ' Watchdog Timer
@ DEVICE pic16F876A, PWRT_ON ' Power-On Timer
@ DEVICE pic16F876A, BOD_ON ' Brown-Out Detect
@ DEVICE pic16F876A, LVP_OFF ' Low-Voltage Programming
@ DEVICE pic16F876A, CPD_OFF ' Data Memory Code Protect
' Set to CPD_ON for Release Copy
@ DEVICE pic16F876A, PROTECT_OFF ' Program Code Protection
' Set to PROTECT_ON for Release
@ DEVICE pic16F876A, WRT_OFF ' Flash Memory Word Enable


Now call me old-fashioned, but I don't use Microcode Studio... and I would compile my program from a Windows DOS box with the command line...

PBPW -p16F876A myprogram -v

If your program is small, you can also use...

PBP -p16F876A myprogram -v

but once it's complexity exceeds a certain limit, you will get "Out of Memory" errors when you compile, and you'll have to use PBPW rather than just PBP.