#include #include #include #include /* 35.476 Computer Applications Laboratory Interactive Lab Tutorial using an IBM PC-AT compatible and an RTI-815-A Multifunction Analog/Digital Board by Analog Devices for BINARY COMMUNICATIONS lab by Dai Vu Fall 1993 modified by Russell P. Kraft Spring 1994 modified by Russell P. Kraft Spring 1998 (for 166MHz PentiumII MMX-HP) modified by Russell P. Kraft Spring 2005 (for 400MHz PentiumII MMX-Dell) The purpose of this tutorial is to allow students to investigate some important concepts of communications: digital modulation techniqes and error-control coding. Through menu options, the students will be able to: (1) Digitize an analog signal from a function generator using two different modulation techniques: pulse amplitude modulation (PAM) and pulse code modulation (PCM); Set important parameters and examine how that affects the modulated wave. (2) Investigate error-control codes by having them enter binary words and having the program generated error-control coding using parity code or hamming code. (3) Simulate a noisy channel by generating a random input bit stream of 50,000 words using the modulation techniques of (1) and summing the input with a noise generator. */ #define numrec 50048 void dmt(void); /* digital modulation technique menu */ void ecc(void); /* error-control coding routine */ void cgen(void); /* code generation */ void cver(void); /* code verification */ void tcs(void); /* transmission of coded signals menu */ void pam(void); /* PAM routine */ void pcm(void); /* PCM routine */ void ham1(void); /* tcs w/ hamming single error correction */ void ham2(void); /* tcs w/ hamming single/double error detection */ void oddp(void); /* tcs w/ odd parity */ void ask(void); void warn(void); /* general warning error */ int pcmam=2; main() { int c,quit=0; /* main menu */ /* set graphic setting to EGA monitor */ /* any changes in monitor/video board hardware will need to change this line !!! */ _setvideomode(_ERESCOLOR); while (quit!=1) { _clearscreen (_GCLEARSCREEN); _settextposition(6,0); printf (" 35.476 Computer Applications Laboratory\n\n"); printf (" BINARY COMMUNICATIONS\n\n\n"); printf (" (1) DIGITAL MODULATION TECHNIQUES\n"); printf (" (2) ERROR-CONTROL CODING\n"); printf (" (3) TRANSMISSION OF CODED SIGNALS\n"); printf (" (4) EXIT PROGRAM\n"); printf ("\n\n Please enter a choice:\n\n"); /* This part simply draws the border and back shadow */ _setcolor (4); _rectangle (_GBORDER, 80,40,480,260); /* Draw the border */ _rectangle (_GFILLINTERIOR, 480,50,500,260); /* Draw backdrop */ _rectangle (_GFILLINTERIOR, 90,260,500,270); while (!kbhit()); c=getch(); /* determine what the user wanted */ switch (c) { case '1':dmt(); break; case '2':ecc(); break; case '3':tcs(); break; case 'q': case '4':quit=1; break; default:break; } } _setvideomode(_DEFAULTMODE); } void dmt(void) { /* This subroutine simply provides a submenu below the main menu for the selection of a particular digital modulation technique */ int c_dmt,quit_dmt=0; while (quit_dmt!=1) { _clearscreen (_GCLEARSCREEN); _settextposition(6,0); /* menu options */ printf (" DIGITAL MODULATION TECHNIQUES\n\n\n"); printf (" (1) Pulse Amplitude Modulation\n"); printf (" (2) Pulse Code Modulation\n"); printf (" (3) Return to Main Menu\n"); printf ("\n\n Please enter a choice:\n\n"); /* Again, this part simply draws the border and back shadow */ _setcolor (2); /* Green */ _rectangle (_GBORDER, 80,40,480,260); /* Draw the border */ _rectangle (_GFILLINTERIOR, 480,50,500,260); /* Draw backdrop */ _rectangle (_GFILLINTERIOR, 90,260,500,270); while (!kbhit()); c_dmt = getch(); /* Check to see what selection was made */ switch (c_dmt) { case '1':pam(); break; case '2':pcm(); break; case 'q': case '3':quit_dmt=1; break; default:break; } } } void ecc(void) { /* This subroutine simply provides a submenu below the main menu for the selection of either code generation or verification */ int c_ecc,quit_ecc=0; while (quit_ecc!=1) { _clearscreen (_GCLEARSCREEN); _settextposition(6,0); /* menu options */ printf (" ERROR CONTROL CODING\n\n\n"); printf (" (1) Code Generation\n"); printf (" (2) Code Verification\n"); printf (" (3) Return to Main Menu\n"); printf ("\n\n Please enter a choice:\n\n"); /* Again, this part simply draws the border and back shadow */ _setcolor (2); /* Green */ _rectangle (_GBORDER, 80,40,480,260); /* Draw the border */ _rectangle (_GFILLINTERIOR, 480,50,500,260); /* Draw backdrop */ _rectangle (_GFILLINTERIOR, 90,260,500,270); while (!kbhit()); c_ecc = getch(); /* Check to see what selection was made */ switch (c_ecc) { case '1':cgen(); break; case '2':cver(); break; case 'q': case '3':quit_ecc=1; break; default:break; } } } void cgen(void) { int state,c,k,count,word,b[8]; _clearscreen(_GCLEARSCREEN); printf ("\n ERROR CODE GENERATION\n\n"); printf (" This excercise allows you to toggle the individual bits\n"); printf (" of a binary word and see how the error control coding \n"); printf (" changes. To toggle a particular bit, simply hit the key\n"); printf (" OVER that bit. To change the coding scheme, hit the (H)\n"); printf (" for Hamming Code; (E) for Even Parity; (O) for Odd Parity.\n"); printf (" (Q) to return to the main menu\n"); /* Draw fancy border and back shadow */ _setcolor (3); _rectangle (_GBORDER, 0,0,600,300); _rectangle (_GFILLINTERIOR, 600,20,620,320); _rectangle (_GFILLINTERIOR, 20,300,620,320); word=0; state=1; /* Set the initial setting to odd parity */ _settextposition (12,5); printf("ODD PARITY \n"); _settextposition (14,13); printf("1 2 3 4 5 6 7"); /* The PARITY LOOP */ loop1: count=state; /* Checks to see if there is even or odd parity. If it is even parity, the count, the # of 1 bits is initally set to 1, not 0 */ _settextposition (15,5); for(k=0;k<8;k++)b[k]=0; for(k=0;k<7;k++) { if(word&1<12)) { warn(); bits=temp1; goto starter; } printf ("The relative delay: (0-255)"); scanf ("%s",token); sscanf (token, "%i", &del); del1=del*3; del2=del1+80; _settextposition(22,40); temp1=state; printf ("(0) RTZ or (1) NRTZ:"); scanf ("%s",token); sscanf (token, "%d", &state); /* Valid range? */ if ((state!=1)&&(state!=0)) { warn(); state=temp1; goto starter; } /* Set the correct mask bits */ switch (bits) { case 12:h=0x0fff;break; /* 0000 1111 1111 1111 */ case 11:h=0x0ffe;break; /* 0000 1111 1111 1110 */ case 10:h=0x0ffc;break; /* 0000 1111 1111 1100 */ case 9:h=0x0ff8;break; /* .... */ case 8:h=0x0ff0;break; case 7:h=0x0fe0;break; case 6:h=0x0fc0;break; case 5:h=0x0f80;break; case 4:h=0x0f00;break; case 3:h=0x0e00;break; case 2:h=0x0c00;break; case 1:h=0x0800;break; /* 0000 1000 0000 0000 */ default:break; } _settextposition(20,20); printf (" %i ", bits); _settextposition(21,18); printf (" %i ", del); /* Clear the screen */ _settextposition(18,35); printf (" "); _settextposition(19,35); printf (" "); _settextposition(20,35); printf (" "); _settextposition(21,35); printf (" "); _settextposition(22,35); printf (" "); _settextposition(23,35); printf (" "); _settextposition(24,35); printf (" "); _settextposition(25,35); printf (" "); _settextposition(22,9); if (state==1) { printf ("NRTZ"); goto loop1; } else { printf("RTZ "); del=del/3; del1=del*3; del2=del1+80; goto loop2; } end: free(token); } void pcm(void) { int temp1,i,j,l,pos,a,neg,b[8],c,state,bits,sbits,h,mask[9]; int v,temp3,lloop,del1,del2,dummy,delay0; unsigned char loop,k,del; unsigned char *i1,*i0,*j1,*j0,*l0,*l1,*p0,*p1,*n1,*n0; char token; token=malloc(5); i0=&i; i1=i0+1; /* set i1 & i0 to the high & low bytes of i */ j0=&j; j1=j0+1; /* same for j0 & j1 */ l0=&l; l1=l0+1; /* same for l0 & l1 */ p0=&pos; p1=p0+1; n0=&neg; n1=n0+1; delay0=6; /* Set the values */ pos=410; /* output the positive output amplitude */ neg=-410; /* output the negative output amplitude */ del=2; /* Set the initial bit duration */ // del1=2*del; del1=100+2*del; del2=500; bits=8; /* Set the initial bits resolution */ sbits=9-bits; state=1; /* Set the initial state: NRTZ */ v = (int) (pos * 20/4096); for(k=0;k<9;k++)mask[k]=1<<(3+k); starter:_clearscreen(_GCLEARSCREEN); outp(0x301,0); /* select A/D ch. 0, set gain to 1 */ printf ("\n PULSE CODE MODULATION\n\n"); printf (" (1) Hit the space bar to change current settings.\n"); printf (" - # Bits resolution - the degree of accuracy\n"); printf (" of the sample voltage: any value between 1 and 8\n"); printf (" - Relative Wait Timer - relative delay correlating\n"); printf (" with bit duration, Tb: any value between 0 and 127.\n"); printf (" - PCM amplitude - amplitude of the output voltage.\n"); printf (" - Mode - Return to Zero (0) or Non-Return to Zero (1)\n"); printf (" (2) Hit 'q' to quit the program\n"); /* Draw border around the directions */ _setcolor (3); /* cyan */ _rectangle (_GBORDER, 0,0,600,200); _rectangle (_GFILLINTERIOR, 600,20,620,220); _rectangle (_GFILLINTERIOR, 20,200,620,220); _settextposition(19,2); /* Print the initial settings */ printf(" #Bits Resolution: %d\n",bits); printf(" Relative Delay: %i\n", del); printf(" PCM amplitude: %i V\n",v); if (state==1) printf (" Mode: NRTZ\n"); else printf (" Mode:RTZ \n"); /* border around the current settings */ _setcolor (3); /* cyan */ _rectangle (_GBORDER, 0,250,220,320); _rectangle (_GFILLINTERIOR, 220,260,230,330); _rectangle (_GFILLINTERIOR, 20,320,230,330); if (state==0) goto loop2; /* Non-Return to Zero */ loop1: outp(0x302,0); /* start conversion */ if (kbhit()) goto testkey; /* Check to see if the keyboard has been hit*/ while(inp(0x300)&0x80); *i0=inp(0x303); *i1=inp(0x304); /* get input voltage */ l=0; /* clear reconstruction value */ dummy=log(delay0); outp(0x301,1); /* select A/D chan 1 */ for(lloop=0;lloop= */ if(j>0) l=l|mask[k]; /* set corresponding bit in reconstr value to 1*/ } outp(0x301,0); /* return to A/D chan 0 */ outp(0x307,*l0); outp(0x308,*l1); /* output reconstructed value to D/A 1 */ for(lloop=0;lloop= */ if(j>0) l=l|mask[k]; /* set corresponding bit in reconstr value to 1*/ for(lloop=0;lloop8)) { warn(); bits=temp1; goto starter; } sbits=9-bits; _settextposition(21,40); printf("Relative delay (0-255):"); scanf ("%s",token); sscanf (token, "%i", &del); // del1=2*del; del1=100+2*del; del2=del1+400; _settextposition(22,40); temp3=v; printf("Amplitude voltage 0-10V: "); scanf ("%s",token); sscanf (token, "%i", &v); /* Checking for valid input */ if ((v<0)||(v>10)) { warn(); v=temp3; goto starter; } neg = (int)(-204.8*v); pos = -neg; if(pos>0x07ff) pos=0x07ff; _settextposition(23,40); temp1=state; printf("(0) RTZ or (1) NRTZ:"); scanf ("%s",token); sscanf (token, "%d", &state); /* Checking for valid input */ if ((state!=1)&&(state!=0)) { warn(); state=temp1; goto starter; } _settextposition(19,21); printf("%i ",bits); _settextposition(20,19); printf("%i ",del); _settextposition(21,18); printf("%i ",v); /* Clear the screen */ _settextposition(18,35); printf (" "); _settextposition(19,35); printf (" "); _settextposition(20,35); printf (" "); _settextposition(21,35); printf (" "); _settextposition(22,35); printf (" "); _settextposition(23,35); printf (" "); _settextposition(24,35); printf (" "); _settextposition(25,35); printf (" "); _settextposition(22,9); if (state==1) { printf("NRTZ "); goto loop1; } else { printf("RTZ "); del=del/2; // del1=2*del; del1=100+2*del; del2=del1+100; goto loop2; } end: free(token); } void ham1(void) { int smallrec,errct; int data[64],sl,i,bcount,gcount,b,g,j,norm; int pos,neg,c_ham1; int delay,dcnt; float xdel; long int count=0,lp,err[4],bitct=0; unsigned char *i1,*i0,*p0,*p1,*n0,*n1; neg = (int) (-204.8 * pcmam); pos = -neg; if(pos>0x07ff) pos=0x07ff; /* Initialize delay based on pulse amplitude */ delay=(int)4.*(5.+log(pcmam)); xdel=0.; /* Initialize the error counter */ for (lp=0;lp<4;lp++) err[lp]=0; /* Pseudo random number generator!!! */ data[0]=22;data[1]=83;data[2]=88;data[3]=78;data[4]=98;data[5]=11; data[6]=0;data[7]=49;data[8]=58;data[9]=29;data[10]=127;data[11]=105; data[12]=116;data[13]=44;data[14]=69;data[15]=39; data[16]=22;data[17]=83;data[18]=88;data[19]=78;data[20]=98;data[21]=11; data[22]=0;data[23]=49;data[24]=58;data[25]=29;data[26]=127;data[27]=105; data[28]=116;data[29]=44;data[30]=69;data[31]=39; data[32]=22;data[33]=83;data[34]=88;data[35]=78;data[36]=98;data[37]=11; data[38]=0;data[39]=49;data[40]=58;data[41]=29;data[42]=127;data[43]=105; data[44]=116;data[45]=44;data[46]=69;data[47]=39; data[48]=22;data[49]=83;data[50]=88;data[51]=78;data[52]=98;data[53]=11; data[54]=0;data[55]=49;data[56]=58;data[57]=29;data[58]=127;data[59]=105; data[60]=116;data[61]=44;data[62]=69;data[63]=39; outp(0x301,0); starter:_clearscreen(_GCLEARSCREEN); printf("\n\n SIMULATION OF A NOISY CHANNEL USING HAMMING DISTANCE\n"); printf(" PCM encoded bit-stream with amplitude of %i Volt\n",pcmam); printf(" SINGLE ERROR CORRECTION\n\n"); i0=&i; i1=i0+1; /* Set high and low bytes!!! */ p0=&pos; p1=p0+1; n0=&neg; n1=n0+1; printf (" %ld words being transmitted.\n\n Please wait...\n",numrec+128); printf (" \n"); /* border around directions */ _setcolor (3); _rectangle (_GBORDER, 0,0,600,180); _rectangle (_GFILLINTERIOR, 600,20,620,200); _rectangle (_GFILLINTERIOR, 20,180,620,200); /* now read data */ smallrec = (int)(numrec/64 + 2); /* 50000/64 */ for (j=0;j0) g=1; /* Checking bit, by bit */ else g=0; if (b!=g) {errct++;bitct++;} } /* Now let's see what type of errors we're dealing with!!! */ switch (errct) { case 0:err[0]++; break; case 1:err[1]++; break; case 2:err[2]++; break; default:err[3]++; break; } } if (kbhit())goto done; _settextposition(8,8); printf ("count=%ld",count); /* Display status to monitor */ } done: _settextposition (15,1); printf ("\n\n RESULTS: \n"); printf (" Words transmitted: %ld\n",count); printf (" # of bit errors: %ld\n",bitct); printf (" # of single-bit word errors -- CORRECTABLE: %ld\n",err[1]); printf (" # of double-bit word errors -- UNCORRECTABLE: %ld\n",err[2]); printf (" # of 3/more-bit word errors -- UNDETECTABLE: %ld\n",err[3]); /* Another fancy border... */ _setcolor (3); _rectangle (_GBORDER, 0,220,500,320); _rectangle (_GFILLINTERIOR, 500,230,510,330); _rectangle (_GFILLINTERIOR, 20,320,510,330); looper: while(!kbhit()); c_ham1=getch(); if ((c_ham1!='q')&&(c_ham1!='Q')) goto looper; } void ham2(void) { int errct; int data[64],smallrec; int sl,i,bcount,gcount,b,g,j,norm; int pos,neg,c_ham2; long int lp,count=0,err[4],bitct=0; unsigned char *i1,*i0,*p0,*p1,*n0,*n1; int delay,dcnt; float xdel; pos = (int) (204.7 * pcmam); neg = pos * (-1); /* Initialize delay based on pulse amplitude */ delay=(int)4.*(5.+log(pcmam)); xdel=0.; /* Initialize the error counter */ for (lp=0;lp<4;lp++) err[lp]=0; /* Pseudo random number generator!!! */ data[0]=22;data[1]=83;data[2]=88;data[3]=78;data[4]=98;data[5]=11; data[6]=0;data[7]=49;data[8]=58;data[9]=29;data[10]=127;data[11]=105; data[12]=116;data[13]=44;data[14]=69;data[15]=39; data[16]=22;data[17]=83;data[18]=88;data[19]=78;data[20]=98;data[21]=11; data[22]=0;data[23]=49;data[24]=58;data[25]=29;data[26]=127;data[27]=105; data[28]=116;data[29]=44;data[30]=69;data[31]=39; data[32]=22;data[33]=83;data[34]=88;data[35]=78;data[36]=98;data[37]=11; data[38]=0;data[39]=49;data[40]=58;data[41]=29;data[42]=127;data[43]=105; data[44]=116;data[45]=44;data[46]=69;data[47]=39; data[48]=22;data[49]=83;data[50]=88;data[51]=78;data[52]=98;data[53]=11; data[54]=0;data[55]=49;data[56]=58;data[57]=29;data[58]=127;data[59]=105; data[60]=116;data[61]=44;data[62]=69;data[63]=39; outp(0x301,0); starter:_clearscreen(_GCLEARSCREEN); printf("\n\n SIMULATION OF A NOISY CHANNEL USING HAMMING DISTANCE\n"); printf(" SINGLE AND DOUBLE ERROR DETECTION\n"); printf(" PCM encoded bit-stream with amplitude of %i Volt\n\n",pcmam); i0=&i; i1=i0+1; /* Set the High and Low bytes for A/D board */ p0=&pos; p1=p0+1; n0=&neg; n1=n0+1; printf (" %ld words being transmitted.\n\n Please wait...\n",numrec+128); printf (" Hit any key to end the simulation.\n"); /* Fancy border */ _setcolor (3); _rectangle (_GBORDER, 0,0,600,180); _rectangle (_GFILLINTERIOR, 600,20,620,200); _rectangle (_GFILLINTERIOR, 20,180,620,200); /* now read data */ smallrec = (int) (numrec/64 + 2); /* Cycle through 50000/64 times */ for (j=0;j0) g=1; /* Checking bit, by bit */ else g=0; if (b!=g){errct++;bitct++;} } /* Now let's see what type of errors we're dealing with!!! */ switch (errct) { case 0:err[0]++; break; case 1:err[1]++; break; case 2:err[2]++; break; default:err[3]++; break; } } if (kbhit())goto done; _settextposition(8,8); printf ("count=%ld",count); /* Display status to monitor */ } done: _settextposition(15,1); printf ("\n\n RESULTS: \n"); printf (" Words transmitted: %ld\n",count); printf (" # of bit errors: %ld\n",bitct); printf (" # of single-bit word errors -- DETECTABLE: %ld\n",err[1]); printf (" # of double-bit word errors -- DETECTABLE: %ld\n",err[2]); printf (" # of 3/more-bit word errors -- UNDETECTABLE: %ld\n",err[3]); /* Border */ _setcolor (3); _rectangle (_GBORDER, 0,220,500,320); _rectangle (_GFILLINTERIOR, 500,230,510,330); _rectangle (_GFILLINTERIOR, 20,320,510,330); looper: while(!kbhit()); c_ham2=getch(); if ((c_ham2!='q')&&(c_ham2!='Q')) goto looper; } void oddp(void) { int data[128],errct; int sl,smallrec,i,bcount,gcount,b,g,j,norm; int pos,neg,c_oddp; long int lp,count=0,err[4],bitct=0; unsigned char *i1,*i0,*p0,*p1,*n0,*n1; int delay,dcnt; float xdel; pos = (int) (204.7 * pcmam); neg = pos * (-1); /* Initialize delay based on pulse amplitude */ delay=(int)4.*(5.+log(pcmam)); xdel=0.; /* Initialize the error counter */ for (lp=0;lp<4;lp++) err[lp]=0; /* Pseudo Random Number Generator!!! */ data[0]=257;data[1]=90;data[2]=335;data[3]=355;data[4]=311;data[5]=28; data[6]=84;data[7]=18;data[8]=26;data[9]=46;data[10]=349;data[11]=126; data[12]=373;data[13]=383;data[14]=86;data[15]=367;data[16]=293;data[17]=60; data[18]=66;data[19]=16;data[20]=351;data[21]=259;data[22]=381;data[23]=343; data[24]=313;data[25]=289;data[26]=108;data[27]=62;data[28]=329;data[29]=112; data[30]=14;data[31]=34;data[32]=10;data[33]=82;data[34]=375;data[35]=92; data[36]=283;data[37]=38;data[38]=50;data[39]=303;data[40]=285;data[41]=275; data[42]=114;data[43]=323;data[44]=32;data[45]=88;data[46]=74;data[47]=122; data[48]=76;data[49]=317;data[50]=124;data[51]=281;data[52]=94;data[53]=8; data[54]=64;data[55]=361;data[56]=58;data[57]=299;data[58]=353;data[59]=307; data[60]=0;data[61]=48;data[62]=345;data[63]=271;data[64]=267;data[65]=301; data[66]=56;data[67]=309;data[68]=377;data[69]=261;data[70]=100;data[71]=2; data[72]=40;data[73]=106;data[74]=20;data[75]=333;data[76]=297;data[77]=52; data[78]=327;data[79]=263;data[80]=287;data[81]=102;data[82]=98;data[83]=291; data[84]=331;data[85]=325;data[86]=70;data[87]=4;data[88]=36;data[89]=24; data[90]=96;data[91]=365;data[92]=315;data[93]=341;data[94]=379;data[95]=371; data[96]=265;data[97]=369;data[98]=277;data[99]=80;data[100]=337;data[101]=54; data[102]=68;data[103]=44;data[104]=22;data[105]=6;data[106]=116;data[107]=321; data[108]=359;data[109]=319;data[110]=78;data[111]=269;data[112]=363; data[113]=104;data[114]=118;data[115]=30;data[116]=305;data[117]=357;data[118]=273; data[119]=72;data[120]=110;data[121]=120;data[122]=12;data[123]=339;data[124]=347; data[125]=295;data[126]=42;data[127]=279; outp(0x301,0); starter:_clearscreen(_GCLEARSCREEN); printf("\n\n SIMULATION OF A NOISY CHANNEL USING ODD PARITY\n"); printf(" PCM encoded bit-stream with amplitude of %i Volt\n\n\n",pcmam); _settextposition (6,5); i0=&i; i1=i0+1; /* set the high and low bytes for A/D board */ p0=&pos; p1=p0+1; n0=&neg; n1=n0+1; printf (" %ld words being transmitted.\n\n Please wait...\n",numrec+128); printf (" Hit any key to end the simulation.\n"); /* border for the directions */ _setcolor (3); _rectangle (_GBORDER, 0,0,600,180); _rectangle (_GFILLINTERIOR, 600,20,620,200); _rectangle (_GFILLINTERIOR, 20,180,620,200); /* now read data */ smallrec = (int)(numrec/128 + 1); /* Cycle through 50000/128 times */ for (j=0;j0) g=1; /* Checking bit, by bit */ else g=0; if (b!=g) {errct++;bitct++;} } /* Now let's see what type of errors we're dealing with!!! */ switch (errct) { case 0:break; case 1:err[1]++; break; case 2:err[2]++; break; default:err[3]++; break; } } if (kbhit())goto done; _settextposition(7,8); printf ("count=%ld",count); /* Display status to monitor */ } done: _settextposition(15,1); printf ("\n\n RESULTS: \n"); printf (" Words transmitted: %ld\n",count); printf (" # of bit errors: %ld\n",bitct); printf (" # of single-bit word errors -- DETECTABLE: %ld\n",err[1]); printf (" # of double-bit word errors -- UNDETECTABLE: %ld\n",err[2]); printf (" # of 3/more-bit word errors -- UNDETECTABLE: %ld\n",err[3]); /* Border!!! */ _setcolor (3); _rectangle (_GBORDER, 0,220,500,320); _rectangle (_GFILLINTERIOR, 500,230,510,330); _rectangle (_GFILLINTERIOR, 20,320,510,330); looper: while(!kbhit()); c_oddp=getch(); if ((c_oddp!='q')&&(c_oddp!='Q')) goto looper; } void ask(void) { /* This subroutine simply allows the user to input an amplitude for the PCM-encoded bitstream for section 3: Transmission of Coded Signals */ int loop,ch,temp; char token; starter:_clearscreen(_GCLEARSCREEN); _settextposition(6,0); printf(" Please enter a voltage amplitude \n"); printf(" for the PCM-encoded bitstream\n\n"); printf(" A value from 0-10V: "); _setcolor (2); _rectangle (_GBORDER, 80,40,480,260); /* Draw the border */ _rectangle (_GFILLINTERIOR, 480,50,500,260); /* Draw backdrop */ _rectangle (_GFILLINTERIOR, 90,260,500,270); scanf ("%s",token); sscanf (token, "%d", &temp); if ((temp<0)||(temp>10)) { warn(); goto starter; } pcmam=temp; _settextposition (14,15); printf ("PCM amplitude is set to: %i V",pcmam); _settextposition (15,15); printf ("Hit 'q' to continue"); /* Wait for the user to hit 'q' to go back to the original screen */ stall: while (!kbhit()); ch=getch(); if ((ch!='q')&&(ch!='Q')) goto stall; free (token); } void warn(void) { /* This is a general warning routine that provides a dialoge box when the user has entered an invalid value */ int loop,ch; _clearscreen(_GCLEARSCREEN); _settextposition(6,0); printf(" YOU HAVE ENTERED AN INVALID VALUE!!!\n\n\n"); printf(" Hit 'q' to continue.\n"); /* Border ! */ _setcolor (2); _rectangle (_GBORDER, 80,40,480,160); /* Draw the border */ _rectangle (_GFILLINTERIOR, 480,50,500,160); /* Draw backdrop */ _rectangle (_GFILLINTERIOR, 90,160,500,170); /* Wait for the user to hit 'q' to go back to the original screen */ stall: while (!kbhit()); ch=getch(); if ((ch!='q')&&(ch!='Q')) goto stall; }