di3080.txt ;************************************************************************************************ ; ; LISTING 1 - C PROGRAM FOR PC-CONFIGURABLE FILTER ; ; "PC-based configurable filter uses no digital potentiometers," EDN, January 23, 2003, pg 76 ; ;************************************************************************************************ #include #include #include #include #define LPT 0x378 /* Data Port Address */ #define CONT 0x37A /* Control Port Address */ #define ESC 27 typedef unsigned char u08; enum boolean {false,true}; /* Funtion Declarations */ void Chip_Program(u08); /* To set the analog switches */ void showbits(u08); /* To see bit pattern */ void DrLine(void); /* Draw a Line */ void init(void); /* Initializes the Parallel Port */ void main() { int fch,ctr,qch; u08 pdat,tdat; float freq,qlty; init(); do{ clrscr(); printf("RECONFIGURABLE UNIVERSAL FILTER By Saurav Gupta & Tejinder Singh\n"); DrLine(); printf(" Select Frequency(in Hz/sec)\n"); DrLine(); printf("\t(1) 159 \t(6) 8110.0\n"); printf("\t(2) 1591.5\t(7) 30.68 K\n"); printf("\t(3) 1750.7\t(8) 32.20 K\n"); printf("\t(4) 6366.0\t(9) 37.00 K\n"); printf("\t(5) 7957.0\t(10) 38.70 K\n"); DrLine(); printf("Your Choice :"); scanf("%d",&fch); }while(fch<1 || fch>10); /* Loop until a valid choice is entered*/ switch(fch) { case 1 : freq=159; pdat=0x08; break; case 2 : freq=1591.5; pdat=0x04; break; case 3 : freq=1750.7; pdat=0x0C; break; case 4 : freq=6366; pdat=0x02; break; case 5 : freq=7957; pdat=0x06; break; case 6 : freq=8110; pdat=0x0E; break; case 7 : freq=30680; pdat=0x01; break; case 8 : freq=32200; pdat=0x05; break; case 9 : freq=37000; pdat=0x03; break; case 10: freq=38000; pdat=0x0F; break; } do{ clrscr(); printf("Filter with Reconfigurable Characteristics\n"); DrLine(); printf(" Select Q (The Quality Factor)\n"); DrLine(); printf("\t(1) 2.24\t(9) 4.70\n"); printf("\t(2) 2.50\t(10) 5.36\n"); printf("\t(3) 2.35\t(11) 6.00\n"); printf("\t(4) 2.65\t(12) 6.38\n"); printf("\t(5) 2.90\t(13) 7.72\n"); printf("\t(6) 3.12\t(14) 11.01\n"); printf("\t(7) 3.40\t(15) 33.72\n"); printf("\t(8) 3.72\n"); DrLine(); printf("Your Choice :"); scanf("%d",&qch); }while(qch<1 || qch>15); switch(qch) { case 1 : qlty=2.24; tdat=0xF0; break; case 2 : qlty=2.50; tdat=0xB0; break; case 3 : qlty=2.35; tdat=0x70; break; case 4 : qlty=2.65; tdat=0x30; break; case 5 : qlty=2.90; tdat=0xD0; break; case 6 : qlty=3.12; tdat=0x50; break; case 7 : qlty=3.40; tdat=0x90; break; case 8 : qlty=3.72; tdat=0x10; break; case 9 : qlty=4.70; tdat=0xE0; break; case 10: qlty=5.36; tdat=0x60; break; case 11: qlty=6.00; tdat=0x40; break; case 12: qlty=6.38; tdat=0xA0; break; case 13: qlty=7.72; tdat=0x20; break; case 14: qlty=11.01; tdat=0xC0; break; case 15: qlty=33.72; tdat=0x80; break; } pdat=pdat|tdat; printf("\nYou Have Selected the Filter with\n"); printf("Frequency : %6.2f Hz/sec\nQuality Factor : %3.2f\n",freq,qlty); printf("Bit Pattern : "); showbits(pdat); printf("\n"); DrLine(); printf("\nPress \nEnter : To Set the Switches\nEsc : To Exit"); if(getch()==ESC) exit(0); Chip_Program(pdat); printf("\n"); DrLine(); printf("Chip Programmed Successfully!!\nPress any key to exit"); getch(); } void DrLine(void) { int ctr; for(ctr=0;ctr<50;ctr++) printf("%c",205); printf("\n"); } void init(void) { outport(CONT,0xFF); delay(100); outport(LPT,0x00); delay(100); } void Chip_Program(u08 pdat) { outport(CONT,0x00); delay(200); outport(LPT,pdat); delay(200); outport(CONT,0xFF); delay(200); } void showbits(u08 num) { int i,k,mask; printf("%x (Hex),\t\t",num); for(i=7;i>=0;i--) { if(i==3 || i==7 || i==11) printf(" "); mask=0x0001<