Eraser
Member level 3
- Joined
- Nov 2, 2007
- Messages
- 63
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- Braga,Portugal
- Activity points
- 1,717
void interrupt my_isr(void)
I built this program, in c , this is a led pingpong, on pic 16f877a, but the program doesnt work 100%, the leds move for one side and dont return, and i dont know why.
Can anyone help me???
the program is :
#include <htc.h>
int direction=0;
__CONFIG(XT & WDTDIS & PWRTDIS & BORDIS & LVPEN & WRTEN & DEBUGDIS & DUNPROT & UNPROTECT);
void inittimer0(void)
{
T0CS=0;
T0SE=0;
PSA=0;
PS2=1;
PS1=1;
PS0=1;
TMR0=0;
}
void initporto(void)
{
TRISD=0;
PORTD=0;
RD7=1;
}
void interrupcoes(void)
{
T0IF=0;
T0IE=1;
GIE=1;
}
void main(void)
{
inittimer0();
initporto();
interrupcoes();
while (1)
{
}
}
void interrupt my_isr(void)
{
if (direction==0)
{
T0IF=0;
PORTD=PORTD*10;
if (RD0==1)
{
direction=1;
}
}
else
{
T0IF=0;
PORTD=PORTD/10;
if (RD7==1)
{
direction=0;
}
}
}
I built this program, in c , this is a led pingpong, on pic 16f877a, but the program doesnt work 100%, the leds move for one side and dont return, and i dont know why.
Can anyone help me???
the program is :
#include <htc.h>
int direction=0;
__CONFIG(XT & WDTDIS & PWRTDIS & BORDIS & LVPEN & WRTEN & DEBUGDIS & DUNPROT & UNPROTECT);
void inittimer0(void)
{
T0CS=0;
T0SE=0;
PSA=0;
PS2=1;
PS1=1;
PS0=1;
TMR0=0;
}
void initporto(void)
{
TRISD=0;
PORTD=0;
RD7=1;
}
void interrupcoes(void)
{
T0IF=0;
T0IE=1;
GIE=1;
}
void main(void)
{
inittimer0();
initporto();
interrupcoes();
while (1)
{
}
}
void interrupt my_isr(void)
{
if (direction==0)
{
T0IF=0;
PORTD=PORTD*10;
if (RD0==1)
{
direction=1;
}
}
else
{
T0IF=0;
PORTD=PORTD/10;
if (RD7==1)
{
direction=0;
}
}
}