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

PIC12F510-LIGHT UP

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



Joined: 15 Sep 2012
Posts: 1
Location: india

View user's profile Send private message

PIC12F510-LIGHT UP
PostPosted: Sat Sep 15, 2012 3:41 am     Reply with quote

HI.... i am new for PIC12F510 microcontroller.i tried to light up a LED.there is no error in my coding.but led is not glowing.

This is my coding

#include <12F510.h>
#fuses INTRC,NOWDT,MCLR,PROTECT
#use delay(clock=8000000)
#use fast_io(B)

void port_init(void);
void led_on(void);
void led_off(void);

void main()
{
port_init();
while(1)
{

led_on();
delay_ms(1500);
led_off();
delay_ms(1500);
}
}


void port_init(void)
{
SET_TRIS_B(0b11111101);
OUTPUT_B(0x00);
}

void led_on(void)
{
OUTPUT_HIGH(PIN_B1);
}

void led_off(void)
{
OUTPUT_LOW(PIN_B1);
}



Thanks.............
Ttelmah



Joined: 11 Mar 2010
Posts: 19541

View user's profile Send private message

PostPosted: Sat Sep 15, 2012 5:17 am     Reply with quote

1) Use the code buttons.
2) 80% of your code is not needed. You can get the same effect with:

Code:

#include <12F510.h>
#fuses INTRC,NOWDT,MCLR,PROTECT
#use delay(clock=8000000)
#define LED PIN_B1

void main(void) {
   while(TRUE) {
      output_high(LED);
      delay_ms(1500);
      output_low(LED);
      delay_ms(1500);
   }
}

CCS will handle the TRIS for you.

There are two other things that do have to be done though:
1) Turn off the comparator.
2) Turn off the ADC,

Both of these can potentially disable the output on this pin.

One other thing that could cause problems, is not a large enough current limiting resistor feeding the LED. This could result in the PIC overloading, and then resetting. This can be so fast that you would not see it.

Other thing obvious, is that you need a pull-up on the MCLR pin.

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Sat Sep 15, 2012 5:55 am     Reply with quote

also..
the LED has to be wired up correctly...quick way to test, take the resistor lead that goes to the PIC I/O pin (B1) and put onto Vcc(+5V) and the LED should light.

yes, simple ,..but some LEDs are hard to figure out anode/cathode connections.

hth
jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Sep 15, 2012 10:17 am     Reply with quote

Quote:
the LED has to be wired up correctly...quick way to test, take the resistor lead that goes to the PIC I/O pin (B1) and put onto Vcc(+5V) and the LED should light.
Depends on which way LED is wired. May need to connect to 0V Gnd. Idea is right, one way should work, no damage done if you make wrong connection.

Mike
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