Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

RetoFinal.c 26/04/2023 11:16:19 a. m.

1: //definimos conexiones
2: sbit LCD_RS at LATB0_bit;
3: sbit LCD_EN at LATB1_bit;
4: sbit LCD_D4 at LATB2_bit;
5: sbit LCD_D5 at LATB3_bit;
6: sbit LCD_D6 at LATB4_bit;
7: sbit LCD_D7 at LATB5_bit;
8:
9: // Pin direction
10: sbit LCD_D7_Direction at TRISB5_bit;
11: sbit LCD_D6_Direction at TRISB4_bit;
12: sbit LCD_D5_Direction at TRISB3_bit;
13: sbit LCD_D4_Direction at TRISB2_bit;
14: sbit LCD_EN_Direction at TRISB1_bit;
15: sbit LCD_RS_Direction at TRISB0_bit;
16: //end LCD mc
17:
18: // Define variables
19: int pot1=0;
20: int pot2=0;
21: float valor1=0;
22: float valor2=0;
23: int pwm=0;
24: int pwm2=0;
25:
26: char valor[]=" ";//valor de porcentaje a char
27: char val2[]=" ";//valor de porcentaje a char
28:
29: char t1[] = "Temperatura";
30: char t2[] = "Agitacion";
31: char t3[] = "CO2";
32: int raw_temp;
33: char *temp = "000.0000 C";
34:
35: void main() {
36: //Inicialización de puertos
37: ADCON1=0b00001101;
38: TRISC=0;
39: TRISB=0;
40: PORTB=0;
41: PORTC=0;
42: TRISA.F0=1;
43: TRISA.F1=1;
44: TRISD=0B0000111;
45: PORTD=0;
46: TRISE=1;
47: PORTB.F7=1;
48:
49:
50: //iniciar PWM
51: PWM1_Init(1222);
52: PWM1_Start();
53:
54: PWM2_Init(1222);
55: PWM2_Start();
56:
57: //iniciar ADC
58: ADC_Init();
59:
60: //Iniciar LCD
61: Lcd_Init();
62: Lcd_Cmd(_LCD_CURSOR_OFF);

1/3 mikroC PRO for PIC by mikroElektronika


RetoFinal.c 26/04/2023 11:16:19 a. m.

63: Lcd_Cmd(_LCD_CLEAR);
64:
65: while(1){
66: if (PORTE.F3 == 1){
67: while(1){
68:
69: if (PORTD.F0 == 1){
70: Ow_Reset(&PORTD, 3);
71: Ow_Write(&PORTD, 3, 0xCC);
72: Ow_Write(&PORTD, 3, 0X44);
73:
74: while(Ow_Read(&PORTD, 3) == 0) ;
75: Ow_Reset(&PORTD, 3);
76: Ow_Write(&PORTD, 3, 0xCC);
77: Ow_Write(&PORTD, 3, 0xBE);
78:
79: raw_temp = Ow_Read(&PORTD, 3);
80: raw_temp |= (Ow_Read(&PORTD, 3) << 8);
81:
82: if(raw_temp & 0x8000) {
83: temp[0] = '-';
84: raw_temp = ~raw_temp + 1;
85: }
86:
87: else {
88: if((raw_temp >> 4) >= 100)
89: temp[0] = '1';
90: else
91: temp[0] = ' ';
92: }
93:
94:
95: temp[1] = ( (raw_temp >> 4) / 10 ) % 10 + 48;
96: temp[2] = (raw_temp >> 4) % 10 + 48;
97:
98:
99: temp[4] = ( (raw_temp & 0x0F) * 625) / 1000 + 48;
100: temp[5] = (((raw_temp & 0x0F) * 625) / 100 ) % 10 + 48;
101: temp[6] = (((raw_temp & 0x0F) * 625) / 10 ) % 10 + 48;
102: temp[7] = ( (raw_temp & 0x0F) * 625) % 10 + 48;
103:
104: temp[8] = 223;
105: lcd_out(1, 3, t1);
106: lcd_out(2, 4, temp);
107:
108: delay_ms(500);
109: }
110:
111: else if(PORTD.F1==1) {
112: // Display "Agitacion"
113: Lcd_Cmd(_LCD_CLEAR);
114: pot2=ADC_Read(1);
115: valor2=pot2/10.23;
116: pwm2=(pot2*255)/1023;
117: FloatToStr(valor2,val2);
118: PWM2_SET_DUTY(pwm2);
119: Lcd_Out(1,1,t2);
120: Lcd_Out(2,1,val2);
121: delay_ms(500);
122: }
123:
124:

2/3 mikroC PRO for PIC by mikroElektronika


RetoFinal.c 26/04/2023 11:16:19 a. m.

125: else if(PORTD.F2==1) {


126:
127: Lcd_Cmd(_LCD_CLEAR);
128: Lcd_Out(1, 7, t3);
129:
130: pot1=ADC_Read(0);
131: valor1=(pot1/10.23);
132: pwm=(pot1*255)/1023;
133: FloatToStr(valor1,valor);
134:
135: PWM1_SET_DUTY(pwm);
136:
137: Lcd_Out(2, 2, valor);
138: Lcd_Chr_CP('%');
139: delay_ms(500);
140: }
141: else {
142: Lcd_Cmd(_LCD_CLEAR);
143: }
144: }
145: }
146: }
147: }

3/3 mikroC PRO for PIC by mikroElektronika

You might also like