Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with code for two LEDs at pin B0 and B1

Status
Not open for further replies.

Tom2

Full Member level 5
Joined
Nov 11, 2006
Messages
318
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Activity points
3,457
I use a pic microcontroller and i want to have two LED at pin B0 and pin B1.The first led will turn on when the input signal is more than zero and the second when the input is zero.I test this code to pic on a breadbord but the signal is zero both of the led are on

if (input(PIN_A0>0));
{ delay_ms(10);
output_high(PIN_B0);}
if (input(PIN_A0<0));
{ delay_ms(10);
output_high(PIN_B1);}
 

Re: LED_code_pic

try <1 and =>1. the input has to be MIN 0.6 volts to sense an high state.
 

Re: LED_code_pic

Your "IF" line is wrong. Remove the semicolon at the end of the line and check the brackets. Try this:

if (input(PIN_A0)>0)
{
delay_ms(10);
output_high(PIN_B0);
output_low(PIN_B1);
}
else
{
delay_ms(10);
output_low(PIN_B0);
output_high(PIN_B1);
}

Regards,

Ric
 

Re: LED_code_pic

I also try this code but still not working.Actually when for no input Pin B0 is on but for not zero input no led is on.

if (input(PIN_A0)==0){

delay_ms(10);
output_bit(PIN_B0,1);
output_bit(PIN_B1,0);
}
else {
delay_ms(10);
output_bit(PIN_B0,0);
output_bit(PIN_B1,1);



}
Have you any idea for this problem?????
 

Re: LED_code_pic

Please let us know more about your code. Post you #fuses for example. How are you setting the I/O direction (#USE_FAST_IO ???)?

Ric
 

Re: LED_code_pic

i use fuses :
#fuses XT,NOWDT,NOPROTECT,NOLVP
main:

void main()
{
long adc_result;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_2);
setup_ccp1(CCP_PWM); // to CCP1 doulevi san PWM
setup_timer_2(T2_DIV_BY_1, 255, 1);
WHILE (1)
{
set_adc_channel(0);
delay_ms(1);
adc_result=read_adc();
adc_result>>=6;


set_pwm1_duty(adc_result);

}
}
 

Re: LED_code_pic

Where are you calling the function that checks the PIN_A0? I also see you are using " setup_adc_ports(ALL_ANALOG)"...don't know what PIC you are using but maybe you are setting some of these ports to analog...I supposed they should be digital for this purpose.

Regards,

Ric
 

Re: LED_code_pic

I thimk there is some Fault in u r Hardware. If u want u r PORT B0 to to ON when its pib is LOW means u have to connect the LED with a PULL UP resister and the other end has to go to u r PORT PIN. BY doing this u will get the output as u required
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top