CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

led blink problem?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
noisepic



Joined: 24 Jul 2005
Posts: 20

View user's profile Send private message

led blink problem?
PostPosted: Mon May 15, 2006 9:56 am     Reply with quote

Code:

#include<18F458.h>
#fuses   NOWDT,HS,NOLVP,NOBROWNOUT,PUT,NOCPD,NOSTVREN,NODEBUG,NOWRT
#use  delay(clock=8000000)
void main()
{
int16 temp;
int8 i;
for(i=1;i<10;i++)
   {
   output_high(PIN_D5);
   delay_ms(300);
   output_low(PIN_D5);   
   delay_ms(300);   
   }
}


I want led on PIN_D5 blink with cycle of 300 ms. But they blink not in the same. and more than 10 times. I don't know why? How can i fixed this problem?
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Mon May 15, 2006 10:14 am     Reply with quote

You have no 'loop' at the end of 'main'. After the 10 flashes the PIC will go into sleep mode !!

try:

Code:
#include<18F458.h>
#fuses   NOWDT,HS,NOLVP,NOBROWNOUT,PUT,NOCPD,NOSTVREN,NODEBUG,NOWRT
#use  delay(clock=8000000)
void main()
{
   while(1)
   {
      output_high(PIN_D5);
      delay_ms(300);
      output_low(PIN_D5);   
      delay_ms(300);   
   }
}


If you don't just want it to keep flashing, you need to tell us what it is SUPPOSED to do rather than telling us what it IS doing !!! We can see from the code what it WILL do.

The code is only 7 lines long ... you should be able to work this one out for yourself.
_________________
Regards,
Simon.
Ttelmah
Guest







PostPosted: Mon May 15, 2006 10:19 am     Reply with quote

I'd 'suspect', that the most likely fault, is a hardware problem. How is the LED wired?. What current limiting resistor is used on the D5 connection?. How is the processor powered?. What supression components ar present?. How is MCLR connected?. Are both pairs of power and ground connections made?.
The code as posted, should blink the LED 9 times (not ten), and the period should be almost perfect (bar a couple of uSec for the actual loop), and then the code will stop (hitting the hidden sleep). However I'd suspect something silly, like a glitch on the power rail, when the LED turns on, so that the chip then resets, giving continuous flashes, but of a short duration.

Best Wishes
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Mon May 15, 2006 10:22 am     Reply with quote

You have asked this question before ....

Original Question

... I suspect you need to read the answer again !!!
_________________
Regards,
Simon.
noisepic



Joined: 24 Jul 2005
Posts: 20

View user's profile Send private message

PostPosted: Mon May 15, 2006 10:36 am     Reply with quote

Maybe something wrong in configuration bit. This is very simple code, i'm newbie use PIC18F458. I want a Led blink with cycle of 500ms. But i can;t see it blink.

Helpme pls, i don't have much time with simple ..things.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon May 15, 2006 11:15 am     Reply with quote

You have no while(1) statement.
Code:

#include<18F458.h>
#fuses   NOWDT,HS,NOLVP,NOBROWNOUT,PUT,NOCPD,NOSTVREN,NODEBUG,NOWRT
#use  delay(clock=8000000)
void main()
{
  int16 temp;
  int8 i;
  for(i=0;i<10;i++)
  {
    output_high(PIN_D5);
    delay_ms(300);
    output_low(PIN_D5);   
    delay_ms(300);   
  }
  while(1)
  {
  }
}
noisepic



Joined: 24 Jul 2005
Posts: 20

View user's profile Send private message

PostPosted: Mon May 15, 2006 6:37 pm     Reply with quote

I have test some connection on my circuit board
+ MCLR --> OK
+ Both power supply-->OK
+ Resistor connected with LED 330 ohm
+ Crystal -> HS

When I measure PIN OSC1,OSC2( Pin13,14) there is no pulse or wave althought righ connection.

Have you ever met this problem!!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon May 15, 2006 6:42 pm     Reply with quote

Measure the output of the LED. If it is blinking, then the crystal must be doing something.
Richard Arroyo



Joined: 04 Apr 2006
Posts: 22
Location: Sebastopol, CA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue May 16, 2006 12:44 am     Reply with quote

Try setting the Tris regisiters otherwise the pins may remain in high impedance state if your compiler doesn't automatically set the Tris regisiters .

Code:

#include<18F458.h>
#fuses   NOWDT,HS,NOLVP,NOBROWNOUT,PUT,NOCPD,NOSTVREN,NODEBUG,NOWRT
#use  delay(clock=8000000)
void main()
{
  int16 temp; //<<-- Must be for something else
  unsigned int8 i;
  SET_TRIS_D(223); //11011111 RD5 as output  <<-- see if this helps
     for(i=0;i<20;i++)
      {
        output_toggle(PIN_D5);
        delay_ms(300);   
      }

//The PIC will now sleep

}

_________________
RAA
noisepic



Joined: 24 Jul 2005
Posts: 20

View user's profile Send private message

PostPosted: Tue May 16, 2006 4:44 am     Reply with quote

oh!! TRISD . I have modified my code. it runs well.
thanks so much.

Richard Arroyo

The first your post is very very good!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group