-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
101 lines (85 loc) · 2.61 KB
/
main.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
/* ========================================
*
* Copyright YOUR COMPANY, THE YEAR
* All Rights Reserved
* UNPUBLISHED, LICENSED SOFTWARE.
*
* CONFIDENTIAL AND PROPRIETARY INFORMATION
* WHICH IS THE PROPERTY OF your company.
*
* ========================================
*/
#include "project.h"
char dataReady=0;
unsigned int ADCresult;
unsigned int voltaje;
unsigned char control=0;
void control_intensidad_led(void);
CY_ISR(contador);
CY_ISR(ADC_INT);
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
isr_ADC_StartEx(ADC_INT);
ADC_IRQ_Enable();
ADC_Start();
LCD_Start();
LCD_ClearDisplay();
LCD_PrintString("Voltaje medido [mV]:");
PWM_Init();
Contador_Start();
isr_500ms_StartEx(contador);
for(;;)
{
if (dataReady==1){ // counts to mV hace lo mismo que 5000/4095
dataReady=0;
voltaje=(ADCresult);//*(5000/4095)); // agrego tantos 0s al 5 para mostrar mili, micro... etc
voltaje=ADC_CountsTo_mVolts(ADCresult); // sirve para cuando use todo el rango de voltaje
}
if (voltaje>2000){
led_Write(1);
}
if (voltaje<=2000){
led_Write(0);
}
if (voltaje<=500)PWM_Stop();
if (500 <= voltaje && voltaje <= 1000) {
PWM_Stop();PWM_WritePeriod(10000);PWM_WriteCompare(100);PWM_Start();
}
if (1001 <= voltaje && voltaje <= 2000){
PWM_Stop();PWM_WritePeriod(10000);PWM_WriteCompare(500);PWM_Start();
}
if (2001 <= voltaje && voltaje <= 3000){
PWM_Stop();PWM_WritePeriod(10000);PWM_WriteCompare(2500);PWM_Start();
}
if (3001 <= voltaje && voltaje <= 4000) {
PWM_Stop();PWM_WritePeriod(10000);PWM_WriteCompare(5000);PWM_Start();
}
if (4001 <= voltaje && voltaje <= 5000) {
PWM_Stop();PWM_WritePeriod(10000);PWM_WriteCompare(10000);PWM_Start();
}
LCD_Position(2,0);
LCD_PrintNumber(voltaje);
}
}
CY_ISR(ADC_INT){
dataReady=1;
ADCresult=ADC_GetResult16();
}
CY_ISR(contador){
ADC_StartConvert();
}
/* [] END OF FILE */
//void control_intensidad_led()
//{
// if (500 <= voltaje && voltaje <= 1000) {
// PWM_Start();PWM_WritePeriod(50000);PWM_WriteCompare(45000);
// }
// if (2000 <= voltaje && voltaje <= 3000){
// PWM_Start();PWM_WritePeriod(50000);PWM_WriteCompare(40000);
// }
// if (4000 <= voltaje && voltaje <= 5000) {
// PWM_Start();PWM_WritePeriod(1999);PWM_WriteCompare(49999);
// }
// else PWM_Stop();
//}