Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need help on start /stop on single switch with pic micro controller

Status
Not open for further replies.
Hi
Any one plz help me on this code

5 led output (for delay status)

2 switch i/p

1 relay output

5 led status( 5min, 10min, 15 min 30 min, 60 min) delay

one switch for select delay and another switch for on/off (relay)

problem is on/off function not working properly ,some times working some times not
can anyone help me simplest way or bugs

#byte portc=0x07
#byte trisc=0x87
#bit start=0x05.0
#bit sel=0x05.1
#bit Rly=0x07.5
int8 minn,secc,msec;
int i;
#int_timer1 // timer code
timer1_isr()
{

msec++;
if(msec==8)
{
msec=0;
secc++;
if(secc==56)
{
secc=0;
minn++;
if(minn==59)
{
minn=0;

}
}}}

void main()
{


SET_TRIS_A( 0x03 );
SET_TRIS_c( 0x00 );
Portc=0;

i=0;

setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
msec=Secc=minn=0;

while(TRUE)
{
if(i==0)
{
output_high(PIN_C0);
output_low(PIN_C1);
output_low(PIN_C2);
output_low(PIN_C3);
output_low(PIN_C4);

}
if(!input(Pin_A1)) // delay selection loop
{
delay_ms(250);
i++;
delay_ms(10);


if(i==1)
{
output_low(PIN_C0);
output_high(PIN_C1);
output_low(PIN_C2);
output_low(PIN_C3);
output_low(PIN_C4);

}
if(i==2)
{
output_low(PIN_C0);
output_low(PIN_C1);
output_high(PIN_C2);
output_low(PIN_C3);
output_low(PIN_C4);

}
if(i==3)
{
output_low(PIN_C0);
output_low(PIN_C1);
output_low(PIN_C2);
output_high(PIN_C3);
output_low(PIN_C4);

}
if(i==4)
{
output_low(PIN_C0);
output_low(PIN_C1);
output_low(PIN_C2);
output_low(PIN_C3);
output_high(PIN_C4);
}
if(i>4)
{
i=0;
}

}

if(!input(Pin_A0)) // ON/off loop
{
delay_ms(50);
Secc=minn=0;
while(1)
{
if(i==0)
{
rly=1;
if((minn==5)||(!input(pin_A0)))
{
rly=0;
delay_ms(150);
break;
}
}
else if(i==1)
{
rly=1;
if((minn==10)||(!input(pin_A0)))
{
rly=0;
delay_ms(150);
break;
}
}
else if(i==2)
{
rly=1;
if((minn==15)||(!input(pin_A0)))
{
rly=0;
delay_ms(150);
break;
}
}
else if(i==3)
{
rly=1;
if((minn==30)||(!input(pin_A0)))
{
rly=0;
delay_ms(150);
break;
}
}
else if(i==4)
{
rly=1;
if((minn==59)||(!input(pin_A0)))
{
rly=0;
delay_ms(150);
break;
}
}
}
}


}
}
 
Sam, just as a suggestion. First Edit this and put it in Code Tags; it's the Gear symbol next to the smilies in the tool bar. Second / comment out what all calls on all lines as to what your expecting them to do

It may be easier to get the right help. I'm not qualified; good luck.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top