| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| shenba 
 
 
 Joined: 15 Sep 2012
 Posts: 1
 Location: india
 
 
			    
 
 | 
			
				| PIC12F510-LIGHT UP |  
				|  Posted: Sat Sep 15, 2012 3:41 am |   |  
				| 
 |  
				| 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: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat Sep 15, 2012 5:17 am |   |  
				| 
 |  
				| 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: 9588
 Location: Greensville,Ontario
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat Sep 15, 2012 5:55 am |   |  
				| 
 |  
				| 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
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat Sep 15, 2012 10:17 am |   |  
				| 
 |  
				| 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. 	  | 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. | 
 
 Mike
 |  | 
	
		|  | 
	
		|  |