/*Author :King Diaw
Project : Setup External Interrupt
Project description : RB0 is Interrupt Input, RB7 is output connect to LED, Every time push button pressed LED will invert condition 1-0,0-1. */
// include
//==========================================================================
#include <pic.h>
// configuration
//==========================================================================
__CONFIG ( 0x3F32 );
// define
//==========================================================================
#define led RB7 //led indicator
#define sw1 RB0 //sw1 (active low)
// function prototype
//==========================================================================
void delay(unsigned long data);
void init_io(void);
void blink(void);
void setup_int(void);
void prog1(void);
// main function
//==========================================================================
void main(void)
{
init_io();
setup_int();
blink();
while(1);
}
//=========================FUNCTIONS======================================
void init_io(void)
{
//set I/O input output
TRISB = 0b00000001; //configure PORTB I/O direction
TRISC = 0b00000000; //configure PORTC I/O direction
TRISA = 0b00000000; //configure PORTA I/O direction
TRISD = 0b00000000; //configure PORTA I/O direction
PORTA=0;PORTB=0;PORTC=0;PORTD=0; //clear all port
//setup ADC
ADCON1 = 0b00000110; //set ADx pin to digital I/O
}
void blink(void)
{
unsigned char i;
for(i=0;i<5;i++)
{
led=!led;
delay(30000);
}
led=1;
}
//========================================================================
void delay(unsigned long data) //delay function, the delay time
{
for( ;data>0;data–); //depend on the given value
}
void setup_int(void)
{
OPTION=0x40;
INTCON=0x90;
}
//interrupt vector
static void interrupt ISR_ssp(void) @0x0004
{
if(INTF==1)
led=!led;
INTF=0;
}