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 issue with PIC 16F887

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



Joined: 16 Nov 2014
Posts: 2

View user's profile Send private message

INT_RB issue with PIC 16F887
PostPosted: Sun Nov 16, 2014 1:31 am     Reply with quote

Hi, I have a question about why the next code works perfectly with the 16F877 but if I change the device to a 16F887 it does nothing.
Code:

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

BYTE blink = 0;

#int_rb
void button_isr() {
   delay_ms (20);  //debounce
         if( !input(PIN_B4) && !blink )
              blink = 1;
         else
         if( !input(PIN_B4) && blink )
              blink = 0;
}

void main() {
   enable_interrupts(global);
   enable_interrupts(int_rb);

   ext_int_edge( H_TO_L );

   do {
      if(blink){
         output_high(PIN_D7);
         delay_ms(500);
         output_low(PIN_D7);
         delay_ms(500);
      }
   } while (TRUE);
}

Thanks in advance, best regards.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Sun Nov 16, 2014 1:46 am     Reply with quote

First, it won't 'work perfectly with the 16F877'. There are major problems:

1) Ext_int_edge, does nothing. It is not for interrupt on change.
2) Your interrupt will on average not be called for nearly 1/4 second. This is caused by having a delay in the interrupt. A search will find why this shouldn't be done....
As written you might as well not use the interrupt at all. Just poll the input after each delay in the main. This is how the code will be functioning....

As for why it runs differently on the 887, this is a 'read the data sheet' one. What is on pin B4, on the 887, that isn't there on the 877?. Keyword analog....
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Nov 16, 2014 6:19 am     Reply with quote

hmm...
first line..

#include <16F877.h>

Although you say you changed the device header, as posted your code will use the 877 header NOT the 887 header.
You must post the exact code you're using NOT the one that worked for another PIC..
As Mr T points out there are several things wrong with the 877 code however there may be more with your 887 code as we don't know what other changes you may have made.

jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 16, 2014 9:57 am     Reply with quote

To amplify previous posts,

Recent versions set ANSELH to 0, which makes pin B4 digital i/o. Which
would mean that's not the problem. He didn't give his compiler version
so we don't know if his version does this.
Quote:
.................... void main() {
005D: MOVF STATUS,W
005E: ANDLW 1F
005F: MOVWF STATUS
0060: CLRF blink
0061: BSF STATUS.RP0
0062: BSF STATUS.RP1
0063: MOVF ANSELH,W
0064: ANDLW C0
0065: MOVWF ANSELH


The real reason will be the delays. If he had warnings turned on, he
would see this:
Quote:

>>> Warning 216 "PCM_Test.c" Line 31(1,2): Interrupts disabled during
call to prevent re-entrancy: (@delay_ms1)
Perrinsky



Joined: 16 Nov 2014
Posts: 2

View user's profile Send private message

PostPosted: Tue Nov 18, 2014 1:22 am     Reply with quote

Hi again guys and thanks for your answers. Sorry I missed the version, it's the 4.104.

My code is almost the same:
Code:

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

#byte STATUS=0x03
#byte ANSELH=0x189

BYTE blink = 0;

#int_rb
void button_isr() {

   if( !input(PIN_B4) && !blink )
         blink = 1;
   else
      if( !input(PIN_B4) && blink )
         blink = 0;
}

void main() {
   
   enable_interrupts(global);
   enable_interrupts(int_rb);
   
   STATUS=0b01100000;        /* RP1 = RP0 = 1
   ANSELH=0;

   setup_adc_ports(no_analogs);

   do {
         if(blink){
             output_high(PIN_D7);
             delay_ms(500);
             output_low(PIN_D7);
             delay_ms(500);
      }
   } while (TRUE);
}

I made a few improvements after reading your answers (thanks a lot). I've tried also to set ANSELH to zero and STATUS byte with RP1 and RP0 to 1 but it's still doing nothing.

Sorry I'm new to interrupts and I haven't found any example that works with this PIC.

Thanks again to all.
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