Help with simple program


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2008
    Location
    I'm From Krooklyn
    Posts
    3

    Default Help with simple program

    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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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)

  3. #3
    Join Date
    Jul 2008
    Location
    I'm From Krooklyn
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Sorry, did not provide a lot of information.

    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.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    <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
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Jul 2008
    Location
    I'm From Krooklyn
    Posts
    3


    Did you find this post helpful? Yes | No

    Default O.k.

    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.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mykewl View Post
    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.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    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
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  9. #9
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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)...

    Code:
    	@ 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.

Similar Threads

  1. Simple Blink program doesnt work.
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 1st March 2009, 21:30
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  3. simple counting program - please help!!
    By john meiers in forum mel PIC BASIC
    Replies: 3
    Last Post: - 20th February 2006, 14:17
  4. Simple RS232 Program
    By BlackNoir in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th January 2006, 01:57
  5. Simple Interrupt Program
    By eoasap in forum General
    Replies: 5
    Last Post: - 28th October 2005, 17:22

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts