-
Notifications
You must be signed in to change notification settings - Fork 1
/
Interrup.c
103 lines (93 loc) · 2.69 KB
/
Interrup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include"Interrup.h"
unsigned contador = 0;
void interrupt INTERRUPTION() {
// #ifdef usePWM
INTERRUPTION_Timer0();
// #endif
// #ifdef useADC
// INTERRUPTION_ADC();
// #endif
// #ifdef useSerial
INTERRUPTION_Serial();
// #endif
return;
}
//#ifdef usePWM
void INTERRUPTION_Timer0(){
if(INTCONbits.TMR0IF) { //TIMER0 OVERFLOW?
INTCONbits.TMR0IF = 0;
PWM_Execute(); //CHAMA FUNÇÃO PWM
TMR0L = freq;
// PID_interrupt_I2C();
}
return;
}
//#endif
//#ifdef useSerial
void INTERRUPTION_Serial(){
if(PIR1bits.RCIF){
PIR1bits.RCIF = 0;
if(waitToken('_'))
{
SerialReadUntilToken('_');
// SerialWrite("ok\r\n");
if(SerialReceivedString[0] == '1'){
_pwm[0]+=1;
}
if(SerialReceivedString[0] == '0'){
_pwm[0]-=1;
}
if(SerialReceivedString[0] == '3'){
_pwm[1]+=1;
}
if(SerialReceivedString[0] == '2'){
_pwm[1]-=1;
}
if(SerialReceivedString[0] == '5'){
_pwm[2]+=1;
}
if(SerialReceivedString[0] == '4'){
_pwm[2]-=1;
}
if(SerialReceivedString[0] == '7'){
_pwm[3]+=1;
}
if(SerialReceivedString[0] == '6'){
_pwm[3]-=1;
}
if(SerialReceivedString[0] == 't'){
_pwm[0]=255;
_pwm[1]=255;
_pwm[2]=255;
_pwm[3]=255;
}
if(SerialReceivedString[0] == 'g'){
_pwm[0]=127;
_pwm[1]=127;
_pwm[2]=127;
_pwm[3]=127;
}
if(SerialReceivedString[0] == 'b'){
_pwm[0]=1;
_pwm[1]=1;
_pwm[2]=1;
_pwm[3]=1;
}
}
}
return;
}
//#endif
//#ifdef useADC
void INTERRUPTION_ADC(){
if(PIR1bits.ADIF){
PIR1bits.ADIF = 0;
ADC_Channel++;
if(ADC_Channel >= ADC_NChannel)
ADC_Channel = 0;
ADC_Read_Interrupt(ADC_Channel);
__delay_us(10);__delay_us(10);__delay_us(10);__delay_us(10);__delay_us(10);
}
return;
}
//#endif