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 support@ccsinfo.com

Interrupt handling in general

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







Interrupt handling in general
PostPosted: Wed Oct 08, 2003 8:45 am     Reply with quote

I've just recently started using my PCM PIC compiler. I find it very difficult to find useful into in the manual about interrupts. In the text for #INT_xxxx a lot of syntax is included with no information about how it works. What, for example, is #INT_BUTTON? Is it used to debounce RB0? Where is an example? A two hour coding project is dragging out into days. And the references I have found in the form, like http://www.pic-c.com/forum/general/posts/2138.html do not exist. I'm not impressed.[/b]
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Oct 08, 2003 9:22 am     Reply with quote

If you study the datasheet on the part that you are programming it will make more sense to you. The defines are taken from the terminology in the datasheet. It took me about 3 mins to find this data.



2. For the 14000 the interrupts #INT_ADOF, #INT_RC, #INT_I2C and #INT_BUTTON
have been added.

Code:

//////// Standard Header file for the PIC14000 device ////////
#device PIC14000
#nolist
/////////////////////////////// I/O definitions for INPUT() and OUTPUT_xxx()
#define PIN_A0  40
#define PIN_A1  41
#define PIN_A2  42
#define PIN_A3  43

#define PIN_C0  56
#define PIN_C1  57
#define PIN_C2  58
#define PIN_C3  59
#define PIN_C4  60
#define PIN_C5  61
#define PIN_C6  62
#define PIN_C7  63

#define PIN_D0  64
#define PIN_D1  65
#define PIN_D2  66
#define PIN_D3  67
#define PIN_D4  68
#define PIN_D5  69
#define PIN_D6  70
#define PIN_D7  71

/////////////////////////////// Useful defines
#define FALSE 0
#define TRUE 1

#define BYTE int
#define BOOLEAN short int

#define getc getch
#define getchar getch
#define puts(s) {printf(s); putchar(13); putchar(10);}
#define putc putchar

/////////////////////////////// Constants used for RESTART_CAUSE()
#define WDT_FROM_SLEEP  0
#define WDT_TIMEOUT     8
#define MCLR_FROM_SLEEP 16
#define NORMAL_POWER_UP 24
/////////////////////////////// Constants used for SETUP_COUNTERS()
#define RTCC_INTERNAL   0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48
#define RTCC_DIV_2      0
#define RTCC_DIV_4      1
#define RTCC_DIV_8      2
#define RTCC_DIV_16     3
#define RTCC_DIV_32     4
#define RTCC_DIV_64     5
#define RTCC_DIV_128    6
#define RTCC_DIV_256    7
#define WDT_18MS        8
#define WDT_36MS        9
#define WDT_72MS       10
#define WDT_144MS      11
#define WDT_288MS      12
#define WDT_576MS      13
#define WDT_1152MS     14
#define WDT_2304MS     15
#define L_TO_H              0x40
#define H_TO_L                 0

#define RTCC_ZERO           0x0B20    // Used for ENABLE/DISABLE INTERRUPTS
#define INT_RTCC            0x0B20    // Used for ENABLE/DISABLE INTERRUPTS
#define RB_CHANGE           0x0B08    // Used for ENABLE/DISABLE INTERRUPTS
#define INT_RB              0x0B08    // Used for ENABLE/DISABLE INTERRUPTS
#define EXT_INT             0x0B10    // Used for ENABLE/DISABLE INTERRUPTS
#define INT_EXT             0x0B10    // Used for ENABLE/DISABLE INTERRUPTS

#define GLOBAL              0x0BC0    // Used for ENABLE/DISABLE INTERRUPTS


///////////////////////////////////// Constants used for SETUP_ADC_PORTS()
#define ALL_ANALOG         0x0   // To setup PORTA and PORTD, 'A'
#define RA0_RA1_RA2_ANALOG 0x1   // and 'D' values should be ORed
#define RA0_RA1_ANALOG     0x2
#define A_NO_ANALOGS       0x3
#define RD4_RD5_RD6_ANALOG 0x4
#define RD4_RD5_ANALOG     0x8
#define D_NO_ANALOGS       0xC
#define NO_ANALOGS         0xf

