Trouble with most basic BLINK on PIC 16F819


Closed Thread
Results 1 to 13 of 13
  1. #1

    Default Trouble with most basic BLINK on PIC 16F819

    Hi folks

    I'm having an impossible time getting anything with this PIC 16F819 chip (http://www.microchip.com/wwwproducts...=en010227)...I can't get the most basic program outputting a blinking LED:

    Code:
    'OSCCON = %01100100
    'OSCCON = %01100110
    OSCCON = $60 'set int osc to 4mhz
    TRISA = %00000000 'set RA0 to output
    ADCON1 = 2
    
    Main:   
       High PORTA.0    ' Turn on LED connected to PORTB.0
       Pause 1000       ' Delay for .5 seconds
    
       Low PORTA.0     ' Turn off LED connected to PORTB.0
       Pause 1000       ' Delay for .5 seconds
    
       Goto main       ' Go back to loop and blink LED forever
       End
    I've checked, double-checked, triple-checked the settings and tried a whole variety of things. I'm compiling with "INTRC" set as oscillator. I've got power going in on the fifth pin on the right side (Vdd, a.k.a. pin 14), and going to ground on the fifth pin on the left side (Vss a.k.a. pin 5). I've got a 100 Kohm resistor on the fourth pin on the left going to power. I've got my 220 ohm resistor w/led (both of which I've tested to make sure they function in the most basic circuit) oriented properly on the second pin down on the left side (which as I understand it is PORTA.0 per pin diagram on datasheet, a.k.a. pin '17').

    Programming seems to work fine; I'm using the melabs U2 programmer. The programming software compiles fine with positive message all along the way, and I can see the U2 responding (via green-red-green led) as I do so. All the configurations options you see above (OSCCON, TRISA, ADCON1 settings) have been at one point removed, set to something else, etc. etc. etc. in all possible variations I could think of. Pointless!

    I'm completely stumped. I can't get a freaking led to blink. I've been working on this for hours! I've reviewed a lot of the forum too, but apologize if I missed something obvious...

    Any help would be greatly appreciated.

    Thank you!!!

    Best,
    Dave

  2. #2


    Did you find this post helpful? Yes | No

    Default

    By the way, that link should be

    http://www.microchip.com/wwwproducts...cName=en010227

    Sorry!

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    ADCON1=2
    This will set all pin to analog, hence why you experiment some problem

    Try
    ADCON1=7
    This will disable all analog stuff.

    100K for MLCR is tad high. Something <10K is more standard.

    Double check your config fuses setting, INTRC, MCLR and LVP. LVP should be set to off.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Here's some handy links for you

    PortA Doesn't Work
    http://www.picbasic.co.uk/forum/showthread.php?t=561


    Presetting Configuration Fuses (PIC Defines) into your Program
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    These are some of the configuration data that I 'embed' at the top of the source file to inform the programmer which fuses to set. This, of course, is for a PIC16F917. You will need to check which fuses apply for the 819 and set them accordingly.

    Code:
    @  device  pic16f917
    @  device  INTRC_OSC_NOCLKOUT,WDT_OFF,PWRT_ON,MCLR_OFF
    @  device  PROTECT_ON,BOD_OFF,CPD_ON,IESO_OFF,FCMEN_ON
    
    define     NO_CLRWDT    1
    define          OSC     4       ' OSCCON defaults to 4MHz on reset

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Here's some handy links for you

    PortA Doesn't Work
    http://www.picbasic.co.uk/forum/showthread.php?t=561


    Presetting Configuration Fuses (PIC Defines) into your Program
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    These 2 links should be required reading to register here. IMHO
    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.

  7. #7


    Did you find this post helpful? Yes | No

    Default Thanks everyone!

    Thanks everyone for responding so fast with such detailed help!! I am at work now but will give these things a shot when I get home, including reading through the docs you linked to.

    One question to Steve (mister_e) though: I thought what I was doing with going high and low out on the pin was analog out, no? Or am I confused about what analog/digital means in this case? Does analog give me a potential range of values vs. digital giving me just two (high/low a.k.a. on/off a.k.a. 0/1) values? As I write it out it seems more and more obvious to me...

  8. #8


    Did you find this post helpful? Yes | No

    Default Okay, getting closer.

    So, I've read through the docs and things are starting to be much more clear, I'm understanding what is important in the data sheet vs. not. I think I'm almost there but what I'm seeing is the led going on once when I power up but then stopping. Does this sound familiar to any of you?

    Thanks again for all your help--

    Best,
    Dave

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Well this doesn't sounds familiar, unless the configuration fuses are not properly programed by your Device Programmer.

    Program your PIC, read it back. See if the config fuses stay the same.

    You could still post your .HEX file here (change the extension to .TXT), so we could try it world-wide
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi,

    as default OSC comes in HS mode ... did you just try to run your PIC with a simple 4Mhz Xtal and its pair of caps ???

    My two cents ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11


    Did you find this post helpful? Yes | No

    Default I got it!

    Hi folks,

    I finally figured it out through fastidiously reading through the docs you linked to and testing out all the settings I could. My led is blinking away happily now. It's amazing what a sense of accomplishment such a small thing can provide!

    However, I'm having trouble with one other element: whenever I try to load the config fuses in the code I get an assembler error:

    Code:
    @ __config _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _MCLR_OFF & _BODEN_OFF & _LVP_OFF
    I'm using MPASM, and so I've checked these against the names used in the PIC16F819 file as described by Melanie here. But whenever I try to compile I get the message

    "Error[118] c:\docume~1\dave\desktop\dd_pic\blink.asm 44: Overwriting previous address contents (2007)"

    However, if I turn off "Update configuration from file" in the programmer, comment out this line, and set the config fuses manually in the programmer config, I can get it to work. Am I doing something obviously wrong here?

    Thank you all for your endless patience and helpful assistance!!

    Best,
    Dave

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Have a look at post #5 in the thread I posted about the config fuses.
    http://www.picbasic.co.uk/forum/show...75&postcount=5

    Clear as mud huh?

    Don't give up.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #13


    Did you find this post helpful? Yes | No

    Default

    Oh, I just needed to read all the way...doh!! Thank you Steve again for being patient with me and pointing out what you'd already showed me...haha.

    You guys have been a great help.

    Thanks--

    Best,
    Dave

Similar Threads

  1. Sending Commands from Visual Basic about IR to Pic
    By tne_de in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th April 2009, 06:09
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. using AND as an IF statement
    By dw_pic in forum mel PIC BASIC
    Replies: 27
    Last Post: - 8th June 2006, 18:05
  4. vb6 to pic basic
    By Darrenmac in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th December 2005, 01:56
  5. The Ultimate PIC Basic
    By picnaut in forum PBP Wish List
    Replies: 4
    Last Post: - 9th November 2004, 22:10

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