View previous topic :: View next topic |
Author |
Message |
sotodaniel
Joined: 23 Jun 2015 Posts: 3
|
after a interrupt off a pin |
Posted: Mon Nov 09, 2015 11:21 am |
|
|
Who wants to help me I would appreciate your input
Part of this program begins with PIN_D0 enabled; when the interrupt occurs in RB4, it switches off PIN_D0 and remain until the RB7 interrupt, which is again turns PIN_D0 is activated. The problem is that this subroutine is not working. Thanks for your time engineers
Code: |
#include <motor1.h>
#fuses XT, NOWDT, NOPROTECT, PUT, NOLVP
#use delay(clock=4000000)
#use fast_io(b)
void motor1 (void)
{
output_low(PIN_D0);
output_high(PIN_A5);
delay_ms(3000);
output_low(PIN_A5);
output_low(PIN_D0);
}
// here you must leave off the PIN_D0, until you turn on the interruption of pin_rb7
}
void available (void)
{
output_high(PIN_D0);
}
int1 flag_int_RB4=FALSE;
int1 flag_int_RB7=FALSE;
#int_RB
void RB_isr(void)
{
static int1 old_RB4=1;
static int1 old_RB7=1;
if(input(PIN_B4))
old_RB4=1;
else
{
if(old_RB4==1)
{
old_RB4=0;
flag_int_RB4=TRUE;
}
}
if(input(PIN_B7))
old_RB7=1;
else
{
if(old_RB7==1)
{
old_RB7=0;
flag_int_RB7=TRUE;
}
}
}
void main()
{
output_high(PIN_D0); //the program starts with PIN_D0 on high;
int temp;
set_tris_b(0XF0);
port_B_pullups(0xFF);
setup_comparator(NC_NC_NC_NC);
temp=input_b();
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
while(TRUE)
{
if(flag_int_RB4)
{
flag_int_RB4=FALSE;
motor1();
output_low(PIN_D0);
}
if(flag_int_RB7)
{
flag_int_RB7=FALSE;
available ();
}
}
} |
Last edited by sotodaniel on Tue Nov 10, 2015 8:37 am; edited 2 times in total |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Nov 09, 2015 1:16 pm |
|
|
I haven't checked the rest of your code, but one possible error is that your portB interrupt routine is not reset. At the start of your main routine you have this line: Code: | temp=input_b(); //you must read the port to reset the change latch] | It is good practice to do the same in your interrupt routine. Now you are just reading the individual bits and I'm not sure that is enough to reset the interrupt trigger.
You have:Why?
When you leave this line out the compiler will set the TRIS registers for you. Much easier. Only for special reasons, like high speed, you have to manually manage the TRIS registers.
Now there is the bug that port_D is all inputs on power up but you are trying to use it as an output. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 09, 2015 8:11 pm |
|
|
sotodaniel wrote: |
/////////////////// Subroutine MOTOR 1 ///////////////////
void motor1 (void)
{
{
output_low(PIN_D0); // off pin d0; control of insert coin piggy.
}
{
output_high(PIN_A5); // comprising motor 1, drift of balls
delay_ms(3000);
output_low(PIN_A5);
}
{
output_low(PIN_D0); // apaga pin d0; control de insert coin monedero.
}
////////////// here you must leave off the PIN_D0, until you turn
//////////////on the interruption of pin_rb7
} |
Get rid of all the extra braces that you have all over your program.
The extra braces are not part of any accepted coding style.
If you get rid of them, more people will be willing to look at your program
and offer help. Clean up all your routines so they look like this:
(Put your comments back in).
Code: | void motor1(void)
{
output_low(PIN_D0);
output_high(PIN_A5);
delay_ms(3000);
output_low(PIN_A5);
output_low(PIN_D0);
} |
sotodaniel wrote: |
#fuses XT, WDT, NOPROTECT, PUT, NOLVP
|
You have the Watchdog Timer enabled, but you never call restart_wdt()
in your program. Therefore, the Watchdog will timeout and reset your PIC.
Your program will not work correctly. Get rid of the WDT fuse.
Change it to NOWDT. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Nov 10, 2015 2:09 pm |
|
|
Please don't change your original post so much. Now we can't see what changes you made to improve your program. Leave the original text as it is and post a new reply in this thread when you make changes to the program.
Good things:
- You made your program a lot smaller so it is easier to find where the problem is.
- You change WDT to NOWDT
Bad things:
- You removed all code comments. Now we have no clue what you want to do.
- The program is not in a 'code' section. Now all formatting is gone and is more difficult to read.
+++++++++++++++
Added code block.
- Forum Moderator
+++++++++++++++
Have you tried what happens when you add my suggestion for reading the whole of port B? Just like in the start of main() ?
I see you still haven't fixed the TRIS register bug I pointed out. Sigh...
This is going to take a lot of time. Not my time, I'm out. |
|
|
|