///////////////////////////////////// Constants used for SETUP_ADC()
#define CURRENT_0          0x00
#define CURRENT_2          0x10
#define CURRENT_4          0x20
#define CURRENT_7          0x30
#define CURRENT_9          0x40
#define CURRENT_11         0x50
#define CURRENT_13         0x60
#define CURRENT_16         0x70
#define CURRENT_18         0x80
#define CURRENT_20         0x90
#define CURRENT_22         0xA0
#define CURRENT_25         0xB0
#define CURRENT_27         0xC0
#define CURRENT_29         0xD0
#define CURRENT_31         0xE0
#define CURRENT_34         0xF0

///////////////////////////////////// 14000 Special
#define INT_RC             0x8C04
#define INT_BUTTON         0x8C10
#define INT_COMP           0x8C80


#list


Form the PIC14000 datasheet
Quote:

10.6.1 EXTERNAL INTERRUPT
An external interrupt can be generated via the
OSC1/PBTN pin if IN (internal oscillator) mode is
enabled. This interrupt is falling edge triggered. When
a valid edge appears on OSC1/PBTN pin, PBIF
(PIR1<4>) is set. This interrupt can be disabled by
clearing PBIE (PIE1<4>). PBIF must be cleared in software
in the interrupt service routine before re-enabling
the interrupt. This interrupt can wake up the processor
from SLEEP if PBIE bit is set (interrupt enabled) prior
to going into SLEEP mode. The status of the GIE bit
determines whether or not the processor branches to
the interrupt vector following wake-up. The timing of the
external interrupt is shown in Figure 10-10.


PBTN = push button Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 08, 2003 12:26 pm     Reply with quote

And the references I have found in the form, like http://www.pic-c.com/forum/general/posts/2138.html do not exist. I'm not impressed.
------------------------------------------------------------------------------
That's a bad link because all the posts from the previous CCS forum
were appended to this new forum, but the links were not updated to
point to the new forum. So here's a repost of the INT_EXT example.

If you have a specific design problem, then tell us what you're trying
to do, and we'll help you to solve it.


Code:
#include "16F877.h"
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP 
#use Delay(Clock=8000000)                   
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 
#zero_ram     

//-------------------------------
// GLOBALS

char got_interrupt;
char interrupt_count;

#bit INTF_BIT = 0x0B.1

//-----------------------------
// FUNCTION PROTOTYPES

#int_ext
void int_ext_isr(void);


//=============================
void main(void)
{

// Make pin B0 into an input.
output_float(PIN_B0);

// Enable pullups on all port B pins.
port_b_pullups(TRUE);

// Wait for them to pull up.
delay_us(10);

// Initialize the variables used by the interrupt routine,
// before enabling interrupts.
interrupt_count = 0;
got_interrupt = FALSE;

// Since we have port B pullups enabled, the normal state
// of Pin B0 is a high level.  Let's set up the external
// interrupt to occur whenever we get a change from
// a high to a low level.
// We will connect a Normally-open push-button switch to Pin B0.
// The "common" pin of the switch goes to Ground.
// When we press the button, Pin B0 will go to logic low level.
ext_int_edge(H_TO_L);


// Make sure the external interrupt flag bit is cleared
// before enabling external interrupts.
INTF_BIT = 0; 

enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL); 


// Wait in this loop.  Check the got_interrupt flag to see
// if an interrupt occurred.  If so, display the count.
// Then clear the flag, wait 50 ms to avoid any "bounce"
// (multiple interrupts) when we press the pushbutton switch,
// which puts Ground on pin B0.  Then re-enable interrupts.

while(1)
{

if(got_interrupt == TRUE)
  {
   printf("%d\n\r", interrupt_count);

   // Clear the global flag which was set in the interrupt routine.
   got_interrupt = FALSE;

   // Wait for debounce period.  This allows time for the switch contacts
   // to quit bouncing.
   delay_ms(50);   

   // Clear any interrupt which might have occurred during the debounce period.
   INTF_BIT = 0;   
   
   // Then re-enable interrupts.
   enable_interrupts(INT_EXT);
  }

}


}
//========================

#int_ext
void int_ext_isr(void)
{

got_interrupt = TRUE;
interrupt_count++;


disable_interrupts(INT_EXT);

}
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