Searching \ for '[pic] How to make a led flash' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/displays.htm?key=led
Search entire site for: 'How to make a led flash'.

Exact match. Not showing close matches.
PICList Thread
'[pic] How to make a led flash'
2009\06\17@234733 by uaca man

picon face
As meny other i'm starting with PICs, i bought some pic 12f629 and im using
some C code exemplas that i found on the net.

I'm sure it was asked many times before but i can't understand what is
wrong.

So far i'm able to turn on the led but there is no way to make it flash.

I'm using the HI-TECH C ide with the PIC10/12/16 MCU family compiler v 9.65
and seems that im cursed, some times the led turns on, some times it just
does nothing until i come close to the PCB and than it turns on just like a
miracle.


The code i'm using:

#include <htc.h>

#define _XTAL_FREQ  4000000     // oscillator frequency for _delay()

// Config: ext reset, no code protect, no brownout detect, no watchdog,
//         power-up timer enabled, 4MHz int clock
__CONFIG(MCLREN & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);


void main()
{
   unsigned char   dcnt;       // delay counter

   // Initialisation
   TRISIO = ~(1<<1);           // configure GP1 (only) as an output

   // Main loop
   for (;;) {
       // turn on LED on GP1
       GPIO1 = 1;

       // stay on for 200ms
       __delay_ms(100);
       __delay_ms(100);

       // turn off LED on GP1
       GPIO1 = 0;

       // stay off for 800ms
       for (dcnt = 0; dcnt < 8; dcnt++) {
           __delay_ms(100);
       }
   }   // repeat forever
}

Any ideas on how to find the problem is greatly apreciatted

Tks
Uaca

2009\06\18@003453 by Chetan Bhargava

picon face
You should add a delay and turn off the LED and repeat forever.

main:
led = on
call delay
led = off
call delay
jump main

delay:
use a loop to cause a delay
return



Chetan Bhargava


On Wed, Jun 17, 2009 at 8:47 PM, uaca man<spam_OUTuacamanTakeThisOuTspamgmail.com> wrote:
{Quote hidden}

>

2009\06\18@003524 by William \Chops\ Westfield

face picon face
On Jun 17, 2009, at 8:47 PM, uaca man wrote:

> As meny other i'm starting with PICs, i bought some pic 12f629 and  
> im using
> some C code exemplas that i found on the net.
       :
{Quote hidden}

You need more initialization.  IIRC, the 12f629 includes some analog  
peripherals (comparator ?) that have to be explicitly disabled to be  
able to use the pins as digital outputs...

BillW

2009\06\18@004213 by solarwind

picon face
On Thu, Jun 18, 2009 at 4:47 AM, uaca man <.....uacamanKILLspamspam@spam@gmail.com> wrote:
>
> As meny other i'm starting with PICs, i bought some pic 12f629 and im using
> some C code exemplas that i found on the net.
>
> I'm sure it was asked many times before but i can't understand what is
> wrong.
>
> So far i'm able to turn on the led but there is no way to make it flash.
>
> I'm using the HI-TECH C ide with the PIC10/12/16 MCU family compiler v 9.65
> and seems that im cursed, some times the led turns on, some times it just
> does nothing until i come close to the PCB and than it turns on just like a
> miracle.

I had the same problem before. The solution for me was to turn off
analogs (that's whats causing the problem when you come close to the
PCB). I'm not sure how the PIC12Fs behave, but on the 16Fs, you would
do:

ANSEL = 0x00;
ANSELH = 0x00;

And that fixed the problem for me.

I was using PIC16F886 with the same compiler you are using.

2009\06\18@014410 by Ruben Jönsson

flavicon
face
{Quote hidden}

Yes, set CMCON to 7 to disable the analog comparator and use the pins for it as
digital I/O.

/Ruben

==============================
Ruben Jönsson
AB Liros Electronic
Box 9124, 200 39 Malmö, Sweden
TEL INT +46 40142078
FAX INT +46 40947388
rubenspamKILLspampp.sbbs.se
==============================

2009\06\18@020551 by Rikard Bosnjakovic

picon face
On Thu, Jun 18, 2009 at 06:34, Chetan Bhargava <.....cbhargavaKILLspamspam.....gmail.com> wrote:

> You should add a delay and turn off the LED and repeat forever.

Since that's what he's doing, what's your point?


--
- Rikard - http://bos.hack.org/cv/

