![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
FRDM KL25Z - LCD 16x2 - Teclado 4x4
Dependencies: Keypad TextLCD-modificada mbed
main.cpp@2:316c3e9ad8d8, 2016-05-08 (annotated)
- Committer:
- Susanaranjo
- Date:
- Sun May 08 17:59:09 2016 +0000
- Revision:
- 2:316c3e9ad8d8
- Parent:
- 1:eeaeab624998
- Child:
- 3:6d93b935b945
//
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Susanaranjo | 0:30426151ddb2 | 1 | #include "mbed.h" |
Susanaranjo | 0:30426151ddb2 | 2 | #include "TextLCD.h" |
Susanaranjo | 0:30426151ddb2 | 3 | #include "Keypad.h" |
Susanaranjo | 0:30426151ddb2 | 4 | |
Susanaranjo | 2:316c3e9ad8d8 | 5 | |
Susanaranjo | 2:316c3e9ad8d8 | 6 | //Configuración de la pantalla |
Susanaranjo | 0:30426151ddb2 | 7 | TextLCD lcd(PTE20,PTE21,PTE22,PTE23,PTE29,PTE30, TextLCD::LCD16x2); // Rs, E, d4, d5, d6, d7 |
Susanaranjo | 0:30426151ddb2 | 8 | |
Susanaranjo | 2:316c3e9ad8d8 | 9 | //COnfiguración del teclado |
Susanaranjo | 0:30426151ddb2 | 10 | Keypad kpad(PTA12,PTD4,PTA2,PTA1,PTC9,PTC8,PTA5,PTA4); // f1,f2,f3,f4,c1,c2,c3,c4 |
Susanaranjo | 0:30426151ddb2 | 11 | |
Susanaranjo | 0:30426151ddb2 | 12 | |
Susanaranjo | 0:30426151ddb2 | 13 | |
Susanaranjo | 0:30426151ddb2 | 14 | int main() { |
Susanaranjo | 0:30426151ddb2 | 15 | int contador=0; |
Susanaranjo | 0:30426151ddb2 | 16 | int item=0; |
Susanaranjo | 0:30426151ddb2 | 17 | int i=0; |
Susanaranjo | 0:30426151ddb2 | 18 | int tecla=0; |
Susanaranjo | 0:30426151ddb2 | 19 | int const0=0; |
Susanaranjo | 0:30426151ddb2 | 20 | int const1=0; |
Susanaranjo | 0:30426151ddb2 | 21 | int const2=0; |
Susanaranjo | 0:30426151ddb2 | 22 | int const3=0; |
Susanaranjo | 0:30426151ddb2 | 23 | int kp,ki,kd,sp; |
Susanaranjo | 0:30426151ddb2 | 24 | int entero; |
Susanaranjo | 0:30426151ddb2 | 25 | char key; |
Susanaranjo | 0:30426151ddb2 | 26 | int released=1; |
Susanaranjo | 0:30426151ddb2 | 27 | |
Susanaranjo | 0:30426151ddb2 | 28 | lcd.locate(0,0); |
Susanaranjo | 0:30426151ddb2 | 29 | lcd.printf("Kp="); |
Susanaranjo | 0:30426151ddb2 | 30 | lcd.locate(8,0); |
Susanaranjo | 0:30426151ddb2 | 31 | lcd.printf("Ki="); |
Susanaranjo | 0:30426151ddb2 | 32 | lcd.locate(0,1); |
Susanaranjo | 0:30426151ddb2 | 33 | lcd.printf("Kd="); |
Susanaranjo | 0:30426151ddb2 | 34 | lcd.locate(8,1); |
Susanaranjo | 0:30426151ddb2 | 35 | lcd.printf("Sp="); |
Susanaranjo | 0:30426151ddb2 | 36 | lcd.locate(3,0); |
Susanaranjo | 2:316c3e9ad8d8 | 37 | lcd.printf("_"); //cursor en el primer campo |
Susanaranjo | 0:30426151ddb2 | 38 | |
Susanaranjo | 0:30426151ddb2 | 39 | |
Susanaranjo | 0:30426151ddb2 | 40 | while(1) { |
Susanaranjo | 0:30426151ddb2 | 41 | i=0; |
Susanaranjo | 0:30426151ddb2 | 42 | contador=0; |
Susanaranjo | 0:30426151ddb2 | 43 | const0=0; |
Susanaranjo | 0:30426151ddb2 | 44 | const1=0; |
Susanaranjo | 0:30426151ddb2 | 45 | const2=0; |
Susanaranjo | 0:30426151ddb2 | 46 | const3=0; |
Susanaranjo | 0:30426151ddb2 | 47 | entero=0; |
Susanaranjo | 0:30426151ddb2 | 48 | |
Susanaranjo | 0:30426151ddb2 | 49 | while (i<=3){ |
Susanaranjo | 2:316c3e9ad8d8 | 50 | key=kpad.ReadKey();//Lectura del teclado |
Susanaranjo | 2:316c3e9ad8d8 | 51 | tecla=key-48; //Conversión de la tecla a entero |
Susanaranjo | 0:30426151ddb2 | 52 | switch(i){ |
Susanaranjo | 0:30426151ddb2 | 53 | case 0: |
Susanaranjo | 0:30426151ddb2 | 54 | const0=tecla; |
Susanaranjo | 0:30426151ddb2 | 55 | case 1: |
Susanaranjo | 0:30426151ddb2 | 56 | const1=tecla; |
Susanaranjo | 0:30426151ddb2 | 57 | case 2: |
Susanaranjo | 0:30426151ddb2 | 58 | const2=tecla; |
Susanaranjo | 0:30426151ddb2 | 59 | case 3: |
Susanaranjo | 0:30426151ddb2 | 60 | const3=tecla;} |
Susanaranjo | 0:30426151ddb2 | 61 | |
Susanaranjo | 2:316c3e9ad8d8 | 62 | //Conversión a entero del número completo ingresado |
Susanaranjo | 0:30426151ddb2 | 63 | if(contador>=3){ |
Susanaranjo | 0:30426151ddb2 | 64 | entero=1000*const0+100*const1+10*const2+const3;} |
Susanaranjo | 0:30426151ddb2 | 65 | else if (contador==2){ |
Susanaranjo | 0:30426151ddb2 | 66 | entero=100*const0+10*const1+const2;} |
Susanaranjo | 0:30426151ddb2 | 67 | else if (contador==1){ |
Susanaranjo | 0:30426151ddb2 | 68 | entero=10*const0+const1;} |
Susanaranjo | 0:30426151ddb2 | 69 | else if (contador==0){ |
Susanaranjo | 0:30426151ddb2 | 70 | entero=const0;} |
Susanaranjo | 0:30426151ddb2 | 71 | |
Susanaranjo | 0:30426151ddb2 | 72 | |
Susanaranjo | 0:30426151ddb2 | 73 | if(key=='\0'){ |
Susanaranjo | 0:30426151ddb2 | 74 | released=1;} |
Susanaranjo | 0:30426151ddb2 | 75 | |
Susanaranjo | 0:30426151ddb2 | 76 | if((key !='\0')&&(released==1)){ |
Susanaranjo | 0:30426151ddb2 | 77 | released=0; |
Susanaranjo | 2:316c3e9ad8d8 | 78 | |
Susanaranjo | 2:316c3e9ad8d8 | 79 | //Limpiar los valores y volver a comenzar |
Susanaranjo | 0:30426151ddb2 | 80 | if(key=='#') { |
Susanaranjo | 0:30426151ddb2 | 81 | lcd.cls(); |
Susanaranjo | 0:30426151ddb2 | 82 | lcd.locate(0,0); |
Susanaranjo | 0:30426151ddb2 | 83 | lcd.printf("Kp="); |
Susanaranjo | 0:30426151ddb2 | 84 | lcd.locate(8,0); |
Susanaranjo | 0:30426151ddb2 | 85 | lcd.printf("Ki="); |
Susanaranjo | 0:30426151ddb2 | 86 | lcd.locate(0,1); |
Susanaranjo | 0:30426151ddb2 | 87 | lcd.printf("Kd="); |
Susanaranjo | 0:30426151ddb2 | 88 | lcd.locate(8,1); |
Susanaranjo | 0:30426151ddb2 | 89 | lcd.printf("Sp="); |
Susanaranjo | 0:30426151ddb2 | 90 | lcd.locate(3,0); |
Susanaranjo | 0:30426151ddb2 | 91 | lcd.printf("_"); |
Susanaranjo | 0:30426151ddb2 | 92 | |
Susanaranjo | 0:30426151ddb2 | 93 | const0=0; |
Susanaranjo | 0:30426151ddb2 | 94 | const1=0; |
Susanaranjo | 0:30426151ddb2 | 95 | const2=0; |
Susanaranjo | 0:30426151ddb2 | 96 | const3=0; |
Susanaranjo | 0:30426151ddb2 | 97 | |
Susanaranjo | 0:30426151ddb2 | 98 | entero=0; |
Susanaranjo | 0:30426151ddb2 | 99 | kp=0; |
Susanaranjo | 0:30426151ddb2 | 100 | ki=0; |
Susanaranjo | 0:30426151ddb2 | 101 | kd=0; |
Susanaranjo | 0:30426151ddb2 | 102 | sp=0; |
Susanaranjo | 0:30426151ddb2 | 103 | contador=-1; |
Susanaranjo | 0:30426151ddb2 | 104 | i=-1; |
Susanaranjo | 0:30426151ddb2 | 105 | item=0; |
Susanaranjo | 2:316c3e9ad8d8 | 106 | |
Susanaranjo | 2:316c3e9ad8d8 | 107 | //Confirmar el valor ingresado y pasar al siguiente campo |
Susanaranjo | 0:30426151ddb2 | 108 | }else if(key=='*'){ |
Susanaranjo | 0:30426151ddb2 | 109 | contador=-1; |
Susanaranjo | 0:30426151ddb2 | 110 | item=item+1; |
Susanaranjo | 0:30426151ddb2 | 111 | i=-1; |
Susanaranjo | 0:30426151ddb2 | 112 | |
Susanaranjo | 0:30426151ddb2 | 113 | if(item==1){ |
Susanaranjo | 0:30426151ddb2 | 114 | lcd.locate(3,0); |
Susanaranjo | 0:30426151ddb2 | 115 | lcd.printf("%4Lu",kp); |
Susanaranjo | 0:30426151ddb2 | 116 | lcd.locate(11,0); |
Susanaranjo | 2:316c3e9ad8d8 | 117 | lcd.printf("_ "); //cursor en el siguiente campo |
Susanaranjo | 0:30426151ddb2 | 118 | entero=0;} |
Susanaranjo | 0:30426151ddb2 | 119 | |
Susanaranjo | 0:30426151ddb2 | 120 | if(item==2){ |
Susanaranjo | 0:30426151ddb2 | 121 | lcd.locate(11,0); |
Susanaranjo | 0:30426151ddb2 | 122 | lcd.printf("%4Lu",ki); |
Susanaranjo | 0:30426151ddb2 | 123 | lcd.locate(3,1); |
Susanaranjo | 2:316c3e9ad8d8 | 124 | lcd.printf("_ "); //cursor en el siguiente campo |
Susanaranjo | 0:30426151ddb2 | 125 | entero=0;} |
Susanaranjo | 0:30426151ddb2 | 126 | |
Susanaranjo | 0:30426151ddb2 | 127 | if(item==3){ |
Susanaranjo | 0:30426151ddb2 | 128 | lcd.locate(3,1); |
Susanaranjo | 0:30426151ddb2 | 129 | lcd.printf("%4Lu",kd); |
Susanaranjo | 0:30426151ddb2 | 130 | lcd.locate(11,1); |
Susanaranjo | 2:316c3e9ad8d8 | 131 | lcd.printf("_ "); //cursor en el siguiente campo |
Susanaranjo | 0:30426151ddb2 | 132 | entero=0;} |
Susanaranjo | 0:30426151ddb2 | 133 | |
Susanaranjo | 0:30426151ddb2 | 134 | if (item==4){ |
Susanaranjo | 0:30426151ddb2 | 135 | lcd.locate(11,1); |
Susanaranjo | 0:30426151ddb2 | 136 | lcd.printf("%4Lu",sp); |
Susanaranjo | 0:30426151ddb2 | 137 | wait_ms(1000); |
Susanaranjo | 0:30426151ddb2 | 138 | lcd.cls(); |
Susanaranjo | 0:30426151ddb2 | 139 | lcd.printf("Los valores han\n"); |
Susanaranjo | 0:30426151ddb2 | 140 | lcd.printf("sido guardados"); |
Susanaranjo | 0:30426151ddb2 | 141 | wait_ms(4000); |
Susanaranjo | 0:30426151ddb2 | 142 | lcd.cls(); |
Susanaranjo | 0:30426151ddb2 | 143 | lcd.printf("Pulse * para\n"); |
Susanaranjo | 0:30426151ddb2 | 144 | lcd.printf("empezar de nuevo"); |
Susanaranjo | 0:30426151ddb2 | 145 | wait_ms(3000); |
Susanaranjo | 0:30426151ddb2 | 146 | lcd.cls(); |
Susanaranjo | 0:30426151ddb2 | 147 | lcd.locate(0,0); |
Susanaranjo | 0:30426151ddb2 | 148 | lcd.printf("Kp=%4Lu",kp); |
Susanaranjo | 0:30426151ddb2 | 149 | lcd.locate(8,0); |
Susanaranjo | 0:30426151ddb2 | 150 | lcd.printf("Ki=%4Lu",ki); |
Susanaranjo | 0:30426151ddb2 | 151 | lcd.locate(0,1); |
Susanaranjo | 0:30426151ddb2 | 152 | lcd.printf("Kd=%4Lu",kd); |
Susanaranjo | 0:30426151ddb2 | 153 | lcd.locate(8,1); |
Susanaranjo | 0:30426151ddb2 | 154 | lcd.printf("Sp=%4Lu",sp);} |
Susanaranjo | 0:30426151ddb2 | 155 | |
Susanaranjo | 0:30426151ddb2 | 156 | if(item==5){ |
Susanaranjo | 0:30426151ddb2 | 157 | lcd.cls(); |
Susanaranjo | 0:30426151ddb2 | 158 | lcd.locate(0,0); |
Susanaranjo | 0:30426151ddb2 | 159 | lcd.printf("Kp="); |
Susanaranjo | 0:30426151ddb2 | 160 | lcd.locate(8,0); |
Susanaranjo | 0:30426151ddb2 | 161 | lcd.printf("Ki="); |
Susanaranjo | 0:30426151ddb2 | 162 | lcd.locate(0,1); |
Susanaranjo | 0:30426151ddb2 | 163 | lcd.printf("Kd="); |
Susanaranjo | 0:30426151ddb2 | 164 | lcd.locate(8,1); |
Susanaranjo | 0:30426151ddb2 | 165 | lcd.printf("Sp="); |
Susanaranjo | 0:30426151ddb2 | 166 | lcd.locate(3,0); |
Susanaranjo | 2:316c3e9ad8d8 | 167 | lcd.printf("_"); //cursor en el primer campo |
Susanaranjo | 0:30426151ddb2 | 168 | |
Susanaranjo | 0:30426151ddb2 | 169 | const0=0; |
Susanaranjo | 0:30426151ddb2 | 170 | const1=0; |
Susanaranjo | 0:30426151ddb2 | 171 | const2=0; |
Susanaranjo | 0:30426151ddb2 | 172 | const3=0; |
Susanaranjo | 0:30426151ddb2 | 173 | |
Susanaranjo | 0:30426151ddb2 | 174 | entero=0; |
Susanaranjo | 0:30426151ddb2 | 175 | kp=0; |
Susanaranjo | 0:30426151ddb2 | 176 | ki=0; |
Susanaranjo | 0:30426151ddb2 | 177 | kd=0; |
Susanaranjo | 0:30426151ddb2 | 178 | sp=0; |
Susanaranjo | 0:30426151ddb2 | 179 | contador=-1; |
Susanaranjo | 0:30426151ddb2 | 180 | i=-1; |
Susanaranjo | 0:30426151ddb2 | 181 | item=0;} |
Susanaranjo | 0:30426151ddb2 | 182 | |
Susanaranjo | 0:30426151ddb2 | 183 | }else if(key=='A'){ |
Susanaranjo | 0:30426151ddb2 | 184 | lcd.cls(); |
Susanaranjo | 1:eeaeab624998 | 185 | lcd.printf("Tarea 8\n"); |
Susanaranjo | 0:30426151ddb2 | 186 | lcd.printf("Procesadores"); |
Susanaranjo | 0:30426151ddb2 | 187 | |
Susanaranjo | 0:30426151ddb2 | 188 | }else if(key=='B'){ |
Susanaranjo | 0:30426151ddb2 | 189 | lcd.cls(); |
Susanaranjo | 0:30426151ddb2 | 190 | lcd.printf("Susana Naranjo\n"); |
Susanaranjo | 0:30426151ddb2 | 191 | lcd.printf("Aaron Gonzalez"); |
Susanaranjo | 0:30426151ddb2 | 192 | |
Susanaranjo | 0:30426151ddb2 | 193 | }else if(key=='C'){ |
Susanaranjo | 0:30426151ddb2 | 194 | lcd.cls(); |
Susanaranjo | 0:30426151ddb2 | 195 | lcd.printf("Universidad\n"); |
Susanaranjo | 0:30426151ddb2 | 196 | lcd.printf("Nacional"); |
Susanaranjo | 0:30426151ddb2 | 197 | |
Susanaranjo | 0:30426151ddb2 | 198 | }else if(key=='D'){ |
Susanaranjo | 0:30426151ddb2 | 199 | lcd.cls(); |
Susanaranjo | 0:30426151ddb2 | 200 | lcd.printf("Facultad de\n"); |
Susanaranjo | 0:30426151ddb2 | 201 | lcd.printf("Minas"); |
Susanaranjo | 0:30426151ddb2 | 202 | } |
Susanaranjo | 0:30426151ddb2 | 203 | |
Susanaranjo | 0:30426151ddb2 | 204 | else{ |
Susanaranjo | 2:316c3e9ad8d8 | 205 | //Mostrar uno a uno el número correspondiente a la tecla pulsada en cada campo |
Susanaranjo | 2:316c3e9ad8d8 | 206 | |
Susanaranjo | 2:316c3e9ad8d8 | 207 | //Kp |
Susanaranjo | 0:30426151ddb2 | 208 | if (item==0){ |
Susanaranjo | 0:30426151ddb2 | 209 | if (i==0){ |
Susanaranjo | 0:30426151ddb2 | 210 | lcd.locate(3,0); |
Susanaranjo | 0:30426151ddb2 | 211 | lcd.printf("_ ");} |
Susanaranjo | 0:30426151ddb2 | 212 | lcd.locate(3+i,0); |
Susanaranjo | 0:30426151ddb2 | 213 | lcd.printf("%u",tecla); |
Susanaranjo | 0:30426151ddb2 | 214 | kp=entero; } |
Susanaranjo | 0:30426151ddb2 | 215 | |
Susanaranjo | 2:316c3e9ad8d8 | 216 | //Ki |
Susanaranjo | 0:30426151ddb2 | 217 | if (item==1){ |
Susanaranjo | 0:30426151ddb2 | 218 | if (i==0){ |
Susanaranjo | 0:30426151ddb2 | 219 | lcd.locate(11,0); |
Susanaranjo | 0:30426151ddb2 | 220 | lcd.printf("_ ");} |
Susanaranjo | 0:30426151ddb2 | 221 | lcd.locate(11+i,0); |
Susanaranjo | 0:30426151ddb2 | 222 | lcd.printf("%u",tecla); |
Susanaranjo | 0:30426151ddb2 | 223 | ki=entero;} |
Susanaranjo | 0:30426151ddb2 | 224 | |
Susanaranjo | 2:316c3e9ad8d8 | 225 | //Kd |
Susanaranjo | 0:30426151ddb2 | 226 | if (item==2){ |
Susanaranjo | 0:30426151ddb2 | 227 | if (i==0){ |
Susanaranjo | 0:30426151ddb2 | 228 | lcd.locate(3,1); |
Susanaranjo | 0:30426151ddb2 | 229 | lcd.printf("_ "); } |
Susanaranjo | 0:30426151ddb2 | 230 | lcd.locate(3+i,1); |
Susanaranjo | 0:30426151ddb2 | 231 | lcd.printf("%u",tecla); |
Susanaranjo | 0:30426151ddb2 | 232 | kd=entero;} |
Susanaranjo | 0:30426151ddb2 | 233 | |
Susanaranjo | 2:316c3e9ad8d8 | 234 | //Sp |
Susanaranjo | 0:30426151ddb2 | 235 | if (item==3){ |
Susanaranjo | 0:30426151ddb2 | 236 | if (i==0){ |
Susanaranjo | 0:30426151ddb2 | 237 | lcd.locate(11,1); |
Susanaranjo | 0:30426151ddb2 | 238 | lcd.printf("_ "); } |
Susanaranjo | 0:30426151ddb2 | 239 | lcd.locate(11+i,1); |
Susanaranjo | 0:30426151ddb2 | 240 | lcd.printf("%u",tecla); |
Susanaranjo | 0:30426151ddb2 | 241 | sp=entero; } |
Susanaranjo | 0:30426151ddb2 | 242 | |
Susanaranjo | 0:30426151ddb2 | 243 | |
Susanaranjo | 2:316c3e9ad8d8 | 244 | }//else |
Susanaranjo | 0:30426151ddb2 | 245 | |
Susanaranjo | 0:30426151ddb2 | 246 | contador=contador+1; |
Susanaranjo | 0:30426151ddb2 | 247 | i++; |
Susanaranjo | 0:30426151ddb2 | 248 | |
Susanaranjo | 0:30426151ddb2 | 249 | |
Susanaranjo | 0:30426151ddb2 | 250 | |
Susanaranjo | 0:30426151ddb2 | 251 | } //if((key !='\0')&&(released==1)) |
Susanaranjo | 0:30426151ddb2 | 252 | |
Susanaranjo | 0:30426151ddb2 | 253 | } //while(i<=3) |
Susanaranjo | 0:30426151ddb2 | 254 | |
Susanaranjo | 0:30426151ddb2 | 255 | } // while(1) |
Susanaranjo | 0:30426151ddb2 | 256 | } //main |