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.

Problem with pic program [SOLVED].

Status
Not open for further replies.

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;
}
}
}
 

Problem with pic program.

can u give us the schematic?

:)
 

Re: Problem with pic program.

xxtigerxx said:
can u give us the schematic?

:)



The problem its not hardware, because i made the same program in assembley, and work,im learning c so i am a roockie.lol

thanks.
 

Problem with pic program.

I don't see which bit pattern is intended or how PORTD=PORTD*10 respectively PORTD=PORTD/10 can generate a useful pattern.
 

Re: Problem with pic program.

I have tried put portd=portd>>1 and portd=portd<<1, and the result its the same.
 

Re: Problem with pic program.

Hi!
I have tested this code in proteus. It works fine. So test this on ur hardware.
I hope this will be successfull.
Regards.

#include <htc.h>

__CONFIG(XT & WDTDIS & PWRTDIS & BORDIS & LVPEN & WRTEN & DEBUGDIS & DUNPROT & UNPROTECT);

int direction=0;
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>>1;
if (RD0==1)
{
direction=1;
}
}
else
{
T0IF=0;
PORTD=PORTD<<1;
if (RD7==1)
{
direction=0;
}
}
}
 

Problem with pic program.

At least, the code looks meaningful now.
 

Re: Problem with pic program.

sorry for my ignorance, but what is the proteus?
 

Problem with pic program.

ohh

PORTD=PORTD<<1; ???

don't do this way

use a variable to shift in PORT

for example:

unsigned char c=80;


PORTD=c>>i;


Pallav Aggarwal
Simpaltechnologies,India
 

Re: Problem with pic program.

Eraser said:
The program already works. Thanks.
Could you please edit the topic to read "Problem with pic program [SOLVED]"? This would help prevent people from reading through the whole thread just to realize that there is now no problems to solve. Thank you.

Cheers,
 

Re: Problem with pic program.

namqn said:
Eraser said:
The program already works. Thanks.
Could you please edit the topic to read "Problem with pic program [SOLVED]"? This would help prevent people from reading through the whole thread just to realize that there is now no problems to solve. Thank you.

Cheers,

Ok no problem.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top