#define FLOAT /* Must use floating point routines in clib */ #define ZCPR3 /* Must use ZCPR3 " " " */ #include /* A cheaters way of doing floating point input */ #define finput atof((ptr=gets(temp,28))) extern float atof(); extern char *gets(); x_vc() { float Vsec,Vrect,Iout,Rs,C; float Vpeak,Vc,Vripple,PIV,Isurge,PDavg; char temp[30],*ptr; Cmode=1; cls(); printf("Enter in the following values:\n"); printf("Vsec,rms ="); Vsec=finput; printf("Vrect ="); Vrect=finput; printf("Iout ="); Iout=finput; printf("Rsec cir ="); Rs=finput; printf("Cfarads ="); C=finput; Vpeak = (Vsec * 1.414) - Vrect; Vripple = (.0833 * Iout) / C; Vc = Vpeak - Vripple; PIV = 1.414 * Vsec; Isurge = Vpeak / Rs; PDavg = (((C * Vripple / .00119) + Iout) * Vrect ) / 13.96; printf("\nThe following are the calculated values\n"); printf("Vpeak = %.2f\tVripple = %.2f\tVc = %.2f\n",Vpeak,Vripple,Vc); printf("PIV = %.2f\tIsurge = %.2f\tPDavg = %.2f\n",PIV,Isurge,PDavg); wait(); } vc_x() { float Vc,Vripple,Vrect,Iout,Rs; float Vpeak,Vsec,C,Isurge,PDavg,PIV; char temp[30],*ptr; Cmode=1; cls(); printf("Enter in the following values:\n"); printf("Vc ="); Vc=finput; printf("Vripple ="); Vripple=finput; printf("Vrect ="); Vrect=finput; printf("Iout ="); Iout=finput; printf("Rsec cir ="); Rs=finput; Vpeak = Vc + Vripple; Vsec = (Vpeak+Vrect) / 1.414; C = (.0833 / Vripple) * Iout; Isurge = Vpeak / Rs; PDavg = (((C * Vripple / .00119) + Iout) * Vrect) / 13.96; printf("The following are the calculated values:\n"); printf("Vpeak %.2f\tVsec %.2f\tC %.6f\n",Vpeak,Vsec,C); printf("Isurge %.2f\tPDavg %.2f\n",Isurge,PDavg); wait(); } wait() { inchar("Press a key to go return to the menu : :\b\b"); } main() { char choice; zsysinit(); while(TRUE) { cls(); stndout(); puts("\t\t+-------------------------------------+\n"); puts("\t\t| POWER SUPPLY CALCULATOR |\n"); puts("\t\t+-------------------------------------+\n"); puts("\t\t| |\n"); puts("\t\t| 1. Xformer to Vc |\n"); puts("\t\t| |\n"); puts("\t\t| 2. Vc to Xformer |\n"); puts("\t\t| |\n"); puts("\t\t| 3. Exit |\n"); puts("\t\t| |\n"); puts("\t\t+-------------------------------------+\n"); puts("\t\t : :\b\b"); stndend(); Cmode=0; switch((choice=getchar())) { case '1' : x_vc(); break; case '2' : vc_x(); break; case '3' : exit(); default : putchar('\07'); break; } } }