PDA

View Full Version : Trouble with most basic BLINK on PIC 16F819



confusedperson
- 15th April 2009, 04:32
Hi folks

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



'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

confusedperson
- 15th April 2009, 04:34
By the way, that link should be

http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010227

Sorry!

mister_e
- 15th April 2009, 04:52
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.

mister_e
- 15th April 2009, 04:55
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

Jerson
- 15th April 2009, 04:55
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.



@ 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

Archangel
- 15th April 2009, 08:13
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

confusedperson
- 15th April 2009, 15:41
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...

confusedperson
- 16th April 2009, 05:33
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

mister_e
- 16th April 2009, 15:41
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 ;)

Acetronics2
- 16th April 2009, 16:14
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

confusedperson
- 16th April 2009, 16:35
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:


@ __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 (http://www.picbasic.co.uk/forum/showthread.php?t=543). 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

mister_e
- 16th April 2009, 16:41
Have a look at post #5 in the thread I posted about the config fuses.
http://www.picbasic.co.uk/forum/showpost.php?p=6775&postcount=5

Clear as mud huh? ;)

Don't give up.

confusedperson
- 16th April 2009, 21:46
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