2009\06\18@021823 by Rikard Bosnjakovic

picon face
On Thu, Jun 18, 2009 at 06:41, solarwind <EraseMEx.solarwind.xspam_OUTspamTakeThisOuTgmail.com> wrote:

> I had the same problem before. The solution for me was to turn off
> analogs (that's whats causing the problem when you come close to the
> PCB).

That will only affect situations where ports are defined as input. If
GP0 is defined as an output, then it does not matter what it says in
the ANSEL-register; GP0 will work as expected.

As others have already pointed out, this problem is caused by the
comparator module not being off. Doing as Ruben says, "CMCON = 7;"
will solve it.


--
- Rikard - http://bos.hack.org/cv/

2009\06\18@072149 by Michael Rigby-Jones

flavicon
face


> -----Original Message-----
> From: piclist-bouncesspamspam_OUTmit.edu
> [@spam@piclist-bouncesKILLspamspammit.edu] On Behalf Of Rikard Bosnjakovic
> Sent: 18 June 2009 07:18
> To: Microcontroller discussion list - Public.
> Subject: Re: [pic] How to make a led flash
>
> On Thu, Jun 18, 2009 at 06:41, solarwind
> <KILLspamx.solarwind.xKILLspamspamgmail.com> wrote:
>
> > I had the same problem before. The solution for me was to turn off
> > analogs (that's whats causing the problem when you come
> close to the
> > PCB).
>
> That will only affect situations where ports are defined as
> input. If GP0 is defined as an output, then it does not
> matter what it says in the ANSEL-register; GP0 will work as expected.


For limited values of "expected" (as Russell would say).  If a pin is
configured as an input then the PORT register will always return zero
for that bit. Setting or clearing a port pin configured for analog use
should set it correctly, but since this is a Read-Modify-Write operation
any other pins configured as analog will get set to zero which probably
won't be expected.  Note that other R-M-W operations such as XORing the
port with a mask to toggle the LED state will NOT work with the pin
configured as an input.

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

2009\06\18@074820 by Isaac Marino Bavaresco

flavicon
face
William "Chops" Westfield escreveu:
{Quote hidden}

The analog configuration affects only pins defined as input, he is only
writing to the pin and not using RMW, then the problem should be in
another place.

Regards,

Isaac

__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/

2009\06\18@080725 by Sean Breheny

face picon face
Hi Uaca,

How do you have the chip connected externally? Do you have a pull-up
on MCLR? It sounds a bit like the classic MCLR floating (unconnected)
problem.

Sean


On Wed, Jun 17, 2009 at 11:47 PM, uaca man <RemoveMEuacamanTakeThisOuTspamgmail.com> wrote:
{Quote hidden}

>

2009\06\18@105257 by Dwayne Reid

flavicon
face
At 09:47 PM 6/17/2009, uaca man wrote:

>some times the led turns on, some times it just
>does nothing until i come close to the PCB and than it turns on just like a
>miracle.
>
>// Config: ext reset, no code protect, no brownout detect, no watchdog,
>//         power-up timer enabled, 4MHz int clock
>__CONFIG(MCLREN & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);

Take a closer look at the above config line.  Reset pin is ENABLED.

Do you have pin 4 (MCLR) tied to +5V?  If not, try connecting pin 4
to pin 1 via a 10k resistor.

dwayne

--
Dwayne Reid   <spamBeGonedwaynerspamBeGonespamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax
http://www.trinity-electronics.com
Custom Electronics Design and Manufacturing

2009\06\18@201407 by solarwind

picon face
On Thu, Jun 18, 2009 at 3:52 PM, Dwayne Reid <TakeThisOuTdwaynerEraseMEspamspam_OUTplanet.eon.net> wrote:
> >// Config: ext reset, no code protect, no brownout detect, no watchdog,
> >//         power-up timer enabled, 4MHz int clock
> >__CONFIG(MCLREN & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);
>
> Take a closer look at the above config line.  Reset pin is ENABLED.
>
> Do you have pin 4 (MCLR) tied to +5V?  If not, try connecting pin 4
> to pin 1 via a 10k resistor.

Or you could replace MCLREN with MCLRDIS.

2009\06\18@223047 by David Meiklejohn

face
flavicon
face
Strange seeing my own code come back at me - this is from one of my
tutorials (see my web site).

So to answer some of the points I have seen in this thread:

