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

Trouble with EXT INT

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



Joined: 21 Nov 2017
Posts: 2

View user's profile Send private message

Trouble with EXT INT
PostPosted: Tue Nov 21, 2017 11:50 am     Reply with quote

I'm new to PIC.
I need 4 ext int for a project. A quick example as is follow, however I'm unable to make the ext int to work. The input pins are working as normal input (under main) however none of them is responding from interrupt.
Any help will be appreciated.
Code:

#include <16f877a.h>

#fuses HS,NOWDT,NOPROTECT,BROWNOUT,NOLVP,NOCPD
#use delay(clock = 20MHz)
//#use fast_io(b)


// LCD 2x16
#define LCD_DB7             PIN_D7
#define LCD_DB6             PIN_D6
#define LCD_DB5             PIN_D5
#define LCD_DB4             PIN_D4
#define LCD_RS              PIN_D3
#define LCD_RW              PIN_D2 
#define LCD_E               PIN_D1

#include <flex_LCD.c>


#define BUTTON_A           PIN_B4
#define BUTTON_B           PIN_B5
#define BUTTON_C           PIN_B6
#define BUTTON_D           PIN_B7

int state = 0;


// ############################################################################
#INT_EXT
void btn_int() {
   if(input(BUTTON_A)) {
      state = 1;
   }
   if(input(BUTTON_B)) {
      state = 2;
   }
   if(input(BUTTON_C)) {
      state = 3;
   }
   if(input(BUTTON_D)) {
      state = 4;
   }
}


// ############################################################################
void main ()
{
   set_tris_b(0x1E);
   
   lcd_init();               // LCD start
   delay_ms(20);
   lcd_putc("\f");           // Clear the LCD
   delay_ms(100);

   ext_int_edge( L_TO_H );   // Sets up EXT
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
 
   while(TRUE){
      lcd_gotoxy(1,2);           
      switch(state) {
         case 1:
            printf(lcd_putc, "Action 1");
            // ... 
            break;
         case 2:
            printf(lcd_putc, "Action 2");
            // ... 
            break;
         case 3:
            printf(lcd_putc, "Action 3");
            // ... 
            break;
         case 4:
            printf(lcd_putc, "Action 4");
            // ... 
            break;
      }

   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19554

View user's profile Send private message

PostPosted: Tue Nov 21, 2017 12:21 pm     Reply with quote

INT_EXT, only works on pin B0.

The interrupt you are trying to use is the interrupt on change. INT_RB.

Interrupt on change triggers always on both edges (L_TO_H only applies to INT_EXT).

There is another problem in the approach.

If (for instance) B7 goes high, 'state' will equal 4. However another then triggers without this releasing, the interrupt will be called again, and it'll still return '4', ignoring the others that have triggered....
temtronic



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

View user's profile Send private message

PostPosted: Tue Nov 21, 2017 2:29 pm     Reply with quote

I seem to recall that CCS has an 'how-to' in the FAQ section of the manual...
not on the eng pc so I can't look it up...
dhpl



Joined: 21 Nov 2017
Posts: 2

View user's profile Send private message

PostPosted: Tue Nov 21, 2017 8:53 pm     Reply with quote

Many thanks for your reply.
I changed the interrupt to int_rb. Not much success.
Read a lot of how to, but couldn't figure out the rb approach. Shading more lights may help. Smile
temtronic



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

View user's profile Send private message

PostPosted: Tue Nov 21, 2017 9:09 pm     Reply with quote

CCS has an example 'ex_pbutt.c' that may work for you...

there is another , I thought was in the FAQ section of the manual.. I KNOW it's 'somewhere' as I used it on an 877 years ago... it showed how in the ISR you read the port, decide which pin was active (RB4,RB5,RB6 or RB7).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 21, 2017 9:11 pm     Reply with quote

Look at this CCS examples file:
Quote:

Ex_pbutt.c

It's in the Examples folder on your PC for CCS.
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