Pengujian Battery

Dependencies:   SDFileSystem TextLCD mbed

Fork of Seeed_SDCard_Shield by Shields

Committer:
ayunemiao
Date:
Sat Feb 11 03:56:41 2017 +0000
Revision:
6:1b08722d3aba
Parent:
5:47c9375675bb
Done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ayunemiao 5:47c9375675bb 1 #include "mbed.h"
ayunemiao 5:47c9375675bb 2 #include "TextLCD.h"
ayunemiao 5:47c9375675bb 3 #define max 5
ayunemiao 5:47c9375675bb 4 #include "SDFileSystem.h"
ayunemiao 5:47c9375675bb 5
ayunemiao 5:47c9375675bb 6
ayunemiao 5:47c9375675bb 7
ayunemiao 5:47c9375675bb 8
ayunemiao 5:47c9375675bb 9 AnalogIn V1_VALUE(A0);
ayunemiao 5:47c9375675bb 10 AnalogIn V2_VALUE(A1);
ayunemiao 5:47c9375675bb 11 AnalogIn V3_VALUE(A2);
ayunemiao 5:47c9375675bb 12 AnalogIn V4_VALUE(A3);
ayunemiao 5:47c9375675bb 13 DigitalOut led(A4);
ayunemiao 5:47c9375675bb 14 DigitalIn mybutton(USER_BUTTON);
ayunemiao 5:47c9375675bb 15 DigitalIn mybutton1(D2);
ayunemiao 5:47c9375675bb 16 DigitalIn mybutton2(D3);
ayunemiao 5:47c9375675bb 17 DigitalIn mybutton3(A5);
ayunemiao 5:47c9375675bb 18
ayunemiao 5:47c9375675bb 19 Serial pc(USBTX, USBRX);
ayunemiao 5:47c9375675bb 20 Timer t;
ayunemiao 5:47c9375675bb 21 Timer t1;
ayunemiao 5:47c9375675bb 22 Timer t2;
ayunemiao 5:47c9375675bb 23 Timer t3;
ayunemiao 5:47c9375675bb 24 Timer t4;
ayunemiao 5:47c9375675bb 25
ayunemiao 5:47c9375675bb 26 TextLCD lcd(D8, D9, D4, D5, D6, D7, TextLCD::LCD20x4);
ayunemiao 5:47c9375675bb 27 SDFileSystem sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCK, CS
ayunemiao 5:47c9375675bb 28 FILE *fp;
ayunemiao 5:47c9375675bb 29
ayunemiao 5:47c9375675bb 30
ayunemiao 5:47c9375675bb 31 float V1,V2,V3,V4,VTOTAL,m,m1,m2,m3,m4,stat,stat1,stat2,stat3,abc1,abc2,abc3,abc4;
ayunemiao 5:47c9375675bb 32 float x1=19.2225579;
ayunemiao 5:47c9375675bb 33 float x2=19.2643794;
ayunemiao 5:47c9375675bb 34 float x3=19.1854839;
ayunemiao 5:47c9375675bb 35 float x4=19.1653226;
ayunemiao 5:47c9375675bb 36 int n=1000;
ayunemiao 5:47c9375675bb 37 int p,z,x,c,d,d1,d2,d3,d4,jam,number;
ayunemiao 5:47c9375675bb 38
ayunemiao 5:47c9375675bb 39 int main()
ayunemiao 5:47c9375675bb 40 {
ayunemiao 5:47c9375675bb 41
ayunemiao 5:47c9375675bb 42 restart:
ayunemiao 5:47c9375675bb 43
ayunemiao 5:47c9375675bb 44 int count=0;
ayunemiao 5:47c9375675bb 45 float jum1,jum2,jum3,jum4;
ayunemiao 5:47c9375675bb 46
ayunemiao 5:47c9375675bb 47 lcd.cls ();
ayunemiao 5:47c9375675bb 48 lcd.locate (0, 0);
ayunemiao 5:47c9375675bb 49 lcd.printf ("********************");
ayunemiao 5:47c9375675bb 50 lcd.locate (0, 1);
ayunemiao 5:47c9375675bb 51 lcd.printf ("* Alat Ukur *");
ayunemiao 5:47c9375675bb 52 lcd.locate (0, 2);
ayunemiao 5:47c9375675bb 53 lcd.printf ("*Pengujian Battery *");
ayunemiao 5:47c9375675bb 54 lcd.locate (0, 3);
ayunemiao 5:47c9375675bb 55 lcd.printf ("********************");
ayunemiao 5:47c9375675bb 56
ayunemiao 5:47c9375675bb 57 while(1)
ayunemiao 5:47c9375675bb 58 {
ayunemiao 5:47c9375675bb 59 if (mybutton == 0){
ayunemiao 5:47c9375675bb 60 p = 1;
ayunemiao 5:47c9375675bb 61 break;
ayunemiao 5:47c9375675bb 62 }
ayunemiao 5:47c9375675bb 63 }
ayunemiao 5:47c9375675bb 64
ayunemiao 5:47c9375675bb 65 loop:
ayunemiao 5:47c9375675bb 66 //SDCARD =====================================
ayunemiao 5:47c9375675bb 67 lcd.cls();
ayunemiao 5:47c9375675bb 68 //pc.printf("Initializing\r\n");
ayunemiao 5:47c9375675bb 69 lcd.printf("Initializing");
ayunemiao 5:47c9375675bb 70 wait(0.1);
ayunemiao 5:47c9375675bb 71 lcd.cls();
ayunemiao 5:47c9375675bb 72 lcd.printf("Initializing.");
ayunemiao 5:47c9375675bb 73 wait(0.1);
ayunemiao 5:47c9375675bb 74 lcd.cls();
ayunemiao 5:47c9375675bb 75 lcd.printf("Initializing..");
ayunemiao 5:47c9375675bb 76 wait(0.1);
ayunemiao 5:47c9375675bb 77 lcd.cls();
ayunemiao 5:47c9375675bb 78 lcd.printf("Initializing...");
ayunemiao 5:47c9375675bb 79 wait(0.1);
ayunemiao 5:47c9375675bb 80
ayunemiao 5:47c9375675bb 81
ayunemiao 5:47c9375675bb 82 char buf [10];
ayunemiao 5:47c9375675bb 83 number %= 1000000;
ayunemiao 5:47c9375675bb 84 sprintf(buf,"/sd/data%d.csv",number);
ayunemiao 5:47c9375675bb 85 fp = fopen(buf, "r");
ayunemiao 5:47c9375675bb 86 if (fp != NULL) {
ayunemiao 5:47c9375675bb 87 fclose(fp);
ayunemiao 5:47c9375675bb 88 number++;
ayunemiao 5:47c9375675bb 89 //pc.printf("data%d\r\n",number);
ayunemiao 5:47c9375675bb 90 lcd.locate(0, 1);
ayunemiao 5:47c9375675bb 91 lcd.printf("data%d\r\n",number);
ayunemiao 5:47c9375675bb 92 wait(1.0);
ayunemiao 5:47c9375675bb 93 goto loop;
ayunemiao 5:47c9375675bb 94 }
ayunemiao 5:47c9375675bb 95
ayunemiao 5:47c9375675bb 96 if (number == 0) {
ayunemiao 5:47c9375675bb 97 number++;
ayunemiao 5:47c9375675bb 98 goto loop;
ayunemiao 5:47c9375675bb 99 }
ayunemiao 5:47c9375675bb 100
ayunemiao 5:47c9375675bb 101 fp = fopen(buf, "w");
ayunemiao 5:47c9375675bb 102 if (fp == NULL) {
ayunemiao 5:47c9375675bb 103 //pc.printf("Unable to write the file\r\n");
ayunemiao 5:47c9375675bb 104 lcd.printf("Unable to write the file");
ayunemiao 5:47c9375675bb 105 } else {
ayunemiao 5:47c9375675bb 106 fprintf(fp, "WAKTU,V1,V2,V3,V4,VTOTAL\n");
ayunemiao 5:47c9375675bb 107 pc.printf("File name: data%d\r\n",number);
ayunemiao 5:47c9375675bb 108 pc.printf("File successfully written!\r\n");
ayunemiao 5:47c9375675bb 109 lcd.cls();
ayunemiao 5:47c9375675bb 110 lcd.printf("File successfully\nwritten!\n");
ayunemiao 5:47c9375675bb 111 lcd.printf("File Name : data%d",number);
ayunemiao 5:47c9375675bb 112 wait(4.0);
ayunemiao 5:47c9375675bb 113 }
ayunemiao 5:47c9375675bb 114
ayunemiao 5:47c9375675bb 115 //Input Lama Pengujian ===================================================================
ayunemiao 5:47c9375675bb 116 lcd.cls();
ayunemiao 5:47c9375675bb 117 lcd.printf("Lama Pengujian:\n1 = 180 Menit\n2 = 300 Menit\n3 = 480 Menit");
ayunemiao 5:47c9375675bb 118 //pc.printf("Lama Pengujian:\n1 = 180 Menit\n2 = 300 Menit\n3 = 480 Menit");
ayunemiao 5:47c9375675bb 119 wait(1.0);
ayunemiao 5:47c9375675bb 120
ayunemiao 5:47c9375675bb 121
ayunemiao 5:47c9375675bb 122 while(p==1)
ayunemiao 5:47c9375675bb 123 {
ayunemiao 5:47c9375675bb 124 if(mybutton1==0)
ayunemiao 5:47c9375675bb 125 {
ayunemiao 5:47c9375675bb 126 lcd.cls();
ayunemiao 5:47c9375675bb 127 jam=180;
ayunemiao 5:47c9375675bb 128 lcd.locate(0, 0);
ayunemiao 5:47c9375675bb 129 lcd.printf("Pengujian 180 Menit\n");
ayunemiao 5:47c9375675bb 130 pc.printf("Pengujian 180 Menit\n");
ayunemiao 5:47c9375675bb 131 wait(1.0);
ayunemiao 5:47c9375675bb 132 z=1;
ayunemiao 5:47c9375675bb 133 p=0;
ayunemiao 5:47c9375675bb 134 break;
ayunemiao 5:47c9375675bb 135 }
ayunemiao 5:47c9375675bb 136
ayunemiao 5:47c9375675bb 137 if(mybutton2==0)
ayunemiao 5:47c9375675bb 138 {
ayunemiao 5:47c9375675bb 139 lcd.cls();
ayunemiao 5:47c9375675bb 140 jam=300;
ayunemiao 5:47c9375675bb 141 lcd.locate(0, 0);
ayunemiao 5:47c9375675bb 142 lcd.printf("Pengujian 300 Menit\n");
ayunemiao 5:47c9375675bb 143 pc.printf("Pengujian 300 Menit\n");
ayunemiao 5:47c9375675bb 144 wait(1.0);
ayunemiao 5:47c9375675bb 145 z=1;
ayunemiao 5:47c9375675bb 146 p=0;
ayunemiao 5:47c9375675bb 147 break;
ayunemiao 5:47c9375675bb 148 }
ayunemiao 5:47c9375675bb 149
ayunemiao 5:47c9375675bb 150 if(mybutton3==0)
ayunemiao 5:47c9375675bb 151 {
ayunemiao 5:47c9375675bb 152 lcd.cls();
ayunemiao 5:47c9375675bb 153 jam=480;
ayunemiao 5:47c9375675bb 154 lcd.locate(0, 0);
ayunemiao 5:47c9375675bb 155 lcd.printf("Pengujian 480 Menit\n");
ayunemiao 5:47c9375675bb 156 pc.printf("Pengujian 480 Menit\n");
ayunemiao 5:47c9375675bb 157 wait(1.0);
ayunemiao 5:47c9375675bb 158 z=1;
ayunemiao 5:47c9375675bb 159 p=0;
ayunemiao 5:47c9375675bb 160 break;
ayunemiao 5:47c9375675bb 161 }
ayunemiao 5:47c9375675bb 162 }
ayunemiao 5:47c9375675bb 163
ayunemiao 5:47c9375675bb 164 //Pengukuran Vopen=================================
ayunemiao 5:47c9375675bb 165 lcd.cls();
ayunemiao 5:47c9375675bb 166 lcd.printf("Tekan 1 Untuk V Open\n");
ayunemiao 5:47c9375675bb 167 pc.printf("Tekan 1 Untuk VOPEN\n");
ayunemiao 5:47c9375675bb 168 wait(1.0);
ayunemiao 5:47c9375675bb 169
ayunemiao 5:47c9375675bb 170 while(z==1)
ayunemiao 5:47c9375675bb 171 {
ayunemiao 5:47c9375675bb 172 V1 = V1_VALUE.read();
ayunemiao 5:47c9375675bb 173 V1 = (V1 * 3300*x1)/n;
ayunemiao 5:47c9375675bb 174
ayunemiao 5:47c9375675bb 175 V2 = V2_VALUE.read();
ayunemiao 5:47c9375675bb 176 V2 = ((V2 * 3300)*x2)/n;
ayunemiao 5:47c9375675bb 177 V2 = V2-V1;
ayunemiao 5:47c9375675bb 178
ayunemiao 5:47c9375675bb 179 V3 = V3_VALUE.read();
ayunemiao 5:47c9375675bb 180 V3 = ((V3 * 3300)*x3)/n;
ayunemiao 5:47c9375675bb 181 V3 = V3-V1-V2;
ayunemiao 5:47c9375675bb 182
ayunemiao 5:47c9375675bb 183 V4 = V4_VALUE.read();
ayunemiao 5:47c9375675bb 184 V4 = ((V4 * 3300)*x4)/n;
ayunemiao 5:47c9375675bb 185 V4 = V4-V1-V2-V3;
ayunemiao 5:47c9375675bb 186
ayunemiao 5:47c9375675bb 187 VTOTAL=V1+V2+V3+V4;
ayunemiao 5:47c9375675bb 188
ayunemiao 5:47c9375675bb 189 if(mybutton1==0)
ayunemiao 5:47c9375675bb 190 {
ayunemiao 5:47c9375675bb 191 fprintf(fp,"V Open,%.1f V,%.1f V,%.1f V,%.1fV,%.1f\r\n",V1,V2,V3,V4,VTOTAL);
ayunemiao 5:47c9375675bb 192 lcd.locate(0, 1);
ayunemiao 5:47c9375675bb 193 lcd.printf("V Open Telah Diukur");
ayunemiao 5:47c9375675bb 194 //lcd.locate(1, 2);
ayunemiao 5:47c9375675bb 195 //lcd.printf("Has been measured");
ayunemiao 5:47c9375675bb 196 pc.printf("\nVOPEN : Volt V1 = %.1f V, Volt V2 = %.1f V, Volt V3 = %.1f V, Volt V4 = %.1fV VTOTAL=%.1f\r\n",V1,V2,V3,V4,VTOTAL);
ayunemiao 5:47c9375675bb 197 wait(3.0);
ayunemiao 5:47c9375675bb 198 z=0;
ayunemiao 5:47c9375675bb 199 x=1;
ayunemiao 5:47c9375675bb 200 break;
ayunemiao 5:47c9375675bb 201 }
ayunemiao 5:47c9375675bb 202 }
ayunemiao 5:47c9375675bb 203
ayunemiao 5:47c9375675bb 204 lcd.cls();
ayunemiao 5:47c9375675bb 205 lcd.printf("Silahkan beri beban\nTekan run untuk mulai");
ayunemiao 5:47c9375675bb 206 // pc.printf("Silahkan Beri Beban\n\rTekan Run Untuk Mulai\n\r");
ayunemiao 5:47c9375675bb 207
ayunemiao 5:47c9375675bb 208 while(x==1)
ayunemiao 5:47c9375675bb 209 {
ayunemiao 5:47c9375675bb 210 V1 = V1_VALUE.read();
ayunemiao 5:47c9375675bb 211 V1 = (V1 * 3300*x1)/n;
ayunemiao 5:47c9375675bb 212
ayunemiao 5:47c9375675bb 213 V2 = V2_VALUE.read();
ayunemiao 5:47c9375675bb 214 V2 = ((V2 * 3300)*x2)/n;
ayunemiao 5:47c9375675bb 215 V2 = V2-V1;
ayunemiao 5:47c9375675bb 216
ayunemiao 5:47c9375675bb 217 V3 = V3_VALUE.read();
ayunemiao 5:47c9375675bb 218 V3 = ((V3 * 3300)*x3)/n;
ayunemiao 5:47c9375675bb 219 V3 = V3-V1-V2;
ayunemiao 5:47c9375675bb 220
ayunemiao 5:47c9375675bb 221 V4 = V4_VALUE.read();
ayunemiao 5:47c9375675bb 222 V4 = ((V4 * 3300)*x4)/n;
ayunemiao 5:47c9375675bb 223 V4 = V4-V1-V2-V3;
ayunemiao 5:47c9375675bb 224
ayunemiao 5:47c9375675bb 225 VTOTAL=V1+V2+V3+V4;
ayunemiao 5:47c9375675bb 226 abc1=V1;
ayunemiao 5:47c9375675bb 227 abc2=V2;
ayunemiao 5:47c9375675bb 228 abc3=V3;
ayunemiao 5:47c9375675bb 229 abc4=V4;
ayunemiao 5:47c9375675bb 230 if(mybutton==0)
ayunemiao 5:47c9375675bb 231 {
ayunemiao 5:47c9375675bb 232 lcd.cls();
ayunemiao 5:47c9375675bb 233 fprintf(fp,"0,%.1f V,%.1f V,%.1f V,%.1fV,%.1f\r\n",V1,V2,V3,V4,VTOTAL);
ayunemiao 5:47c9375675bb 234 lcd.printf("Pengujian Dimulai\n");
ayunemiao 5:47c9375675bb 235 //pc.printf("0,Volt V1 = %.2f V, Volt V2 = %.2f V, Volt V3 = %.2f V, Volt V4 = %.2fV VTOTAL=%.2f\r\n",V1,V2,V3,V4,VTOTAL);
ayunemiao 5:47c9375675bb 236 wait(1.0);
ayunemiao 5:47c9375675bb 237 c=1;
ayunemiao 5:47c9375675bb 238 x=0;
ayunemiao 5:47c9375675bb 239 break;
ayunemiao 5:47c9375675bb 240 }
ayunemiao 5:47c9375675bb 241 }
ayunemiao 5:47c9375675bb 242 //Timer Start
ayunemiao 5:47c9375675bb 243 t.start();
ayunemiao 5:47c9375675bb 244 t1.start();
ayunemiao 5:47c9375675bb 245 t2.start();
ayunemiao 5:47c9375675bb 246 t3.start();
ayunemiao 5:47c9375675bb 247 t4.start();
ayunemiao 5:47c9375675bb 248
ayunemiao 5:47c9375675bb 249
ayunemiao 5:47c9375675bb 250 float Vsat=10.80;
ayunemiao 5:47c9375675bb 251 int n=1000;
ayunemiao 6:1b08722d3aba 252 int k=1;
ayunemiao 5:47c9375675bb 253
ayunemiao 5:47c9375675bb 254 ulang:
ayunemiao 5:47c9375675bb 255 while(c==1)
ayunemiao 5:47c9375675bb 256 {
ayunemiao 5:47c9375675bb 257 lcd.cls();
ayunemiao 5:47c9375675bb 258 d=t.read();
ayunemiao 5:47c9375675bb 259 d1=t1.read();
ayunemiao 5:47c9375675bb 260 d2=t2.read();
ayunemiao 5:47c9375675bb 261 d3=t3.read();
ayunemiao 5:47c9375675bb 262 d4=t4.read();
ayunemiao 5:47c9375675bb 263
ayunemiao 5:47c9375675bb 264 if(d==59)
ayunemiao 5:47c9375675bb 265 {
ayunemiao 5:47c9375675bb 266 t.reset();
ayunemiao 5:47c9375675bb 267 m=m+1;
ayunemiao 5:47c9375675bb 268
ayunemiao 5:47c9375675bb 269 }
ayunemiao 5:47c9375675bb 270 if(d1==59)
ayunemiao 5:47c9375675bb 271 {
ayunemiao 5:47c9375675bb 272 t1.reset();
ayunemiao 5:47c9375675bb 273 m1=m1+1;
ayunemiao 5:47c9375675bb 274
ayunemiao 5:47c9375675bb 275 }
ayunemiao 5:47c9375675bb 276 if(d2==59)
ayunemiao 5:47c9375675bb 277 {
ayunemiao 5:47c9375675bb 278 t2.reset();
ayunemiao 5:47c9375675bb 279 m2=m2+1;
ayunemiao 5:47c9375675bb 280
ayunemiao 5:47c9375675bb 281 }
ayunemiao 5:47c9375675bb 282 if(d3==59)
ayunemiao 5:47c9375675bb 283 {
ayunemiao 5:47c9375675bb 284 t3.reset();
ayunemiao 5:47c9375675bb 285 m3=m3+1;
ayunemiao 5:47c9375675bb 286
ayunemiao 5:47c9375675bb 287 }
ayunemiao 5:47c9375675bb 288
ayunemiao 5:47c9375675bb 289 //Volt 4 Battery
ayunemiao 5:47c9375675bb 290 V1 = V1_VALUE.read();
ayunemiao 5:47c9375675bb 291 V1 = (V1 * 3300*x1)/n;
ayunemiao 5:47c9375675bb 292 jum1 += V1;
ayunemiao 5:47c9375675bb 293
ayunemiao 5:47c9375675bb 294 V2 = V2_VALUE.read();
ayunemiao 5:47c9375675bb 295 V2 = ((V2 * 3300)*x2)/n;
ayunemiao 5:47c9375675bb 296 V2 = V2-V1;
ayunemiao 5:47c9375675bb 297 jum2 += V2;
ayunemiao 5:47c9375675bb 298
ayunemiao 5:47c9375675bb 299 V3 = V3_VALUE.read();
ayunemiao 5:47c9375675bb 300 V3 = ((V3 * 3300)*x3)/n;
ayunemiao 5:47c9375675bb 301 V3 = V3-V1-V2;
ayunemiao 5:47c9375675bb 302 jum3 += V3;
ayunemiao 5:47c9375675bb 303
ayunemiao 5:47c9375675bb 304 V4 = V4_VALUE.read();
ayunemiao 5:47c9375675bb 305 V4 = ((V4 * 3300)*x4)/n;
ayunemiao 5:47c9375675bb 306 V4 = V4-V1-V2-V3;
ayunemiao 5:47c9375675bb 307 jum4 += V4;
ayunemiao 5:47c9375675bb 308
ayunemiao 5:47c9375675bb 309 count++;
ayunemiao 5:47c9375675bb 310
ayunemiao 5:47c9375675bb 311
ayunemiao 5:47c9375675bb 312 stat=((m*100)/jam);
ayunemiao 5:47c9375675bb 313 stat1=((m1*100)/jam);
ayunemiao 5:47c9375675bb 314 stat2=((m2*100)/jam);
ayunemiao 5:47c9375675bb 315 stat3=((m3*100)/jam);
ayunemiao 5:47c9375675bb 316
ayunemiao 5:47c9375675bb 317 lcd.cls();
ayunemiao 6:1b08722d3aba 318 if(abc1<=Vsat)
ayunemiao 5:47c9375675bb 319 {
ayunemiao 5:47c9375675bb 320 lcd.locate(10, 0);
ayunemiao 5:47c9375675bb 321 lcd.printf("C1=%.1f",stat);
ayunemiao 5:47c9375675bb 322 lcd.locate(19, 0);
ayunemiao 5:47c9375675bb 323 lcd.printf("%");
ayunemiao 5:47c9375675bb 324 t.stop();
ayunemiao 5:47c9375675bb 325 }
ayunemiao 6:1b08722d3aba 326 if(abc2<=Vsat)
ayunemiao 5:47c9375675bb 327 {
ayunemiao 5:47c9375675bb 328 lcd.locate(10, 1);
ayunemiao 5:47c9375675bb 329 lcd.printf("C2=%.1f",stat1);
ayunemiao 5:47c9375675bb 330 t1.stop();
ayunemiao 5:47c9375675bb 331 }
ayunemiao 6:1b08722d3aba 332 if(abc3<=Vsat)
ayunemiao 5:47c9375675bb 333 {
ayunemiao 5:47c9375675bb 334 lcd.locate(10, 2);
ayunemiao 5:47c9375675bb 335 lcd.printf("C3=%.1f",stat2);
ayunemiao 5:47c9375675bb 336 t2.stop();
ayunemiao 5:47c9375675bb 337 }
ayunemiao 6:1b08722d3aba 338 if(abc4<=Vsat)
ayunemiao 5:47c9375675bb 339 {
ayunemiao 5:47c9375675bb 340 lcd.locate(10, 3);
ayunemiao 5:47c9375675bb 341 lcd.printf("C4=%.1f",stat3);
ayunemiao 5:47c9375675bb 342 t3.stop();
ayunemiao 5:47c9375675bb 343 }
ayunemiao 5:47c9375675bb 344
ayunemiao 6:1b08722d3aba 345 if((abc4<=Vsat)||(abc3<=Vsat)||(abc2<=Vsat)||(abc1<Vsat))
ayunemiao 5:47c9375675bb 346 {
ayunemiao 5:47c9375675bb 347 led=!led;
ayunemiao 5:47c9375675bb 348 }
ayunemiao 5:47c9375675bb 349 else
ayunemiao 5:47c9375675bb 350 {
ayunemiao 5:47c9375675bb 351 lcd.locate(9, 0);
ayunemiao 5:47c9375675bb 352 lcd.printf("Time:%.0d:%.0f",d3,m3);
ayunemiao 5:47c9375675bb 353 led=0;
ayunemiao 5:47c9375675bb 354 }
ayunemiao 5:47c9375675bb 355
ayunemiao 5:47c9375675bb 356 while (count == max){
ayunemiao 5:47c9375675bb 357
ayunemiao 5:47c9375675bb 358 jum1/=max;
ayunemiao 5:47c9375675bb 359 jum2/=max;
ayunemiao 5:47c9375675bb 360 jum3/=max;
ayunemiao 5:47c9375675bb 361 jum4/=max;
ayunemiao 5:47c9375675bb 362 VTOTAL = jum1+jum2+jum3+jum4;
ayunemiao 5:47c9375675bb 363
ayunemiao 5:47c9375675bb 364 abc1=jum1;
ayunemiao 5:47c9375675bb 365 abc2=jum2;
ayunemiao 5:47c9375675bb 366 abc3=jum3;
ayunemiao 5:47c9375675bb 367 abc4=jum4;
ayunemiao 5:47c9375675bb 368
ayunemiao 5:47c9375675bb 369 jum1 = 0;
ayunemiao 5:47c9375675bb 370 jum2 = 0;
ayunemiao 5:47c9375675bb 371 jum3 = 0;
ayunemiao 5:47c9375675bb 372 jum4 = 0;
ayunemiao 5:47c9375675bb 373 count = 0;
ayunemiao 5:47c9375675bb 374
ayunemiao 5:47c9375675bb 375 goto ulang;
ayunemiao 5:47c9375675bb 376
ayunemiao 5:47c9375675bb 377 }
ayunemiao 5:47c9375675bb 378 lcd.locate(0, 0);
ayunemiao 5:47c9375675bb 379 lcd.printf("V1=%.1fV",abc1);
ayunemiao 5:47c9375675bb 380 lcd.locate(0, 1);
ayunemiao 5:47c9375675bb 381 lcd.printf("V2=%.1fV",abc2);
ayunemiao 5:47c9375675bb 382 lcd.locate(0, 2);
ayunemiao 5:47c9375675bb 383 lcd.printf("V3=%.1fV",abc3);
ayunemiao 5:47c9375675bb 384 lcd.locate(0, 3);
ayunemiao 5:47c9375675bb 385 lcd.printf("V4=%.1fV",abc4);
ayunemiao 5:47c9375675bb 386 wait(1.0);
ayunemiao 6:1b08722d3aba 387
ayunemiao 6:1b08722d3aba 388 if (((abc4<=Vsat)||(abc3<=Vsat)||(abc2<=Vsat)||(abc1<=Vsat))&&(k==1)){
ayunemiao 6:1b08722d3aba 389 fprintf(fp,"%.0f,%.1f V,%.1f V,%.1f V,%.1fV,%.1f\r\n",m,abc1,abc2,abc3,abc4,VTOTAL);
ayunemiao 6:1b08722d3aba 390 k=0;
ayunemiao 6:1b08722d3aba 391 }
ayunemiao 6:1b08722d3aba 392
ayunemiao 6:1b08722d3aba 393 if (d4>898){
ayunemiao 6:1b08722d3aba 394 fprintf(fp,"%.0f,%.1f V,%.1f V,%.1f V,%.1fV,%.1f\r\n",m,abc1,abc2,abc3,abc4,VTOTAL);
ayunemiao 6:1b08722d3aba 395 //pc.printf("%.0f,Volt V1 = %.2f V, Volt V2 = %.2f V, Volt V3 = %.2f V, Volt V4 = %.2fV VTOTAL=%.2f\r\n",m,V1,V2,V3,V4,VTOTAL);
ayunemiao 6:1b08722d3aba 396 t4.reset();
ayunemiao 5:47c9375675bb 397 }
ayunemiao 5:47c9375675bb 398
ayunemiao 6:1b08722d3aba 399 if (mybutton==0){
ayunemiao 6:1b08722d3aba 400 c=0;
ayunemiao 6:1b08722d3aba 401 led=0;
ayunemiao 6:1b08722d3aba 402 fprintf(fp,"%.0f,%.1f V,%.1f V,%.1f V,%.1fV,%.1f\r\n",m,abc1,abc2,abc3,abc4,VTOTAL);
ayunemiao 6:1b08722d3aba 403 break;
ayunemiao 5:47c9375675bb 404 }
ayunemiao 5:47c9375675bb 405 }
ayunemiao 5:47c9375675bb 406
ayunemiao 5:47c9375675bb 407 fclose(fp);
ayunemiao 5:47c9375675bb 408 lcd.cls();
ayunemiao 5:47c9375675bb 409 lcd.printf(" Pengujian Selesai");
ayunemiao 5:47c9375675bb 410 //pc.printf("Pengujian Selsai");
ayunemiao 5:47c9375675bb 411 wait(2.0);
ayunemiao 5:47c9375675bb 412 goto restart;
ayunemiao 5:47c9375675bb 413 }