Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD keypad mbed
main.cpp
00001 # include "mbed.h" 00002 # include "keypad.h" 00003 # include "TextLCD.h" 00004 00005 00006 TextLCD lcd (D15,D14,D13,D12,D11,D10); // RS, e, d4-d7 00007 00008 AnalogIn Ain (A0); 00009 AnalogOut Aout (A2); 00010 00011 int C4 = 0x0C ; 00012 int C1 = 0x0E ; 00013 int p = 0 ; 00014 00015 int c = 0 ; 00016 int y = 0 ; 00017 float i; // establecer el punto 00018 float j = 0 ; // salida planta 00019 float ji = 0 ; // variable de Proceso interno 00020 float spi = 0 ; // variable de Proceso interno 00021 float h = 0 ; // entrada planta 00022 float m = 0 ; // Error 00023 float mv = 0 ; 00024 float g = 0 ; 00025 00026 00027 float ap, ai; 00028 int sp = 0 ; 00029 int kp = 0 ; 00030 int ki = 0 ; 00031 int k = 0 ; 00032 00033 00034 00035 00036 // Definir sus propios valores del teclado 00037 char tabla de teclas [] = { '1' , '2' , '3' , '*' , 00038 '4' , '5' , '6' , '0' , 00039 '7' , ' 8 ' , ' 9 ' , ' # ' , 00040 ' A ' , ' B ' , ' C ' , ' D '}; 00041 00042 int Teclado [] = { 1 , 4 , 7 , 13 , 00043 2 , 5 , 8 , 0 , 00044 3 , 6 , 9 , 14 , 00045 10 , 11 , 12 , 15 00046 }; 00047 00048 uint32_t cbAfterInput ( uint32_t clave) 00049 { 00050 00051 if (KEYPAD [clave] == 'A' ) 00052 { 00053 Teclado [clave] = 0 ; 00054 C ++; 00055 } 00056 00057 if (KEYPAD [clave] == 'B' ) { 00058 Teclado [clave] = 0 ; 00059 sp = 0 ; 00060 kp = 0 ; 00061 ki = 0 ; 00062 kd = 0 ; 00063 } 00064 00065 00066 if (KEYTABLE [clave] == 'D' ) { 00067 Teclado [clave] = 0 ; 00068 p = 1 ; 00069 } 00070 00071 //////////// 00072 00073 if (c == 0 ) { 00074 00075 SP = SP + Teclado [clave]; 00076 00077 } 00078 00079 if (c == 1 ) { 00080 00081 kp kp = + Teclado [clave]; 00082 00083 } 00084 if (c == 2 ) { 00085 00086 ki ki = + Teclado [clave]; 00087 00088 } 00089 if (c == 3 ) { 00090 00091 KD = kd + Teclado [clave]; 00092 00093 } 00094 00095 //////////// 00096 00097 00098 volver 0 ; 00099 } // Fin unit32_t 00100 00101 00102 00103 int main () { 00104 teclado teclado (D9,D8,D7,D6,D5,D4,D3,D2); 00105 keypad.CallAfterInput (y cbAfterInput); 00106 keypad.Start (); 00107 00108 lcd.cls (); 00109 lcd. printf ( "SP:% d" , sp); 00110 lcd.locate ( 8 , 0 ); 00111 lcd. printf ( "Kp:% d" , kp); 00112 lcd.locate ( 0 , 1 ); 00113 lcd. printf ( "Ki:% d" , ki); 00114 lcd.locate ( 8 , 1 ); 00115 lcd. printf ( "Kd:% d" , kd); 00116 lcd.writeCommand (C1); // escribimos ONU comando segun el manual del módulo del LCD 00117 lcd.locate ( 0 , 0 ); 00118 lcd. printf ( "SP:% d" , sp); 00119 00120 mientras que ( 1 ) { 00121 00122 00123 if (c == 0 ) { 00124 lcd.locate ( 3 , 0 ); 00125 . lcd putc ( 0xFE ); 00126 lcd.locate ( 4 , 0 ); 00127 lcd. printf ( "% d" , sp); 00128 00129 // NUEVO !! (no ceros en - proceso) 00130 if (sp < 10 ) { 00131 lcd.locate ( 5 , 0 ); 00132 . lcd putc ( 0xFE ); 00133 } 00134 00135 if (sp < 100 ) { 00136 lcd.locate ( 6 , 0 ); 00137 . lcd putc ( 0xFE ); 00138 } 00139 00140 lcd.locate ( 4 , 0 ); 00141 lcd. printf ( "% d" , sp); 00142 //wait(0.1); 00143 00144 // 00145 00146 } 00147 00148 if (c == 1 ) { 00149 lcd.locate ( 11 , 0 ); 00150 . lcd putc ( 0xFE ); 00151 lcd.locate ( 12 , 0 ); 00152 lcd. printf ( "% d" , kp); 00153 00154 // NUEVO !! (no ceros en - proceso) 00155 if (kp < 10 ) { 00156 lcd.locate ( 13 , 0 ); 00157 . lcd putc ( 0xFE ); 00158 } 00159 00160 if (kp < 100 ) { 00161 lcd.locate ( 14 , 0 ); 00162 . lcd putc ( 0xFE ); 00163 } 00164 00165 lcd.locate ( 12 , 0 ); 00166 lcd. printf ( "% d" , kp); 00167 //wait(0.1); 00168 00169 // 00170 00171 } 00172 00173 if (c == 2 ) { 00174 lcd.locate ( 3 , 1 ); 00175 . lcd putc ( 0xFE ); 00176 lcd.locate ( 4 , 1 ); 00177 lcd. printf ( "% d" , ki); 00178 00179 // NUEVO !! (no ceros en - proceso) 00180 if (Ki < 10 ) { 00181 lcd.locate ( 5 , 1 ); 00182 . lcd putc ( 0xFE ); 00183 } 00184 00185 if (ki < 100 ) { 00186 lcd.locate ( 6 , 1 ); 00187 . lcd putc ( 0xFE ); 00188 } 00189 00190 lcd.locate ( 4 , 1 ); 00191 lcd. printf ( "% d" , ki); 00192 //wait(0.2); 00193 00194 // 00195 00196 } 00197 if (c == 3 ) { 00198 lcd.locate ( 11 , 1 ); 00199 . lcd putc ( 0xFE ); 00200 lcd.locate ( 12 , 1 ); 00201 lcd. printf ( "% d" , kd); 00202 00203 // NUEVO !! (no ceros en - proceso) 00204 if (kd < 10 ) { 00205 lcd.locate ( 13 , 1 ); 00206 . lcd putc ( 0xFE ); 00207 } 00208 00209 if (kd < 100 ) { 00210 lcd.locate ( 14 , 1 ); 00211 . lcd putc ( 0xFE ); 00212 } 00213 00214 lcd.locate ( 12 , 1 ); 00215 lcd. printf ( "% d" , kd); 00216 //wait(0.2); 00217 } 00218 00219 if (c == 4 || c> 4 ) { 00220 c = 0 ; 00221 } 00222 00223 if (p == 1 ) { 00224 c = 0 ; 00225 romper ; 00226 } 00227 00228 } 00229 00230 00231 lcd.writeCommand (C4); // escribimos ONU comando segun el manual del módulo del LCD para quitar el cursor bajo 00232 lcd.cls (); // Borra la Pantalla 00233 . lcd printf ( "Guardados!" ); 00234 wait ( 2 ); 00235 lcd.cls (); 00236 . lcd printf ( "INICIA EL PID" ); 00237 wait ( 2 ); 00238 // se imprimen los reseca del control de ************************************* **** 00239 00240 i = sp / 999 ; 00241 lcd.cls (); 00242 lcd. printf ( "Er:% 2F." , m); 00243 lcd.locate ( 8 , 0 ); 00244 lcd. printf ( "Yo:% 2F." , j); 00245 lcd.locate ( 0 , 1 ); 00246 lcd. printf ( "SP:% d" , sp); 00247 lcd.locate ( 8 , 1 ); 00248 lcd. printf ( "Co: 1f%." , h); 00249 wait ( 2 ); 00250 00251 // 00252 while ( 1 ) { 00253 00254 spi = sp * ( 3.3 / 999 ); 00255 00256 //wait(0.3); 00257 i = sp / 999 ; 00258 if (i <= 1 ) { 00259 00260 j = Ain; 00261 ji = j * 3.3 ; 00262 m = (SPI-ji); 00263 // N = m * 100; 00264 ap = kp * m; 00265 ai = (Ki * m) + ai; 00266 00267 ad = kd * (m-mv); 00268 h = p + ai + ad; 00269 00270 si (h> 999 ) { 00271 h = 999 ; 00272 } 00273 si (h < 0 ) { 00274 h = 0 ; 00275 } 00276 00277 g = (h / 999 ); 00278 00279 Aout = g; 00280 esperar ( 0,22 ); 00281 00282 00283 lcd.cls (); 00284 lcd. printf ( "Er:% 2F." , m); 00285 lcd.locate ( 8 , 0 ); 00286 lcd. printf ( "Yo:% 2F." , j); 00287 lcd.locate ( 0 , 1 ); 00288 lcd. printf ( "SP:% d" , sp); 00289 lcd.locate ( 8 , 1 ); 00290 lcd. printf ( "Co: 1f%." , h); 00291 } 00292 00293 00294 MV = m; 00295 } // Si bien 00296 // 00297 00298 } // Int main
Generated on Sun Jul 17 2022 01:37:34 by
1.7.2