CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

after a interrupt off a pin

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sotodaniel



Joined: 23 Jun 2015
Posts: 3

View user's profile Send private message

after a interrupt off a pin
PostPosted: Mon Nov 09, 2015 11:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 09, 2015 1:16 pm     Reply with quote

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:
Code:
#use fast_io(b)
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

View user's profile Send private message

PostPosted: Mon Nov 09, 2015 8:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 10, 2015 2:09 pm     Reply with quote

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... Rolling Eyes
This is going to take a lot of time. Not my time, I'm out.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group