![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Permite la configuración de los parámetros Kp, Ki Kd y Sp en un Display LCD 16x2 en un teclado matricial 4x4.
Dependencies: TextLCD keypad mbed
main.cpp
- Committer:
- SSJprocesa
- Date:
- 2016-05-17
- Revision:
- 0:626b11d510b7
File content as of revision 0:626b11d510b7:
#include "mbed.h" #include "TextLCD.h" #include "Keypad.h" TextLCD lcd(PTC9, PTC8, PTA5, PTA4, PTA12, PTD4); // rs, e, d4-d7 int long g=0,p=0,i=0,d=0,s=0,chan=0,num=0; int c=1,b=1,a=15,uno=0,dos=0,tre=0,cua=0,aux=0,jod=0,pla=0,aste=0; int Keytable[] = { 1, 2, 3, 10, // r0 4, 5, 6, 11, // r1 7, 8, 9, 12, // r2 20,0, 21, 13 // r3 }; uint32_t cbAfterInput(uint32_t index) { a = index; return 0; } void limpiar() { c=1,a=15,uno=0,dos=0,tre=0,cua=0,aux=0,b=1,jod=0,pla=0; } void nds() { if(aste==0){lcd.locate((3+aux),0);} if(aste==1){lcd.locate((11+aux),0);} if(aste==2){lcd.locate((3+aux),1);} if(aste==3){lcd.locate((11+aux),1);} } void mostrar () { lcd.locate(0,0); lcd.printf("Kp=%Ld", p); lcd.locate(8,0); lcd.printf("Ki=%Ld", i); lcd.locate(0,1); lcd.printf("Kd=%Ld", d); lcd.locate(8,1); lcd.printf("Sp=%Ld", s); } void titi() { jod++; if(jod<=1000){ nds(); lcd.printf ("_"); } if(jod>=2000){ nds(); lcd.printf ("%Ld",chan); } if(jod==3000){jod=0;} } int long numero() { while(b==1&&c==1) { titi(); nds(); lcd.printf("%Ld",chan); if(Keytable[a]==21){ aux++; if(aux==4){c=0;aux=3;} a=15; chan=0;} if(Keytable[a]==10){b=0;chan=0;} if(Keytable[a]!=10&&Keytable[a]!=11&&Keytable[a]!=12&&Keytable[a]!=13&&Keytable[a]!=20&&Keytable[a]!=21&&a!=15) { chan=Keytable[a]; nds(); lcd.printf ("%Ld",chan); if(chan==50){chan=0;} switch(aux){ case 0:uno=chan; break; case 1:dos=chan; break; case 2:tre=chan; break; case 3:cua=chan; break; default : a=15; } a=15; } } aux=aux; switch(aux) { case 0: uno=uno; break; case 1: uno=uno*10;dos=dos; break; case 2: uno=uno*100;dos=dos*10;tre=tre; break; case 3: uno=uno*1000;dos=dos*100;tre=tre*10;cua=cua; break; default : aux=0; } num=uno+dos+tre+cua; aux=0; return(num); } int main() { // r0 r1 r2 r3 c0 c1 c2 c3 Keypad keypad(PTC11, PTC10, PTC6, PTC5, PTC4, PTC3, PTC0, PTC7); keypad.attach(&cbAfterInput); keypad.start(); // energize the keypad via c0-c3 mostrar(); while(1) { if(Keytable[a]==10) { if(aste==4){aste=0;} switch(aste) { case 0:limpiar(); lcd.locate(3,0); lcd.printf(" "); p=numero(); mostrar(); break; case 1:limpiar(); lcd.locate(11,0); lcd.printf(" "); i=numero(); mostrar(); break; case 2:limpiar(); lcd.locate(3,1); lcd.printf(" "); d=numero(); mostrar(); break; case 3:limpiar(); lcd.locate(11,1); lcd.printf(" "); s=numero(); mostrar(); break; } aste++; } } }