/Users/farid11/MPLABXProjects/simple C Code/C_Blink_LED.X/Interrupt_Example.c |
1
2
3
4
5
6
7
8
9
10 #include <stdio.h>
11 #include <math.h>
12 #include <xc.h>
13 #include "p18f45k20.h"
14 #include <stdlib.h>
15 #define _XTAL_FREQ 4000000
16 #pragma config FOSC = INTIO67
17 #pragma config FCMEN = OFF
18 #pragma config IESO = OFF
19
20
21 #pragma config PWRT = ON
22 #pragma config BOREN = SBORDIS
23 #pragma config BORV = 30
24
25
26 #pragma config WDTEN = OFF
27 #pragma config WDTPS = 32768
28
29
30 #pragma config CCP2MX = PORTC
31 #pragma config PBADEN = OFF
32 #pragma config LPT1OSC = OFF
33 #pragma config HFOFST = OFF
34 #pragma config MCLRE = OFF
35
36
37 #pragma config STVREN = ON
38 #pragma config LVP = OFF
39 #pragma config XINST = OFF
40
41
42 #pragma config CP0 = OFF
43 #pragma config CP1 = OFF
44 #pragma config CP2 = OFF
45 #pragma config CP3 = OFF
46
47
48 #pragma config CPB = OFF
49 #pragma config CPD = OFF
50
51
52 #pragma config WRT0 = OFF
53 #pragma config WRT1 = OFF
54 #pragma config WRT2 = OFF
55 #pragma config WRT3 = OFF
56
57
58 #pragma config WRTC = OFF
59 #pragma config WRTB = OFF
60 #pragma config WRTD = OFF
61
62
63 #pragma config EBTR0 = OFF
64 #pragma config EBTR1 = OFF
65 #pragma config EBTR2 = OFF
66 #pragma config EBTR3 = OFF
67
68 #define LG LATDbits.LD5
69 void interrupt low_priority CheckButtonPressed(){
70 int k=0;
71 if(INTCONbits.INT0IF){
72 LG=!LG;
73 for(k=0;k<5;k++)
74 __delay_ms(100);
75 INTCONbits.INT0IF=0;
76 }
77 }
78
79 int main(){
80 TRISDbits.RD5=0;
81 TRISBbits.RB0=1;
82
83 LG=0;
84 RCONbits.IPEN=1;
85 INTCONbits.GIEH=1;
86 INTCON2bits.INTEDG0=1;
87 INTCONbits.INT0IE=1;
88 INTCONbits.INT0IF=0;
89
90 while(1){
91
92 }
93
94 }
95
96