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

int_rb interrupts do not work

 
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

int_rb interrupts do not work
PostPosted: Tue May 03, 2016 7:27 pm     Reply with quote

Greetings Ing. I wrote this program and my pc-1 compiles fine without any error or warnings. When programmed in the PIC16F887, and installed in the breadboard, it runs the program to perfection. However on another computer-2, I write this same program and it compiles fine without any errors or warnings. Then I program the PIC16F887 and put it in the breadboard and oh surprise, it does nothing ! or does not accept the interrupts. What is causing this ? Does the same program not work for different versions of CCS C ? Thank you for your help.
Code:

#include <UNO_10.h>

#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, PUT, NOLVP
#use fast_io(b)


void parpadeo (void)
{
  #BYTE TRISA = 0X85
   TRISA = 0X00;
   set_tris_a(0X00);
 
   int i=0;

   for(i=0; i<12; i++)
   {
   output_high(PIN_A1);
   delay_ms(500);   
   output_low(PIN_A1);
   delay_ms(500);
   }
   
  output_high(PIN_A1); 
  }

    // standard i/o is the default.
    // it is easier to handle interrupt on change with the pins
    // fixed regarding their i/o, hence selecting fast_io.
   
    int1 flag_int_RB4 = FALSE;
   
     // flags to say these pin have_dropped_
   
   //this sets each flag if the pin changes_low_, when it was high
     
#int_RB
void  RB_isr(void)
{
   static int1 old_RB4=1;
   
   //handle  RB4
   
   if(input(PIN_B4)) //PIN is high
        old_RB4=1;  //record this
        else
        {
           if(old_RB4==1) //pin is now low, and was high
           { //RB4 has changed to low
           old_RB4=0;
           flag_int_RB4=TRUE;
        }
     }
         
}


void main()
{
  int temp;
  set_tris_b(0XF0); //since you want to interrupt on B4, and B7
                    //they_must_be (u) inputs (/u);

   port_B_pullups(0xFF);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   temp=input_b(); //you must read the port to reset the change latch
   
   clear_interrupt(INT_RB);
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
     

   while(TRUE)
   {
      //TODO: User Code
     
      if(flag_int_RB4)
      {
      flag_int_RB4=FALSE;
      //RB4 has now drppped -do what you want
      //
      ///////////////
      parpadeo();
      //
     
      ///////////////
     
      }
               
      ///////////// regreso de interrupciones
             
   }///llave de cierre del while

}////llave de cierre del main
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Wed May 04, 2016 12:58 am     Reply with quote

First tidy things. Make your indenting logical. Then there are silly things like setting TRIS twice. Unnecessary anyway, since you are not using fast_io on port a. Then use the C standard of putting all variable declarations at the start of the code sections. This is not _required_ by CCS on current versions, but is required on older versions, can give problems, even on current compilers, but especially on older compilers.
Code:

#include <UNO_10.h>

#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, PUT, NOLVP

#use fast_io(b)
int1 flag_int_RB4 = FALSE;

void parpadeo (void)
{
   int i=0;

   for(i=0; i<12; i++)
   {
      output_high(PIN_A1);
      delay_ms(500);   
      output_low(PIN_A1);
      delay_ms(500);
   }
   
  output_high(PIN_A1);
}

    // standard i/o is the default.
    // it is easier to handle interrupt on change with the pins
    // fixed regarding their i/o, hence selecting fast_io.
   
#int_RB
void  RB_isr(void)
{
   static int1 old_RB4=1;
   //handle  RB4
   if(input(PIN_B4)) //PIN is high
       old_RB4=1;  //record this
   else
   {
       if(old_RB4==1) //pin is now low, and was high
       { //RB4 has changed to low
           old_RB4=0;
           flag_int_RB4=TRUE;
       }
   }         
}

void main(void)
{
   int temp;
   set_tris_b(0XF0); //since you want to interrupt on B4, and B7
                    //they_must_be (u) inputs (/u);

   port_B_pullups(0xFF);
   setup_comparator(NC_NC_NC_NC);
   temp=input_b(); //you must read the port to reset the change latch
   
   clear_interrupt(INT_RB);
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
   
   while(TRUE)
   {
      if(flag_int_RB4)
      {
         flag_int_RB4=FALSE;
         //RB4 has now drppped -do what you want
         parpadeo();
      }           
   }///llave de cierre del while
}////llave de cierre del main


If this doesn't work, then check your hardware. Are you sure RB4 actually is changing?. Are you sure the code was for the same chip?. On some modern PIC's you must use individual bit input to clear the latch, while a few older chips require byte reads to clear the latch. If the 887 is one where this applies, then the interrupt code will never exit.

Generally, you can run CCS code pretty universally, unless you are talking major changes (like between a V3 program and a V4 program, where some tweaking will apply). However even with this level of change, something as simple as this ought to work with just about any compiler version.

Are you sure the chip actually is starting?. Could be something as silly as an incorrect power connection, or MCLR not pulled up....
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