The 12F629 does not have an ADC, so there are no analog inputs to turn off.
In fact, that's why I started the midrange lessons with this part - there is
less to confuse the beginner, no need to say "clear ANSEL for now and we'll
explain why later".

Yes, it is true that the 12F629 does have a comparator.  (Funnily enough,
that's actually the next lesson I plan to write.)  However, the comparator
does not in its default state interfere with any outputs.  I recognise that,
when comparator inputs, being used as digital outputs, are read, the bits
read as zero and will cause problems due to RMW, even if they are not
explicitly read.  But I have been careful in all of my 12F629 examples to
avoid any situation where this is the issue - again to avoid saying "use
CMCON = 7 for now, and we'll explain why later".  I'll explain about this in
my next lesson, though.

I believe, as couple have pointed out, that the problem here is a floating
MCLR input.  The lessons were written for Microchip's low pin count demo
board, where MCLR is held high through a 10k resistor (and grounded by a
pushbutton, in time honoured fashion).  Perhaps I should show this
explicitly in the circuit diagrams in my tutorials, despite having explained
what MCLR is.  Probably worth doing that in a future revision...

The simplest solution here is to enable internal MCLR, by changing 'MCLREN'
to 'MCLRDIS'.


Regards,
David Meiklejohn
http://www.gooligum.com.au



> {Original Message removed}

2009\06\18@223305 by uaca man

picon face
Thanks everyone for the answers.

>> It sounds a bit like the classic MCLR floating (unconnected)
problem. <<

Indeed, it looks like it was. When I connected the 5v+ in the MCLR it worked
like magic. Thanks!!

However, I tried disabling the reset pin using the MCLRDIS instruction and
it didn`t work without connecting pin 4 to the +5v supply. Does I need an
external oscillator to make it work this way?

Thanks a lot for the answers, there`s no word to express the joy i`m feeling
right now, I wish I could buy you guys some beer!

Cheers.

2009\06\18@225208 by uaca man

picon face
Well I just tried it again with the MCLRDIS instruction and it WORKED, I
forgot to configure the progammer properly (Winpic).

David i did read your tutorial and did not understand that i also need power
supply at the pin 4.

Thatks everyone again.

The joy!!! :)

Beer is on me.

Cheers,
Uaca



2009/6/18 David Meiklejohn <RemoveMEdavidspamTakeThisOuTgooligum.com.au>

{Quote hidden}

> > {Original Message removed}

2009\06\18@235512 by David Meiklejohn

face
flavicon
face
Thanks for the feedback.

By the way, it's not quite "power supply" that you need at pin 4 (MCLR),
it's a logic high.  You can do that by tying the pin directly to Vdd, but
more normally it's done through a resistor (typically 10k), so that you can
pull the pin low to reset the PIC if you want to.

I don't understand, though, why you needed to make MCLR high after you
disabled external reset.  Granted, it's not a good idea to leave unused
inputs (this pin becomes GP3 when internal reset is used), but it shouldn't
have stopped your code working.

I wonder if your programmer is setting the config bits correctly?  It may be
set to override the settings in the code.  Or, perhaps it's the other way
around - you haven't changed the code, and your programmer isn't applying
the config you think you have selected.  I don't know about winpic.

But in any case, external vs internal clock isn't relevant here - it doesn't
affect MCLR in any way.


> {Original Message removed}

2009\06\19@042042 by Alan B. Pearce

face picon face
>I believe, as couple have pointed out, that the problem here is
>a floating MCLR input.  The lessons were written for Microchip's
>low pin count demo board, where MCLR is held high through a 10k
>resistor (and grounded by a pushbutton, in time honoured fashion).

You may want to have a paragraph where you point out "This project assumes
that you are using Microchips Low Pin Count demo board. If building your own
hardware you need to make sure you add a resistor between the MCLR pin and
Vcc" along with any other assumptions that are required from that hardware.

2009\06\19@075305 by olin piclist

face picon face
uaca man wrote:
> However, I tried disabling the reset pin using the MCLRDIS
> instruction

There is no such instruction.  You may be confusing configuration settings
with instructions.  The two are very different and you need to learn the
distinction.

> and it didn`t work without connecting pin 4 to the +5v
> supply.

And pin 4 is ..?  You can't expect us to look up the datasheet for your
particular chip just to answer a basic PIClist question.


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.

More... (looser matching)
- Last day of these posts
- In 2009 , 2010 only
- Today
- New search...