0% found this document useful (0 votes)
20 views

MikroC Final Reto

This document contains code for integrating a stirring motor, CO2 motor, temperature sensor, and LCD display. It initializes PWM for the motors, ADC for sensors, and LCD display. It then enters a loop to read the temperature sensor and display the temperature when one button is pressed. When another button is pressed, it reads the potentiometer to control the stirring motor PWM and displays the value. For the third button, it controls the CO2 motor PWM based on another potentiometer reading and displays the CO2 value.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

MikroC Final Reto

This document contains code for integrating a stirring motor, CO2 motor, temperature sensor, and LCD display. It initializes PWM for the motors, ADC for sensors, and LCD display. It then enters a loop to read the temperature sensor and display the temperature when one button is pressed. When another button is pressed, it reads the potentiometer to control the stirring motor PWM and displays the value. For the third button, it controls the CO2 motor PWM based on another potentiometer reading and displays the CO2 value.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Retoentregablesemana4.c 26/04/2023 06:25:05 a. m.

1: //LCD PARTE 4 --> integracion del motor de agitacion, motor de CO2


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

1/3 mikroC PRO for PIC by mikroElektronika


Retoentregablesemana4.c 26/04/2023 06:25:05 a. m.

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

2/3 mikroC PRO for PIC by mikroElektronika


Retoentregablesemana4.c 26/04/2023 06:25:05 a. m.

125: Lcd_Out(1, 7, t3);


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

3/3 mikroC PRO for PIC by mikroElektronika

You might also like