TAREA 1 PROCESADORES
Dependencies: Debounced TextLCD1 mbed
main.cpp@0:4bbed673452c, 2013-11-18 (annotated)
- Committer:
- caaruizze
- Date:
- Mon Nov 18 01:44:07 2013 +0000
- Revision:
- 0:4bbed673452c
TAREA 1 ESCRITURA PARAMETROS lEN UN LCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
caaruizze | 0:4bbed673452c | 1 | #include "mbed.h" |
caaruizze | 0:4bbed673452c | 2 | #include "DebouncedIn.h" |
caaruizze | 0:4bbed673452c | 3 | #include "TextLCD1.h" |
caaruizze | 0:4bbed673452c | 4 | int C1=0x0e; |
caaruizze | 0:4bbed673452c | 5 | int i,k,j,n; |
caaruizze | 0:4bbed673452c | 6 | int x=1; |
caaruizze | 0:4bbed673452c | 7 | int px=3,py=0; |
caaruizze | 0:4bbed673452c | 8 | int B1,B2; |
caaruizze | 0:4bbed673452c | 9 | |
caaruizze | 0:4bbed673452c | 10 | int main() { |
caaruizze | 0:4bbed673452c | 11 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5) ;// declaración de los puertos del lcd |
caaruizze | 0:4bbed673452c | 12 | DebouncedIn b1(PTC16); //cambio de posición |
caaruizze | 0:4bbed673452c | 13 | DebouncedIn b2(PTC13);// aumento, |
caaruizze | 0:4bbed673452c | 14 | DebouncedIn b3(PTC12);// disminuye |
caaruizze | 0:4bbed673452c | 15 | lcd.printf("TAREA1:Proc"); // IMPRIMIR |
caaruizze | 0:4bbed673452c | 16 | wait(1); // espera 1 segundo |
caaruizze | 0:4bbed673452c | 17 | lcd.cls(); // borra lcd |
caaruizze | 0:4bbed673452c | 18 | lcd.writeCommand(C1); // escribe el comando C1 |
caaruizze | 0:4bbed673452c | 19 | // Localiza y escribe los titulos Sp,Kp,Ki,Kd en la patalla |
caaruizze | 0:4bbed673452c | 20 | lcd.locate(0,0); |
caaruizze | 0:4bbed673452c | 21 | lcd.printf("Sp:%d", b1.read()); |
caaruizze | 0:4bbed673452c | 22 | lcd.locate(8,0); |
caaruizze | 0:4bbed673452c | 23 | lcd.printf("Kp:%d",b1.read()); |
caaruizze | 0:4bbed673452c | 24 | lcd.locate(0,1); |
caaruizze | 0:4bbed673452c | 25 | lcd.printf("Ki:%d",b1.read()); |
caaruizze | 0:4bbed673452c | 26 | lcd.locate(8,1); |
caaruizze | 0:4bbed673452c | 27 | lcd.printf("Kd:%d",b1.read()); |
caaruizze | 0:4bbed673452c | 28 | // Ciclo infinito |
caaruizze | 0:4bbed673452c | 29 | while (1) |
caaruizze | 0:4bbed673452c | 30 | { |
caaruizze | 0:4bbed673452c | 31 | if(b2.falling()){ |
caaruizze | 0:4bbed673452c | 32 | x=x+1; |
caaruizze | 0:4bbed673452c | 33 | |
caaruizze | 0:4bbed673452c | 34 | } |
caaruizze | 0:4bbed673452c | 35 | //condicionales para ubicación en pantalla |
caaruizze | 0:4bbed673452c | 36 | if(x==1){ |
caaruizze | 0:4bbed673452c | 37 | px=3; |
caaruizze | 0:4bbed673452c | 38 | py=0; |
caaruizze | 0:4bbed673452c | 39 | |
caaruizze | 0:4bbed673452c | 40 | } |
caaruizze | 0:4bbed673452c | 41 | if(x==2) |
caaruizze | 0:4bbed673452c | 42 | { |
caaruizze | 0:4bbed673452c | 43 | px=11; |
caaruizze | 0:4bbed673452c | 44 | py=0; |
caaruizze | 0:4bbed673452c | 45 | } |
caaruizze | 0:4bbed673452c | 46 | |
caaruizze | 0:4bbed673452c | 47 | if(x==3){ |
caaruizze | 0:4bbed673452c | 48 | px=3; |
caaruizze | 0:4bbed673452c | 49 | py=1; |
caaruizze | 0:4bbed673452c | 50 | } |
caaruizze | 0:4bbed673452c | 51 | if(x==4){ |
caaruizze | 0:4bbed673452c | 52 | px=11; |
caaruizze | 0:4bbed673452c | 53 | py=1; |
caaruizze | 0:4bbed673452c | 54 | } |
caaruizze | 0:4bbed673452c | 55 | if(x>4){ |
caaruizze | 0:4bbed673452c | 56 | //px=0; |
caaruizze | 0:4bbed673452c | 57 | //py=0; |
caaruizze | 0:4bbed673452c | 58 | x=1; |
caaruizze | 0:4bbed673452c | 59 | } |
caaruizze | 0:4bbed673452c | 60 | //condicional para contador ascendente y imprimir |
caaruizze | 0:4bbed673452c | 61 | |
caaruizze | 0:4bbed673452c | 62 | if(px==3 && py==0){ |
caaruizze | 0:4bbed673452c | 63 | if(b1.falling()){ |
caaruizze | 0:4bbed673452c | 64 | i=i+1; |
caaruizze | 0:4bbed673452c | 65 | } |
caaruizze | 0:4bbed673452c | 66 | if(b3.falling()){ |
caaruizze | 0:4bbed673452c | 67 | i=i-1; |
caaruizze | 0:4bbed673452c | 68 | } |
caaruizze | 0:4bbed673452c | 69 | if(i<0){ |
caaruizze | 0:4bbed673452c | 70 | i=0; |
caaruizze | 0:4bbed673452c | 71 | } |
caaruizze | 0:4bbed673452c | 72 | lcd.locate(px,py); |
caaruizze | 0:4bbed673452c | 73 | lcd.printf("%d",i); |
caaruizze | 0:4bbed673452c | 74 | |
caaruizze | 0:4bbed673452c | 75 | } |
caaruizze | 0:4bbed673452c | 76 | |
caaruizze | 0:4bbed673452c | 77 | if(px==11 && py==0){ |
caaruizze | 0:4bbed673452c | 78 | if(b1.falling()){ |
caaruizze | 0:4bbed673452c | 79 | k=k+1; |
caaruizze | 0:4bbed673452c | 80 | } |
caaruizze | 0:4bbed673452c | 81 | if(b3.falling()){ |
caaruizze | 0:4bbed673452c | 82 | k=k-1; |
caaruizze | 0:4bbed673452c | 83 | } |
caaruizze | 0:4bbed673452c | 84 | if(k<0){ |
caaruizze | 0:4bbed673452c | 85 | k=0; |
caaruizze | 0:4bbed673452c | 86 | } |
caaruizze | 0:4bbed673452c | 87 | lcd.locate(px,py); |
caaruizze | 0:4bbed673452c | 88 | lcd.printf("%d",k); |
caaruizze | 0:4bbed673452c | 89 | } |
caaruizze | 0:4bbed673452c | 90 | |
caaruizze | 0:4bbed673452c | 91 | if(px==3 && py==1){ |
caaruizze | 0:4bbed673452c | 92 | if(b1.falling()){ |
caaruizze | 0:4bbed673452c | 93 | j=j+1; |
caaruizze | 0:4bbed673452c | 94 | } |
caaruizze | 0:4bbed673452c | 95 | if(b3.falling()){ |
caaruizze | 0:4bbed673452c | 96 | j=j-1; |
caaruizze | 0:4bbed673452c | 97 | } |
caaruizze | 0:4bbed673452c | 98 | if(j<0){ |
caaruizze | 0:4bbed673452c | 99 | j=0; |
caaruizze | 0:4bbed673452c | 100 | } |
caaruizze | 0:4bbed673452c | 101 | lcd.locate(px,py); |
caaruizze | 0:4bbed673452c | 102 | lcd.printf("%d",j); |
caaruizze | 0:4bbed673452c | 103 | } |
caaruizze | 0:4bbed673452c | 104 | if(px==11 && py==1){ |
caaruizze | 0:4bbed673452c | 105 | if(b1.falling()){ |
caaruizze | 0:4bbed673452c | 106 | n=n+1; |
caaruizze | 0:4bbed673452c | 107 | } |
caaruizze | 0:4bbed673452c | 108 | if(b3.falling()){ |
caaruizze | 0:4bbed673452c | 109 | n=n-1; |
caaruizze | 0:4bbed673452c | 110 | } |
caaruizze | 0:4bbed673452c | 111 | if(n<0){ |
caaruizze | 0:4bbed673452c | 112 | n=0; |
caaruizze | 0:4bbed673452c | 113 | } |
caaruizze | 0:4bbed673452c | 114 | lcd.locate(px,py); |
caaruizze | 0:4bbed673452c | 115 | lcd.printf("%d",n); |
caaruizze | 0:4bbed673452c | 116 | } |
caaruizze | 0:4bbed673452c | 117 | //localizar en px,py y imprimir el valor de i |
caaruizze | 0:4bbed673452c | 118 | //lcd.locate(px,py); |
caaruizze | 0:4bbed673452c | 119 | //lcd.printf("%d",i); |
caaruizze | 0:4bbed673452c | 120 | /* |
caaruizze | 0:4bbed673452c | 121 | if(px==3 && py==0){ |
caaruizze | 0:4bbed673452c | 122 | |
caaruizze | 0:4bbed673452c | 123 | }*/ |
caaruizze | 0:4bbed673452c | 124 | |
caaruizze | 0:4bbed673452c | 125 | } |
caaruizze | 0:4bbed673452c | 126 | } |
caaruizze | 0:4bbed673452c | 127 | |
caaruizze | 0:4bbed673452c | 128 | |
caaruizze | 0:4bbed673452c | 129 | |
caaruizze | 0:4bbed673452c | 130 |