Pengujian Battery
Dependencies: SDFileSystem TextLCD mbed
Fork of Seeed_SDCard_Shield by
main.cpp@5:47c9375675bb, 2017-02-02 (annotated)
- Committer:
- ayunemiao
- Date:
- Thu Feb 02 08:01:29 2017 +0000
- Revision:
- 5:47c9375675bb
- Parent:
- 3:5edc67dee8b7
- Child:
- 6:1b08722d3aba
1
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:47c9375675bb | 252 | |
ayunemiao | 5:47c9375675bb | 253 | ulang: |
ayunemiao | 5:47c9375675bb | 254 | while(c==1) |
ayunemiao | 5:47c9375675bb | 255 | { |
ayunemiao | 5:47c9375675bb | 256 | lcd.cls(); |
ayunemiao | 5:47c9375675bb | 257 | d=t.read(); |
ayunemiao | 5:47c9375675bb | 258 | d1=t1.read(); |
ayunemiao | 5:47c9375675bb | 259 | d2=t2.read(); |
ayunemiao | 5:47c9375675bb | 260 | d3=t3.read(); |
ayunemiao | 5:47c9375675bb | 261 | d4=t4.read(); |
ayunemiao | 5:47c9375675bb | 262 | |
ayunemiao | 5:47c9375675bb | 263 | if(d==59) |
ayunemiao | 5:47c9375675bb | 264 | { |
ayunemiao | 5:47c9375675bb | 265 | t.reset(); |
ayunemiao | 5:47c9375675bb | 266 | m=m+1; |
ayunemiao | 5:47c9375675bb | 267 | |
ayunemiao | 5:47c9375675bb | 268 | } |
ayunemiao | 5:47c9375675bb | 269 | if(d1==59) |
ayunemiao | 5:47c9375675bb | 270 | { |
ayunemiao | 5:47c9375675bb | 271 | t1.reset(); |
ayunemiao | 5:47c9375675bb | 272 | m1=m1+1; |
ayunemiao | 5:47c9375675bb | 273 | |
ayunemiao | 5:47c9375675bb | 274 | } |
ayunemiao | 5:47c9375675bb | 275 | if(d2==59) |
ayunemiao | 5:47c9375675bb | 276 | { |
ayunemiao | 5:47c9375675bb | 277 | t2.reset(); |
ayunemiao | 5:47c9375675bb | 278 | m2=m2+1; |
ayunemiao | 5:47c9375675bb | 279 | |
ayunemiao | 5:47c9375675bb | 280 | } |
ayunemiao | 5:47c9375675bb | 281 | if(d3==59) |
ayunemiao | 5:47c9375675bb | 282 | { |
ayunemiao | 5:47c9375675bb | 283 | t3.reset(); |
ayunemiao | 5:47c9375675bb | 284 | m3=m3+1; |
ayunemiao | 5:47c9375675bb | 285 | |
ayunemiao | 5:47c9375675bb | 286 | } |
ayunemiao | 5:47c9375675bb | 287 | |
ayunemiao | 5:47c9375675bb | 288 | //Volt 4 Battery |
ayunemiao | 5:47c9375675bb | 289 | V1 = V1_VALUE.read(); |
ayunemiao | 5:47c9375675bb | 290 | V1 = (V1 * 3300*x1)/n; |
ayunemiao | 5:47c9375675bb | 291 | jum1 += V1; |
ayunemiao | 5:47c9375675bb | 292 | |
ayunemiao | 5:47c9375675bb | 293 | V2 = V2_VALUE.read(); |
ayunemiao | 5:47c9375675bb | 294 | V2 = ((V2 * 3300)*x2)/n; |
ayunemiao | 5:47c9375675bb | 295 | V2 = V2-V1; |
ayunemiao | 5:47c9375675bb | 296 | jum2 += V2; |
ayunemiao | 5:47c9375675bb | 297 | |
ayunemiao | 5:47c9375675bb | 298 | V3 = V3_VALUE.read(); |
ayunemiao | 5:47c9375675bb | 299 | V3 = ((V3 * 3300)*x3)/n; |
ayunemiao | 5:47c9375675bb | 300 | V3 = V3-V1-V2; |
ayunemiao | 5:47c9375675bb | 301 | jum3 += V3; |
ayunemiao | 5:47c9375675bb | 302 | |
ayunemiao | 5:47c9375675bb | 303 | V4 = V4_VALUE.read(); |
ayunemiao | 5:47c9375675bb | 304 | V4 = ((V4 * 3300)*x4)/n; |
ayunemiao | 5:47c9375675bb | 305 | V4 = V4-V1-V2-V3; |
ayunemiao | 5:47c9375675bb | 306 | jum4 += V4; |
ayunemiao | 5:47c9375675bb | 307 | |
ayunemiao | 5:47c9375675bb | 308 | count++; |
ayunemiao | 5:47c9375675bb | 309 | |
ayunemiao | 5:47c9375675bb | 310 | |
ayunemiao | 5:47c9375675bb | 311 | stat=((m*100)/jam); |
ayunemiao | 5:47c9375675bb | 312 | stat1=((m1*100)/jam); |
ayunemiao | 5:47c9375675bb | 313 | stat2=((m2*100)/jam); |
ayunemiao | 5:47c9375675bb | 314 | stat3=((m3*100)/jam); |
ayunemiao | 5:47c9375675bb | 315 | |
ayunemiao | 5:47c9375675bb | 316 | lcd.cls(); |
ayunemiao | 5:47c9375675bb | 317 | if(V1<=Vsat) |
ayunemiao | 5:47c9375675bb | 318 | { |
ayunemiao | 5:47c9375675bb | 319 | lcd.locate(10, 0); |
ayunemiao | 5:47c9375675bb | 320 | lcd.printf("C1=%.1f",stat); |
ayunemiao | 5:47c9375675bb | 321 | lcd.locate(19, 0); |
ayunemiao | 5:47c9375675bb | 322 | lcd.printf("%"); |
ayunemiao | 5:47c9375675bb | 323 | t.stop(); |
ayunemiao | 5:47c9375675bb | 324 | } |
ayunemiao | 5:47c9375675bb | 325 | if(V2<=Vsat) |
ayunemiao | 5:47c9375675bb | 326 | { |
ayunemiao | 5:47c9375675bb | 327 | lcd.locate(10, 1); |
ayunemiao | 5:47c9375675bb | 328 | lcd.printf("C2=%.1f",stat1); |
ayunemiao | 5:47c9375675bb | 329 | t1.stop(); |
ayunemiao | 5:47c9375675bb | 330 | } |
ayunemiao | 5:47c9375675bb | 331 | if(V3<=Vsat) |
ayunemiao | 5:47c9375675bb | 332 | { |
ayunemiao | 5:47c9375675bb | 333 | lcd.locate(10, 2); |
ayunemiao | 5:47c9375675bb | 334 | lcd.printf("C3=%.1f",stat2); |
ayunemiao | 5:47c9375675bb | 335 | t2.stop(); |
ayunemiao | 5:47c9375675bb | 336 | } |
ayunemiao | 5:47c9375675bb | 337 | if(V4<=Vsat) |
ayunemiao | 5:47c9375675bb | 338 | { |
ayunemiao | 5:47c9375675bb | 339 | lcd.locate(10, 3); |
ayunemiao | 5:47c9375675bb | 340 | lcd.printf("C4=%.1f",stat3); |
ayunemiao | 5:47c9375675bb | 341 | t3.stop(); |
ayunemiao | 5:47c9375675bb | 342 | } |
ayunemiao | 5:47c9375675bb | 343 | |
ayunemiao | 5:47c9375675bb | 344 | if((V4<Vsat)||(V3<Vsat)||(V2<Vsat)||(V1<Vsat)) |
ayunemiao | 5:47c9375675bb | 345 | { |
ayunemiao | 5:47c9375675bb | 346 | led=!led; |
ayunemiao | 5:47c9375675bb | 347 | } |
ayunemiao | 5:47c9375675bb | 348 | else |
ayunemiao | 5:47c9375675bb | 349 | { |
ayunemiao | 5:47c9375675bb | 350 | lcd.locate(9, 0); |
ayunemiao | 5:47c9375675bb | 351 | lcd.printf("Time:%.0d:%.0f",d3,m3); |
ayunemiao | 5:47c9375675bb | 352 | led=0; |
ayunemiao | 5:47c9375675bb | 353 | } |
ayunemiao | 5:47c9375675bb | 354 | |
ayunemiao | 5:47c9375675bb | 355 | while (count == max){ |
ayunemiao | 5:47c9375675bb | 356 | |
ayunemiao | 5:47c9375675bb | 357 | jum1/=max; |
ayunemiao | 5:47c9375675bb | 358 | jum2/=max; |
ayunemiao | 5:47c9375675bb | 359 | jum3/=max; |
ayunemiao | 5:47c9375675bb | 360 | jum4/=max; |
ayunemiao | 5:47c9375675bb | 361 | VTOTAL = jum1+jum2+jum3+jum4; |
ayunemiao | 5:47c9375675bb | 362 | |
ayunemiao | 5:47c9375675bb | 363 | abc1=jum1; |
ayunemiao | 5:47c9375675bb | 364 | abc2=jum2; |
ayunemiao | 5:47c9375675bb | 365 | abc3=jum3; |
ayunemiao | 5:47c9375675bb | 366 | abc4=jum4; |
ayunemiao | 5:47c9375675bb | 367 | |
ayunemiao | 5:47c9375675bb | 368 | jum1 = 0; |
ayunemiao | 5:47c9375675bb | 369 | jum2 = 0; |
ayunemiao | 5:47c9375675bb | 370 | jum3 = 0; |
ayunemiao | 5:47c9375675bb | 371 | jum4 = 0; |
ayunemiao | 5:47c9375675bb | 372 | count = 0; |
ayunemiao | 5:47c9375675bb | 373 | |
ayunemiao | 5:47c9375675bb | 374 | goto ulang; |
ayunemiao | 5:47c9375675bb | 375 | |
ayunemiao | 5:47c9375675bb | 376 | } |
ayunemiao | 5:47c9375675bb | 377 | lcd.locate(0, 0); |
ayunemiao | 5:47c9375675bb | 378 | lcd.printf("V1=%.1fV",abc1); |
ayunemiao | 5:47c9375675bb | 379 | lcd.locate(0, 1); |
ayunemiao | 5:47c9375675bb | 380 | lcd.printf("V2=%.1fV",abc2); |
ayunemiao | 5:47c9375675bb | 381 | lcd.locate(0, 2); |
ayunemiao | 5:47c9375675bb | 382 | lcd.printf("V3=%.1fV",abc3); |
ayunemiao | 5:47c9375675bb | 383 | lcd.locate(0, 3); |
ayunemiao | 5:47c9375675bb | 384 | lcd.printf("V4=%.1fV",abc4); |
ayunemiao | 5:47c9375675bb | 385 | wait(1.0); |
ayunemiao | 5:47c9375675bb | 386 | if(d4>902){ |
ayunemiao | 5:47c9375675bb | 387 | fprintf(fp,"%.0f,%.1f V,%.1f V,%.1f V,%.1fV,%.1f\r\n",m,abc1,abc2,abc3,abc4,VTOTAL); |
ayunemiao | 5:47c9375675bb | 388 | //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 | 5:47c9375675bb | 389 | t4.reset(); |
ayunemiao | 5:47c9375675bb | 390 | } |
ayunemiao | 5:47c9375675bb | 391 | |
ayunemiao | 5:47c9375675bb | 392 | if(mybutton==0) |
ayunemiao | 5:47c9375675bb | 393 | { |
ayunemiao | 5:47c9375675bb | 394 | c=0; |
ayunemiao | 5:47c9375675bb | 395 | led=0; |
ayunemiao | 5:47c9375675bb | 396 | fprintf(fp,"%.0f,%.1f V,%.1f V,%.1f V,%.1fV,%.1f\r\n",m,abc1,abc2,abc3,abc4,VTOTAL); |
ayunemiao | 5:47c9375675bb | 397 | break; |
ayunemiao | 5:47c9375675bb | 398 | } |
ayunemiao | 5:47c9375675bb | 399 | } |
ayunemiao | 5:47c9375675bb | 400 | |
ayunemiao | 5:47c9375675bb | 401 | fclose(fp); |
ayunemiao | 5:47c9375675bb | 402 | lcd.cls(); |
ayunemiao | 5:47c9375675bb | 403 | lcd.printf(" Pengujian Selesai"); |
ayunemiao | 5:47c9375675bb | 404 | //pc.printf("Pengujian Selsai"); |
ayunemiao | 5:47c9375675bb | 405 | wait(2.0); |
ayunemiao | 5:47c9375675bb | 406 | goto restart; |
ayunemiao | 5:47c9375675bb | 407 | } |