codigo_fuente_pic18f4550.
c 25/09/2018 19:51:20
1: #define electr_valv1 PORTE.RE0 //RC0 Pin de entrada digital de pulsador
2: //#define Led PORTA.RA1 //RA1 Pin de salida digital de led
3: // LCD module connections
4: sbit LCD_RS at RB2_bit;
5: sbit LCD_EN at RB3_bit;
6: sbit LCD_D4 at RB4_bit;
7: sbit LCD_D5 at RB5_bit;
8: sbit LCD_D6 at RB6_bit;
9: sbit LCD_D7 at RB7_bit;
10:
11: sbit LCD_RS_Direction at TRISB2_bit;
12: sbit LCD_EN_Direction at TRISB3_bit;
13: sbit LCD_D4_Direction at TRISB4_bit;
14: sbit LCD_D5_Direction at TRISB5_bit;
15: sbit LCD_D6_Direction at TRISB6_bit;
16: sbit LCD_D7_Direction at TRISB7_bit;
17: // End LCD module connections
18:
19: //unsigned int in = 0;
20: //char arr[11] = "0123456789";
21: char txtHumI1[20];
22: char txtHumI1_1[20];
23: char txtHumI2[20];
24: char txtHumI2_2[20];
25: char txtTempE[10];
26: char txtTempE_1[10];
27: const char character[] = {14,10,14,0,0,0,0,0};
28: void CustomChar(char pos_row, char pos_char) {
29: char i;
30: Lcd_Cmd(64);
31: for (i = 0; i<=7; i++) Lcd_Chr_CP(character[i]);
32: Lcd_Cmd(_LCD_RETURN_HOME);
33: Lcd_Chr(pos_row, pos_char, 0);
34: }
35:
36:
37: void main() {
38: float HumInt01=0;
39: float HumInt02=0;
40: float HumExt=0;
41: float TempExt=0;
42: int H1invert=0;
43: int H2invert=0;
44: //varaibles para el menu de LCD
45: int variable=0;
46: int contador=0;
47: //fin de las varaibles para el menu de LCD
48: ADCON0 = 0b00000011; // los bit 7y6="00" no se utilizan, los bits 5,4,3y2="0000
0" indica que el PORT AN0 sera el canal leido
49: // y los bits 1="1" indica que la convercion ADC esta en p
proceso y finalmente el bit "0"=1 indica que el ADC esta habilitado
50: ADCON0 = 0b00000011;
51: ADCON0 = 0b00000111;
52: ADCON0 = 0b00001011;
53: ADCON0 = 0b00001111;
54: ADCON1 = 0b00001011; // los puertos AN 0-3 configuradas como entradas analógica
as
55: ADCON2 = 0b10111110;
56: CMCON |= 7; // Comparadores desactivados
57:
58: PORTA = 0x00; //Inicializamos el PORTA en "ceros"
59: PORTB = 0x00; //Inicializamos el PORTB en "ceros"
1/4 mikroC PRO for PIC by mikroElektronika
codigo_fuente_pic18f4550.c 25/09/2018 19:51:20
60: PORTC = 0x00; //Inicializamos el PORTB en "ceros"
61: PORTD = 0x00; //Inicializamos el PORTD en "ceros"
62:
63: TRISA.RA0 = 1; // PORT RA0 como entrada
64: TRISA.RA1 = 1; // PORT RA1 como entrada
65: TRISA.RA2 = 1; // PORT RA2 como entrada
66: TRISC.RC4 = 1; // PORT RC7 como ENTRADA
67:
68: TRISD = 0; //PORTD COMO SALIDA
69:
70: TRISE.RE0 = 0; // PORT RE0 como salida
71: //TRISB = 0x78; // PORTB como salida
72: Lcd_Init();
73: ADC_Init();
74: // Initialize LCD
75:
76: Lcd_Cmd(_LCD_CLEAR); // Clear display
77: Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
78: delay_ms(100);
79: // Write text in first row
80:
81: while(contador=0){
82: delay_ms(500);
83: HumInt01 = (ADC_Read(0)*100.0)/1023.0;
84: Lcd_Out(1,1,"Hum1:");
85: FloatToStr_FixLen(HumInt01,txtHumI1,4);
86: //Lcd_Chr(1,6,48+txtHumI1);
87: //Lcd_Out_Cp(Ltrim(txtHumI1));
88: //Lcd_Out_Cp(txtHumI1);
89: //Lcd_Out_Cp("%");
90:
91:
92: }
93: do {
94:
95: H1invert= (ADC_Read(0)*100.0)/1023.0;
96: HumInt01 = 100 - H1invert;
97: //Lcd_Out(1,1,"Hum1:");
98: IntToStr(HumInt01,txtHumI1);
99: //Lcd_Out(1,12,txtHumI1_1);
100:
101: FloatToStr_FixLen(HumInt01,txtHumI1_1,4);
102: //Lcd_Out_Cp(txtHumI1);
103: //Lcd_Out_Cp("%");
104: //delay_ms(150);
105: /////////////////////
106: H2invert = (ADC_Read(1)*100.0)/1023.0;
107: HumInt02 = 100 - H2invert;
108: //Lcd_Out(2,1,"Hum2:");
109: FloatToStr_FixLen(HumInt02,txtHumI2,4);
110: //Lcd_Out_Cp(txtHumI2);
111: //Lcd_Out_Cp("%");
112: //delay_ms(150);
113: /////////////////////
114: TempExt = ADC_Read(2);
115: //Lcd_Out(1,12,"Temp:");
116: TempExt = TempExt*0.488;
117: FloatToStr_FixLen(TempExt,txtTempE,4);
118: //Lcd_Out(2,13,txtTempE);
119: //CustomChar(2,15);
120: //Lcd_Chr_CP('C');
121: //delay_ms(150);
2/4 mikroC PRO for PIC by mikroElektronika
codigo_fuente_pic18f4550.c 25/09/2018 19:51:20
122: /////////////////////
123:
124: if(HumInt01 <= 50){
125: electr_valv1 = 1;
126: }
127: else{
128: electr_valv1=0;
129: }
130: delay_ms(100);
131: /////////////////////
132: if(TempExt>= 21){
133: electr_valv1 = 1;
134: }
135: else{
136: electr_valv1=0;
137: }
138:
139: /////////////////////////////////////////////////////////////
140: //MENU DE PANTALLAS EN LCD
141:
142: if(Button(&PORTC,6,1,1)){
143: variable=1; }
144:
145: if(variable && Button(&PORTC,6,1,0)){
146: variable=0;
147: contador++;
148: LCD_CMD(_LCD_CLEAR);
149: LCD_CMD(_LCD_RETURN_HOME);
150:
151: switch (contador){
152:
153: case 1:
154: Lcd_Out(1,1,"Hum1:");
155: //FloatToStr_FixLen(HumInt01,txtHumI1,4);
156: Lcd_Out_Cp(Ltrim(txtHumI1));
157: Lcd_Out_Cp("%");
158: delay_ms(150);
159: Lcd_Out(2,1,"Hum2:");
160: //FloatToStr_FixLen(HumInt02,txtHumI2,4);
161: Lcd_Out_Cp(txtHumI2);
162: Lcd_Out_Cp("%");
163: delay_ms(150);
164: Lcd_Out(1,12,"Temp:");
165: //TempExt = TempExt*0.488;
166: //FloatToStr_FixLen(TempExt,txtTempE,4);
167: Lcd_Out(2,13,txtTempE);
168: CustomChar(2,15);
169: Lcd_Chr_CP('C');
170: delay_ms(150);
171: break;
172: case 2:
173: Lcd_Out(1,1,"HumedadSuelo 1:");
174: H1invert= (ADC_Read(0)*100.0)/1023.0;
175: HumInt01 = 100 - H1invert;
176: FloatToStr_FixLen(HumInt01,txtHumI1_1,4);
177: Lcd_Out(2,5,txtHumI1_1);
178: Lcd_Out_Cp("%");
179: break;
180: case 3:
181: Lcd_Out(1,1,"HumedadSuelo 2:");
182: Lcd_Out(2,5,"indutrial");
183: PORTD.F2 = 1;
3/4 mikroC PRO for PIC by mikroElektronika
codigo_fuente_pic18f4550.c 25/09/2018 19:51:20
184: PORTD.F1 = 0;
185: break;
186: case 4:
187: Lcd_Out(1,1,"Temperatura Ext:");
188: Lcd_Out(2,5,"CIENCIA");
189: PORTD.F3 = 1;
190: PORTD.F2 = 0;
191: break;
192: case 5:
193: Lcd_Out(1,1,"Temperatura Int:");
194: Lcd_Out(2,5,"PIC");
195: PORTD.F4 = 1;
196: PORTD.F3 = 0;
197: break;
198: case 6:
199: Lcd_Out(1,1,"Caudal H2O:");
200: Lcd_Out(2,5,"OK");
201: PORTD.F5 = 1;
202: PORTD.F4 = 0;
203: break;
204: case 7:
205: Lcd_Out(1,1,"Electroval Sta:");
206: Lcd_Out(2,5,"Activado");
207: PORTD.F6 = 1;
208: PORTD.F5 = 0;
209: break;
210: case 8:
211: Lcd_Out(1,2,"AUTOMATIZACION");
212: Lcd_Out(2,3,"PIC18F4550");
213: PORTD.F7 = 1;
214: PORTD.F6 = 0;
215: break;
216: default:
217: Lcd_Out(1,2,"AUTOMATIZACION");
218: Lcd_Out(2,2,"INVERNADERO");
219: PORTD.F0 = 1;
220: PORTD.F7 = 0;
221: {contador = 0;}}
222:
223: }
224:
225: } while(1);
226: delay_ms(100);
227:
228: }
4/4 mikroC PRO for PIC by mikroElektronika