FRDM KL25Z - LCD 16x2 - Teclado 4x4

Dependencies:   Keypad TextLCD-modificada mbed

/media/uploads/Susanaranjo/img_20160508_014013.jpg

Revision:
0:30426151ddb2
Child:
1:eeaeab624998
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun May 08 06:32:09 2016 +0000
@@ -0,0 +1,244 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "Keypad.h"
+
+TextLCD lcd(PTE20,PTE21,PTE22,PTE23,PTE29,PTE30, TextLCD::LCD16x2); // Rs, E, d4, d5, d6, d7 
+
+Keypad kpad(PTA12,PTD4,PTA2,PTA1,PTC9,PTC8,PTA5,PTA4); // f1,f2,f3,f4,c1,c2,c3,c4
+
+
+
+int main() {
+   int contador=0;
+   int item=0;
+   int i=0;
+   int tecla=0;
+   int const0=0;
+   int const1=0;
+   int const2=0;
+   int const3=0;
+   int kp,ki,kd,sp;
+   int entero;
+   char key;
+   int released=1;
+    
+    lcd.locate(0,0);
+    lcd.printf("Kp=");
+    lcd.locate(8,0);
+    lcd.printf("Ki=");
+    lcd.locate(0,1);
+    lcd.printf("Kd=");
+    lcd.locate(8,1);
+    lcd.printf("Sp=");
+    lcd.locate(3,0);
+    lcd.printf("_");
+    
+    
+    while(1) {
+       i=0;
+       contador=0;
+       const0=0;
+        const1=0;
+         const2=0;
+          const3=0;
+          entero=0;
+       
+       while (i<=3){       
+       key=kpad.ReadKey();
+       tecla=key-48;
+       switch(i){
+       case 0:
+       const0=tecla;
+       case 1:
+       const1=tecla;
+       case 2:
+       const2=tecla;
+       case 3:
+       const3=tecla;}
+       
+       if(contador>=3){
+           entero=1000*const0+100*const1+10*const2+const3;}
+       else if (contador==2){
+           entero=100*const0+10*const1+const2;}
+       else if (contador==1){
+           entero=10*const0+const1;}
+       else if (contador==0){
+           entero=const0;}
+       
+       
+       if(key=='\0'){
+       released=1;}
+              
+       if((key !='\0')&&(released==1)){
+       released=0;  
+       
+      if(key=='#') {
+       lcd.cls();
+       lcd.locate(0,0);
+       lcd.printf("Kp=");
+       lcd.locate(8,0);
+       lcd.printf("Ki=");
+       lcd.locate(0,1);
+       lcd.printf("Kd=");
+       lcd.locate(8,1);
+       lcd.printf("Sp=");
+       lcd.locate(3,0);
+       lcd.printf("_");
+       
+       const0=0;
+       const1=0;
+       const2=0;
+       const3=0;
+       
+       entero=0;
+       kp=0;
+       ki=0;
+       kd=0;
+       sp=0;
+       contador=-1;
+       i=-1;
+       item=0;
+        
+      }else if(key=='*'){
+      contador=-1;
+      item=item+1;
+      i=-1;
+      
+      if(item==1){
+      lcd.locate(3,0);
+      lcd.printf("%4Lu",kp); 
+      lcd.locate(11,0);
+      lcd.printf("_   ");
+      entero=0;}
+      
+      if(item==2){
+      lcd.locate(11,0);
+      lcd.printf("%4Lu",ki); 
+      lcd.locate(3,1);
+      lcd.printf("_   ");
+      entero=0;}
+      
+      if(item==3){
+      lcd.locate(3,1);
+      lcd.printf("%4Lu",kd); 
+      lcd.locate(11,1);
+      lcd.printf("_   ");
+      entero=0;}
+      
+      if (item==4){
+               lcd.locate(11,1);
+               lcd.printf("%4Lu",sp); 
+               wait_ms(1000);
+               lcd.cls();   
+               lcd.printf("Los valores han\n");
+               lcd.printf("sido guardados");
+               wait_ms(4000);
+               lcd.cls();   
+               lcd.printf("Pulse * para\n");
+               lcd.printf("empezar de nuevo");
+               wait_ms(3000);
+               lcd.cls();
+               lcd.locate(0,0);
+               lcd.printf("Kp=%4Lu",kp);
+               lcd.locate(8,0);
+               lcd.printf("Ki=%4Lu",ki);
+               lcd.locate(0,1);
+               lcd.printf("Kd=%4Lu",kd);
+               lcd.locate(8,1);
+               lcd.printf("Sp=%4Lu",sp);}  
+           
+        if(item==5){
+               lcd.cls();
+               lcd.locate(0,0);
+               lcd.printf("Kp=");
+               lcd.locate(8,0);
+               lcd.printf("Ki=");
+               lcd.locate(0,1);
+               lcd.printf("Kd=");
+               lcd.locate(8,1);
+               lcd.printf("Sp=");
+               lcd.locate(3,0);
+               lcd.printf("_");
+       
+               const0=0;
+               const1=0;
+               const2=0;
+               const3=0;
+       
+               entero=0;
+               kp=0;
+               ki=0;
+               kd=0;
+               sp=0;
+               contador=-1;
+               i=-1;
+               item=0;}   
+      
+       }else if(key=='A'){
+        lcd.cls();  
+        lcd.printf("Tarea 7\n");
+        lcd.printf("Procesadores");
+         
+           }else if(key=='B'){
+        lcd.cls();   
+        lcd.printf("Susana Naranjo\n");
+        lcd.printf("Aaron Gonzalez");
+            
+           }else if(key=='C'){
+         lcd.cls();     
+         lcd.printf("Universidad\n");
+         lcd.printf("Nacional");
+          
+           }else if(key=='D'){
+         lcd.cls();    
+         lcd.printf("Facultad de\n");
+         lcd.printf("Minas");  
+           }
+       
+       else{
+           if (item==0){
+               if (i==0){
+                   lcd.locate(3,0); 
+                   lcd.printf("_   ");}
+               lcd.locate(3+i,0);
+               lcd.printf("%u",tecla);
+               kp=entero; }
+               
+           if (item==1){
+               if (i==0){
+                   lcd.locate(11,0);
+                   lcd.printf("_   ");}
+               lcd.locate(11+i,0);
+               lcd.printf("%u",tecla);
+               ki=entero;}     
+           
+           if (item==2){
+               if (i==0){
+                   lcd.locate(3,1);
+                   lcd.printf("_   "); }
+               lcd.locate(3+i,1);
+               lcd.printf("%u",tecla);
+               kd=entero;}            
+           
+           if (item==3){
+               if (i==0){
+               lcd.locate(11,1);
+               lcd.printf("_   "); }
+               lcd.locate(11+i,1);
+               lcd.printf("%u",tecla);
+               sp=entero; }  
+           
+           
+           }//else item
+           
+           contador=contador+1;
+           i++;
+           
+                 
+           
+           } //if((key !='\0')&&(released==1))
+       
+       } //while(i<=3)
+     
+    } // while(1)
+} //main