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 CCS Technical Support

Led Blinking program won't work C

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



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

Led Blinking program won't work C
PostPosted: Thu Jun 28, 2012 7:30 am     Reply with quote

Hello I just got a problem, that i just can't run that program:

Here is the code:
Code:
#include <16F887.h>
#include <delay.c>
//#FUSES NOWDT, HS, NOMCLR, NOBROWNOUT, NOIESO, NOLVP
//I setup the config in usburn
#use delay(clock=20000000)


void main() {


   while (TRUE) {
     output_high(PIN_B7);
     delay_ms(100);

     output_low(PIN_B7);
     delay_ms(100);

   }
}


I hope that someone knows why i have this problem. The pic is setting the pin to high but not to low then.
And when I put:
set_tris_b(0x00);

everything led blinking then^^
It's correcty wired.

Regards Benni
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 8:05 am     Reply with quote

Most likely the wrong fuses are being set/reset in your programmer.
I dont have or use the 'usburn' programmer

Not required is the #include delay.c
never used, don't know what it really is, doesn't matter.

Not required is the set_tris_b(..)
the compiler will automatically handle the I/O registers.

Some internal perhipheral might be on B7
if so ,check to be sure , it is disabled

hth jay
benni



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 8:28 am     Reply with quote

Hello,
I've done that what you said and the config is also ok because i everytime use the same settings...

I hope you and the others have an idea to solve this problem.


regards Benni
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 8:50 am     Reply with quote

dump out the listing and show us the fuses code.

also need to know the compiler version( it's at the top of the listing 4.xxx)

do you have the correct caps for the xtal ?

hth jay
benni



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 9:05 am     Reply with quote

I have 4.120 and what do you mean with the fuses code? I don't have the configs in the file i set it in the programmer.


Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 9:17 am     Reply with quote

You say "it's correctly wired". Describe the LED connection. What resistor value have you got to limit the current to the LED?.
What you are describing, is what you would expect to happen if the LED was overloading the PIC output.

Seriously, also, let the code set the fuses.

Setting them in the programmer, means you can't just take the code as a single complete 'entity', and program it using any programmer, without having to make any settings/changes. Extra work, that is basically pointless, and increases the chance of something being wrong.

Best Wishes
benni



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 9:22 am     Reply with quote

What i dont understand is that the LED goes on but doesn't go off....
And i use a 100 ohm resistor
Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 10:23 am     Reply with quote

OK.
That should be alright.

I'd guess possibly your watchdog timer is tripping (fuses.....).

What would then happen, is the LED would come on, then while the code is sitting in the 100mSec delay, with the watchdog still 'on', the watchdog forces a reset. For a few uSec, the pin would then go floating, and immediately be turned back on again. Then the cycle would repeat. You'd never see the 'off' period, since it'd literally be microseconds.
The settings you show, have this 'off', but possibly the programmer is not doing this right.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 12:16 pm     Reply with quote

Quote:
#include <16F887.h>
#include <delay.c>
//#FUSES NOWDT, HS, NOMCLR, NOBROWNOUT, NOIESO, NOLVP
//I setup the config in usburn
#use delay(clock=20000000)

The delay.c is a Hi-Tech C file. I wonder if you really have CCS ?
Also the fact that you're reluctant to use CCS fuses statement.
Again, that points to maybe Hi-Tech ? Other parts of the program
are definitely CCS, but I wonder.

Also, your choice of pin B7 for the LED is not good. If you use an ICD
debugger/programmer, it uses pins B6 and B7 to communicate with the
PIC. It's much better to not use those pins.

Here is a test program to blink an LED on pin B0.
Code:

#include <16F887.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, MCLR, NOLVP
#use delay(clock=8M)

//===============================
void main()
{

while(1)
   {
    output_high(PIN_B0);
    delay_ms(500);
    output_low(PIN_B0);
    delay_ms(500);
   }

}



Quote:
And i use a 100 ohm resistor

100 ohms is too low. Let's say you are using an LED with a Vf voltage
drop of 2 volts. For a PIC running at 5v, that means approximately 3v
must be dropped across the 100 ohm resistors. That's 30 ma. That
amount of current exceeds the limit for the PIC pin. Get rid of that
resistor and put in a better value, such as 470 ohms. Your circuit
should look like this:
Code:

pin      470 ohms      LED       
B0    ---/\/\/\/------->|----
                            |
                            |
                          -----  Ground 
                           ---
                            -


Also, make sure you have a 10K pull-up resistor on the PIC's MCLR pin:
Code:

           +5v
            |
            <
            > 10K       
            <   
To          |
MCLR  -------
pin                         
benni



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 2:42 pm     Reply with quote

Thánks to all for the help i know what it was. It was my Power Supply which gives 100hz DC out.... So the pic started everytime from new....




Regards Benni
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