I need help (MPLAB)

Thread Starter

Faisal906

Joined Feb 18, 2008
1
i am programming the PIC16F877 in which to control 3 LEDs using one push button.
in other word, if the push button is pressed once the LED1 will be high and the other two will be low.
and if the push button is pressed twice the LED2 will be high and the other two will be low.

and if the push button is pressed 3 times the LED3 will be high and the other two will be low.

i did write the code in c language, but i don't know how to controller it through the push button.

the code:


#include "C:\faisal\Wdoorbell.h"
int on,off,data1, data2,data3;
void main()
{

setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);



output_bit( PIN_a4, 0);

while(1){
data1=input(PIN_a4);
set_timer0(0);
if(data1==0){

output_bit( PIN_a4, 1);
output_bit(pin_b1,1);
delay_ms( 1000 );
if (get_timer0()!=0){

data2 = data1;
}
else if(get_timer0()!=5000){
output_bit(pin_b1,1);
output_bit(pin_b1,0);

}



if(data2==0){
output_bit(pin_b1,0);
output_bit(pin_b2,1);
delay_ms( 1000 );
set_timer0(2);
while (get_timer0()!=0){
data3 = data2;
}


}
if(data3==0){
output_bit( PIN_a4, 1);


output_bit(pin_b1,0);
output_bit(pin_b2,0);
output_bit(pin_b3,1);

delay_ms( 1000 );
while (get_timer0()!=0){

output_bit(pin_b3,0);
}



}

}




else if (data1==1){
output_bit( PIN_a4, 0);

output_bit(pin_b1,0);






}

}
}
 
Top