Tarea2, procesadores

Dependencies:   Debounced TextLCDm mbed

Revision:
0:62bc56579cdb
diff -r 000000000000 -r 62bc56579cdb main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Nov 10 20:28:47 2013 +0000
@@ -0,0 +1,462 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "DebouncedIn.h"
+
+TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7.. Nota: No se quiere función de lectura, luego ese puerto a tierra.
+//lectura=1, escritura=0
+
+//Aumento en rampa de Sp, Kp, Ki, Kd
+PwmOut rled(LED_RED);
+
+DebouncedIn next(PTE2);
+DebouncedIn up(PTE3);
+DebouncedIn down(PTE4);
+
+Timer timer1;
+
+int C1=0x0F; 
+int i,j,k,l;
+
+int main() {
+
+int c;
+c=0;
+
+lcd.cls();     
+lcd.locate(0,0);
+lcd.printf("sp:%d",i);
+lcd.locate(8,0);
+lcd.printf("kp:%d",j);
+lcd.locate(0,1);
+lcd.printf("ki:%d",k);
+lcd.locate(8,1);
+lcd.printf("kd:%d",l);
+
+//SP
+
+while (1){
+
+if (next.falling()){    
+        c++;
+        }          
+
+    //Salto a SP
+    if (c==0){
+        
+        lcd.locate(3,0);
+        lcd.putc(0xFE);                
+        lcd.writeCommand(C1);
+        lcd.locate(3,0);
+        lcd.printf("%d",i);
+        
+            while(c==0){  
+              
+            //espacio de trabajo
+            
+            if(up.falling()||down.falling()){
+                timer1.start();
+            
+            while(up==0||down==0){                       
+                if(up==1&&down==1){
+                timer1.stop();
+                timer1.reset();
+                               }
+                if (timer1.read()>0&&timer1.read()<=5&&up==0&&i>=0&&i<=9999) {
+                ++i;                
+                wait(0.1);               
+                                                                                  } 
+                if (timer1.read()>0&&timer1.read()<=5&&down==0&&i>=0&&i<=9999) {
+                --i;                
+                wait(0.1);               
+                                                                                } 
+        
+                if (timer1.read()>5&&timer1.read()<=10&&up==0&&i>=0&&i<=9999) {
+                i+=5;                
+                wait(0.1/5);               
+                                                                              } 
+                
+                if (timer1.read()>5&&timer1.read()<=10&&down==0&&i>=0&&i<=9999) {
+                i-=5;                
+                wait(0.1/5);             
+                                                                                } 
+                
+                
+                if (timer1.read()>10&&timer1.read()<=100&&up==0&&i>=0&&i<=9999) {
+                i+=10;               
+                wait(0.03);               
+                                                                               }
+                
+                if (timer1.read()>10&&timer1.read()<=100&&down==0&&i>=0&&i<=9999) {
+                i-=10;                
+                wait(0.03);               
+                                                                                  } 
+                if (timer1.read()>10&&timer1.read()<=1000&&up==0&&i>=0&&i<=9999) {
+                i+=100;
+                wait(0.003);              
+                                                                               }
+                
+                if (timer1.read()>10&&timer1.read()<=1000&&down==0&&i>=0&&i<=9999) {
+                i-=100;                  
+                wait(0.003);
+                                                                                  } 
+                                                                                                  
+                if(i<0){
+                i=0;
+                        }
+           
+                if(i>9999){
+                i=9999;
+                }
+                
+                //NEW !! (not zeros in -- process)
+                if(i<10){                
+                lcd.locate(4,0);
+                lcd.putc(0xFE);  
+                        }
+                        
+                if(i<100){                
+                lcd.locate(5,0);
+                lcd.putc(0xFE);  
+                        }                
+                
+                if(i<1000){                
+                lcd.locate(6,0);
+                lcd.putc(0xFE);  
+                        }  
+                //
+                
+                i=i;
+                //lcd.locate(3,0);
+                //lcd.printf("     ");
+                lcd.locate(3,0);
+                lcd.printf("%d", i);
+                wait(0.2);          
+                       
+                       }
+                                            }
+           
+            //fin espacio de trabajo            
+            
+            if(next.falling()){
+                c++;
+                }                                                             
+                }
+                } 
+              
+        
+    //Salto a Kp
+    if (c==1){
+        
+        lcd.locate(11,0);
+        lcd.putc(0xFE);                
+        lcd.writeCommand(C1);
+        lcd.locate(11,0);
+        lcd.printf("%d",j);
+        
+            while(c==1){
+            
+            //Work space
+            
+            if(up.falling()||down.falling()){
+                timer1.start();
+            
+            while(up==0||down==0){                       
+                if(up==1&&down==1){
+                timer1.stop();
+                timer1.reset();
+                               }
+                if (timer1.read()>0&&timer1.read()<=5&&up==0&&j>=0&&j<=9999) {
+                ++j;                
+                wait(0.1);               
+                                                                                  } 
+                if (timer1.read()>0&&timer1.read()<=5&&down==0&&j>=0&&j<=9999) {
+                --j;                
+                wait(0.1);               
+                                                                                } 
+        
+                if (timer1.read()>5&&timer1.read()<=10&&up==0&&j>=0&&j<=9999) {
+                j+=5;                
+                wait(0.1/5);               
+                                                                              } 
+                
+                if (timer1.read()>5&&timer1.read()<=10&&down==0&&j>=0&&j<=9999) {
+                j-=5;                
+                wait(0.1/5);             
+                                                                                } 
+                
+                
+                if (timer1.read()>10&&timer1.read()<=100&&up==0&&j>=0&&j<=9999) {
+                j+=10;               
+                wait(0.03);               
+                                                                               }
+                
+                if (timer1.read()>10&&timer1.read()<=100&&down==0&&j>=0&&j<=9999) {
+                j-=10;                
+                wait(0.03);               
+                                                                                  } 
+                if (timer1.read()>10&&timer1.read()<=1000&&up==0&&j>=0&&j<=9999) {
+                j+=100;
+                wait(0.003);              
+                                                                               }
+                
+                if (timer1.read()>10&&timer1.read()<=1000&&down==0&&j>=0&&j<=9999) {
+                j-=100;                  
+                wait(0.003);
+                                                                                  } 
+                                                                                                  
+                if(j<0){
+                j=0;
+                        }
+           
+                if(j>9999){
+                j=9999;
+                }
+                
+                //NEW !! (not zeros in -- process)
+                if(j<10){                
+                lcd.locate(12,0);
+                lcd.putc(0xFE);  
+                        }
+                        
+                if(j<100){                
+                lcd.locate(13,0);
+                lcd.putc(0xFE);  
+                        }                
+                
+                if(j<1000){                
+                lcd.locate(14,0);
+                lcd.putc(0xFE);  
+                        }  
+                //
+                
+                j=j;
+                //lcd.locate(11,0);
+                //lcd.printf("     ");
+                lcd.locate(11,0); //before lcd.locate(12,0);
+                lcd.printf("%d", j);
+                wait(0.2);          
+                       
+                       }
+                                            }
+           
+            //End work space            
+              
+             if(next.falling()){
+                c++;
+                }                                                             
+                }
+                }
+              
+    //Salto a Kp
+    if (c==2){
+        
+        lcd.locate(3,1);
+        lcd.putc(0xFE);                
+        lcd.writeCommand(C1);
+        lcd.locate(3,1);
+        lcd.printf("%d",k);
+        
+            while(c==2){ 
+            
+            //Work space
+            
+            if(up.falling()||down.falling()){
+                timer1.start();
+            
+            while(up==0||down==0){                       
+                if(up==1&&down==1){
+                timer1.stop();
+                timer1.reset();
+                               }
+                if (timer1.read()>0&&timer1.read()<=5&&up==0&&k>=0&&k<=9999) {
+                ++k;                
+                wait(0.1);               
+                                                                                  } 
+                if (timer1.read()>0&&timer1.read()<=5&&down==0&&k>=0&&k<=9999) {
+                --k;                
+                wait(0.1);               
+                                                                                } 
+        
+                if (timer1.read()>5&&timer1.read()<=10&&up==0&&k>=0&&k<=9999) {
+                k+=5;                
+                wait(0.1/5);               
+                                                                              } 
+                
+                if (timer1.read()>5&&timer1.read()<=10&&down==0&&k>=0&&k<=9999) {
+                k-=5;                
+                wait(0.1/5);             
+                                                                                } 
+                
+                
+                if (timer1.read()>10&&timer1.read()<=100&&up==0&&k>=0&&k<=9999) {
+                k+=10;               
+                wait(0.03);               
+                                                                               }
+                
+                if (timer1.read()>10&&timer1.read()<=100&&down==0&&k>=0&&k<=9999) {
+                k-=10;                
+                wait(0.03);               
+                                                                                  } 
+                if (timer1.read()>10&&timer1.read()<=1000&&up==0&&k>=0&&k<=9999) {
+                k+=100;
+                wait(0.003);              
+                                                                               }
+                
+                if (timer1.read()>10&&timer1.read()<=1000&&down==0&&k>=0&&k<=9999) {
+                k-=100;                  
+                wait(0.003);
+                                                                                  } 
+                                                                                                  
+                if(k<0){
+                k=0;
+                        }
+           
+                if(k>9999){
+                k=9999;
+                }
+                
+                //NEW !! (not zeros in -- process)
+                if(k<10){                
+                lcd.locate(4,1);
+                lcd.putc(0xFE);  
+                        }
+                        
+                if(k<100){                
+                lcd.locate(5,1);
+                lcd.putc(0xFE);  
+                        }                
+                
+                if(k<1000){                
+                lcd.locate(6,1);
+                lcd.putc(0xFE);  
+                        }  
+                //
+                
+                k=k;
+                //lcd.locate(3,1);
+                //lcd.printf("     ");
+                lcd.locate(3,1); //before lcd.locate(4,1);
+                lcd.printf("%d", k);
+                wait(0.2);          
+                       
+                       }
+                                            }
+           
+            //End work space  
+
+             if(next.falling()){
+                c++;
+                }                                                             
+                }
+                }        
+
+    //Salto a Kp
+    if (c==3){
+        
+        lcd.locate(11,1);
+        lcd.putc(0xFE);                
+        lcd.writeCommand(C1);
+        lcd.locate(11,1);
+        lcd.printf("%d",l);
+        
+            while(c==3){
+            
+            //Work space
+            
+            if(up.falling()||down.falling()){
+                timer1.start();
+            
+            while(up==0||down==0){                       
+                if(up==1&&down==1){
+                timer1.stop();
+                timer1.reset();
+                               }
+                if (timer1.read()>0&&timer1.read()<=5&&up==0&&l>=0&&l<=9999) {
+                ++l;                
+                wait(0.1);               
+                                                                                  } 
+                if (timer1.read()>0&&timer1.read()<=5&&down==0&&l>=0&&l<=9999) {
+                --l;                
+                wait(0.1);               
+                                                                                } 
+        
+                if (timer1.read()>5&&timer1.read()<=10&&up==0&&l>=0&&l<=9999) {
+                l+=5;                
+                wait(0.1/5);               
+                                                                              } 
+                
+                if (timer1.read()>5&&timer1.read()<=10&&down==0&&l>=0&&l<=9999) {
+                l-=5;                
+                wait(0.1/5);             
+                                                                                } 
+                
+                
+                if (timer1.read()>10&&timer1.read()<=100&&up==0&&l>=0&&l<=9999) {
+                l+=10;               
+                wait(0.03);               
+                                                                               }
+                
+                if (timer1.read()>10&&timer1.read()<=100&&down==0&&l>=0&&l<=9999) {
+                l-=10;                
+                wait(0.03);               
+                                                                                  } 
+                if (timer1.read()>10&&timer1.read()<=1000&&up==0&&l>=0&&l<=9999) {
+                l+=100;
+                wait(0.003);              
+                                                                               }
+                
+                if (timer1.read()>10&&timer1.read()<=1000&&down==0&&l>=0&&l<=9999) {
+                l-=100;                  
+                wait(0.003);
+                                                                                  } 
+                                                                                                  
+                if(l<0){
+                l=0;
+                        }
+           
+                if(l>9999){
+                l=9999;
+                }
+                
+                //NEW !! (not zeros in -- process)
+                if(l<10){                
+                lcd.locate(12,1);
+                lcd.putc(0xFE);  
+                        }
+                        
+                if(l<100){                
+                lcd.locate(13,1);
+                lcd.putc(0xFE);  
+                        }                
+                
+                if(l<1000){                
+                lcd.locate(14,1);
+                lcd.putc(0xFE);  
+                        }  
+                //
+                
+                l=l;
+                //lcd.locate(11,1);
+                //lcd.printf("     ");
+                lcd.locate(11,1); //before lcd.locate(12,1);
+                lcd.printf("%d", l);
+                wait(0.2);          
+                       
+                       }
+                                            }
+           
+            //End work space                           
+             
+             if(next.falling()){
+                c++;
+                                }                                                             
+                }
+                }   
+
+    //          
+                 if(c==4 || c>4){
+                c=0;
+                                }                                                                                  
+                         
+}
+}  
\ No newline at end of file