0% found this document useful (0 votes)
5 views3 pages

PIC Microcontroller Interrupt Examples

Uploaded by

Mlik Med Koussay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

PIC Microcontroller Interrupt Examples

Uploaded by

Mlik Med Koussay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

----------------------------------------------------------EXERCICE 1

#include <xc.h>
#define _XTAL_FREQ 8000000
#pragma config OSC=HS ,WDT=OFF,LVP=OFF,PWRT=ON
#define led PORTCbits.RC0

void __interrupt ()ISR(){


if(INT0IF==1){
led =!led;
}

INT0IF=0;
}
void main(void) {
INTCON=0x90;
INTCON2=0b01000000;
ADCON1=0x0F;
TRISC=0x00;
TRISB=0xFF;
while(1){

return;
}
------------------------------------------------------------------EXERCICE 2

#include <xc.h>
#define _XTAL_FREQ 8000000
#pragma config OSC=HS ,WDT=OFF,LVP=OFF,PWRT=ON
#define led PORTCbits.RC0

void __interrupt ()ISR(){


if(INT0IF==1){
led =1;
__delay_ms(1000);
led =0;
}

INT0IF=0;
}
void main(void) {
INTCON=0x90;
INTCON2=0b01000000;
ADCON1=0x0F;
TRISC=0x00;
TRISB=0xFF;
while(1){
PORTCbits.RC1=1;
__delay_ms(500);
PORTCbits.RC1=0;
__delay_ms(500);
}
return;
}
----------------------------------------------------------------------------------
EXERCICE 3 (compteur simple)
#include <xc.h>
#pragma config OSC=HS,WDT=OFF,LVP=OFF, PWRT=ON
#define _XTAL_FREQ 8000000
void main(void)
{
ADCON1=0x0F;
TRISC=0x00;

char t[10] = {0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110,


0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01101111};

while (1){
for (char i=0 ;i<10;i++){
PORTC=t[i];
__delay_ms(300);
}
}
}
-------------------------------------------------------HATHA FEL DAR !!!!! :
#include <xc.h>
#pragma config OSC=HS,WDT=OFF,LVP=OFF, PWRT=ON
#define _XTAL_FREQ 8000000
char compteur(int i){
char t[10] = {0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110,
0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01101111};
return t[i];
}
int i=0;
void __interrupt()ISR(){
if (INT0IF){
PORTC=compteur(i);
i++;
if (i==10){
i=0;
}
INT0IF=0;
}
if (INT1IF){
if (i==0){
i=10;
}
i--;
PORTC=compteur(i);

INT1IF=0;
}
}
void main(void)
{
ADCON1=0x0F;

TRISC=0x00;
TRISB=0xFF;
INTCON=0x90;
INTCON2=0xC0;
INTCON3=0x08;

PORTD=0;
while (1){

You might also like