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

I Need to know my RB interrupt

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



Joined: 02 Oct 2013
Posts: 4

View user's profile Send private message

I Need to know my RB interrupt
PostPosted: Wed Aug 20, 2014 8:28 am     Reply with quote

What is the problem in my code. Please help me.

Code:

#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

int set=0;

#INT_RB
void RB_SERV(){
   if(input(PIN_B7)){            //externally pulluped
      set=1;                      // variable for to avoid the delay function into this subroutine
   }
}     

void main(){
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
   while(TRUE){
      if(set==1){                  //This set variable act like the same thing. but in main function
         write_eeprom(0x00,4);
         delay_ms(5);              //Because the EEPROM writing is need some delay to next operation.
         write_eeprom(0x01,7);     // So this variable avoid this writing process into interrupt subroutine
         delay_ms(5);
         write_eeprom(0x02,9);
         delay_ms(5);
         write_eeprom(0x03,2);
         delay_ms(5);
         output_high(PIN_D2);
         delay_ms(100);
         output_low(PIN_D2);
         delay_ms(10);
         set=0;                    //After finishing the variable set to 0 for next and avoid again and again...
      }
   }
}           

Pin B7 was to detect the power failure case. So this pin was connected with 7805 output with the help of a transistor.

Collector pin was connected with the PIN B7 pin.
Emitter pin was connected to ground.
Base pin was connected to 7805 output.

A large Capacitor(4700uf 25v) was connected with MCU's VDD and VSS for making delay. This delay time the writing process was running.

This method was working properly good in Proteus. But in hardware the interrupt was fired again and again... Even the pin state not change.
When I remove the Transistor Base pin that time the loop was contentiously running.

What is the problem in my code ?.
please help me.
_________________
Thanks and Regards
Sureshkumar.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 20, 2014 8:46 am     Reply with quote

On the 16F877, when you enable INT_RB interrupts, you enable them for
pins B4, B5, B6, and B7. But I suspect that you have pins B4, B5, B6
un-connected (floating input pins). This may cause continuous INT_RB
interrupts. To fix this problem, enable Port B pullups, wait a short time
for them to pull-up, then read PortB to clear the interrupt-on-change
condition latches, and then clear the INT_RB interrupt flag. See the
code below. After doing this, pins B4-B6 should not cause unwanted
INT_RB interrupts.

Add the code shown in bold below:
Quote:

void main()
{
int8 temp;

port_b_pullups(TRUE);
delay_us(10);
temp = input_b();
clear_interrupt(INT_RB);


enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
sureshkumar



Joined: 02 Oct 2013
Posts: 4

View user's profile Send private message

PostPosted: Wed Aug 20, 2014 10:04 am     Reply with quote

PCM programmer wrote:
On the 16F877, when you enable INT_RB interrupts, you enable them for
pins B4, B5, B6, and B7. But I suspect that you have pins B4, B5, B6
un-connected (floating input pins). This may cause continuous INT_RB
interrupts. To fix this problem, enable Port B pullups, wait a short time
for them to pull-up, then read PortB to clear the interrupt-on-change
condition latches, and then clear the INT_RB interrupt flag. See the
code below. After doing this, pins B4-B6 should not cause unwanted
INT_RB interrupts.

Add the code shown in bold below:
Quote:

void main()
{
int8 temp;

port_b_pullups(TRUE);
delay_us(10);
temp = input_b();
clear_interrupt(INT_RB);


enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
Ok thanks a lot Sir, Yes I am leaving other pins without pullup and pulldown. Software pullup is enough ?.
But I need to execute at once for EEPROM writing purpose when the power is gone. I just add your code like this but the loop was continuously running even the pin is same state. If I need to make external pullup ?.
My requirement is when this pins go high that time only once write the data into eeprom. The capacitor will also goes discharged. Not issue. Even I think some mistake on my code sir.

My Question is Why this PIN_D2 always run even the B7 pin in same state ?.

What is the difference between if(input(PIN_B7)) and if ((!bit_test(last,7))&&(bit_test(current,7)))
Code:

#int_rb
void detect_rb_change() {
   int current;
   static int last=0;

   set_tris_b(0xF0);
   current=input_b();

   #if LOWTOHIGH
   if ((!bit_test(last,4))&&(bit_test(current,4))) {dbutton4=1;}
   if ((!bit_test(last,5))&&(bit_test(current,5))) {dbutton5=1;}
   if ((!bit_test(last,6))&&(bit_test(current,6))) {dbutton6=1;}
   if ((!bit_test(last,7))&&(bit_test(current,7))) {dbutton7=1;}
   #elif HIGHTOLOW
   if ((!bit_test(current,4))&&(bit_test(last,4))) {dbutton4=1;}
   if ((!bit_test(current,5))&&(bit_test(last,5))) {dbutton5=1;}
   if ((!bit_test(current,6))&&(bit_test(last,6))) {dbutton6=1;}
   if ((!bit_test(current,7))&&(bit_test(last,7))) {dbutton7=1;}
   #endif

   last=current;
}

Code:

#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

int set=0;

#INT_RB
void RB_SERV(){
   if(!input(PIN_B7)){        //externally pulluped
      set=1;                      // variable for to avoid the delay function into this subroutine
   }                                // I think here is the problem if(!input(PIN_B7)) this is just like digital input.
                                   //So when the isr fired this state was executed.
                                  //so I the if(set==1) was in super loop,  that is why always run. I need this run at once.
}     

void main(){
   int temp;
   port_b_pullups(TRUE);
    delay_us(10);
    temp = input_b();
   
   clear_interrupt(INT_RB);
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
   while(TRUE){
      if(set==1){                  //This set variable act like the same thing. but in main function
         /*write_eeprom(0x00,4);
         delay_ms(5);              //Because the EEPROM writing is need some delay to next operation.
         write_eeprom(0x01,7);     // So this variable avoid this writing process into interrupt subroutinue
         delay_ms(5);
         write_eeprom(0x02,9);
         delay_ms(5);
         write_eeprom(0x03,2);
         delay_ms(5);*/
         output_high(PIN_D2);
         delay_ms(1000);
         output_low(PIN_D2);
         delay_ms(1000);
         set=0;                    //After finishing the variable set to 0 for next and avoid again and again...
      }
   }
}           


Code:

#INT_RB
void RB_SERV(){
   if(!input(PIN_B7)){        //externally pulluped
      set=1;                      // variable for to avoid the delay function into this subroutine
   }                                // I think here is the problem if(!input(PIN_B7)) this is just like digital input.
                                    //So when the isr fired this state was executed.
                                   //So the if(set==1) was in super loop,  that is why always run. I need this run at once.
}

_________________
Thanks and Regards
Sureshkumar.
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