用打印機(jī)端口做可編程頻率發(fā)生器電路

2013-10-29 14:28:00
  • 相關(guān)元件pdf下載:max5130 op07 ad537 #include#include#include#include#include#define clk1 0x04 /* clock pulse high*/#define clk

相關(guān)元件pdf下載:max5130 op07 ad537 #include#include#include#include#include#define clk1 0x04 /* clock pulse high*/#define clk0 0xfb /* clock pulse low*/#define cs1 0x01 /* chip high to deactivate dac*/#define cs0 0xfe /* chip low to activate dac*/#define data1 0x02 /* data pulse high*/#define data0 0xfd /* data pulse low*/int c[16],dpt,actualdata,out,k; /*global declarations*/float vout;/*dac output*/void d2b(unsigned int x, int*c)/*routine f decimal to binary conversion*/{int i;f(i=0;i>i) & 0x1;}float ftov() /*hertz to dac output conversion routine*/{int hertz;printf("\n \nenter the frequency within 0 to 10000hz:");scanf("%d",&hertz);vout=0.00040955*hertz;printf("\n vout=%f\n",vout);return vout;}void clock_dac(void)/*routine f clocking the dac*/{out|=clk1;outptb(dpt,out);/*setting the clock high*/delay(1);out&=clk0;outptb(dpt,out);/*setting the clock low*/delay(1);}void load_dacdata(int*c)/*routine f loading actual data into the dac*/{out|=cs1;outptb(dpt,out);/*chip high to disable dac*/delay(1);out&=cs0;outptb(dpt,out);/*chip low to enable dac*/delay(1);printf("\ndata loaded into the dac=");f(k=15;k>=0;k--){out|=c[k];outptb(dpt,out);printf("%d",c[k]);delay(1);clock_dac();}out|=cs1;outptb(dpt,out);delay(1);}main(){int v,inc;float y;unsigned int x;double fraction, integer, number;clrscr();printf("\tuse your printer pt as a programmable frequency generat");printf("\n\t\t\t by\n");printf("\tk.suresh,msd,igcar,kalpakkam,tamilnadu-603102,india");dpt= peek(0x40,8);/*check up f availability of printer pt*/if (dpt==0){printf("\n\n lpt not aviailable! exiting........");exit(1);}printf("\n\naddress of the printer pt found =0x%x",dpt);ftov();y=(vout*8192)/(2.5*1.6384);v=y/1;number=y;fraction = modf(number, &integer);if (fraction<0.44)inc=0;else inc=1;actualdata=16384+v+inc; /*actual data including the control wd f dac*/d2b(actualdata,c);load_dacdata(c);return 0;}