用打印機(jī)端口做可編程頻率發(fā)生器電路
出處:sunkingyan 發(fā)布于:2008-07-05 00:00:00 | 1843 次閱讀
#include<stdio.h>#include<conio.h>
#include<math.h>
#include<bios.h>
#include<dos.h>
#define CLK1 0x04 /* Clock Pulse High*/
#define CLK0 0xfb /* Clock Pulse Low*/
#define CS1 0x01 /* Chip Select high to deacTIvate DAC*/
#define CS0 0xfe /* Chip Select low to activate DAC*/
#define DATA1 0x02 /* Data Pulse High*/
#define DATA0 0xfd /* Data Pulse low*/
int c[16],dport,ACTUALDATA,out,k; /*Global Declarations*/
float VOUT;/*DAC OUTPUT*/
void d2b(unsigned int x, int*c)/*Routine for Decimal to Binary Conversion*/
{
int i;
for(i=0;i<=15;i++)
*(c++)=(x>>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 for clocking the DAC*/
{
out|=CLK1;
outportb(dport,out);/*Setting the clock high*/
delay(1);
out&=CLK0;
outportb(dport,out);/*Setting the clock low*/
delay(1);
}
void LOAD_DACDATA(int*c)/*Routine for loading actual data into the DAC*/
{
out|=CS1;
outportb(dport,out);/*Chip Select high to disable DAC*/
delay(1);
out&=CS0;
outportb(dport,out);/*Chip Select low to enable DAC*/
delay(1);
printf("\nDATA loaded into the DAC=");
for(k=15;k>=0;k--)
{
out|=c[k];
outportb(dport,out);
printf("%d",c[k]);
delay(1);
CLOCK_DAC();
}
out|=CS1;
outportb(dport,out);
delay(1);
}
main()
{
int v,inc;
float y;
unsigned int x;
double fraction, integer, number;
clrscr();
printf("\tUse Your Printer Port as a Programmable Frequency Generator");
printf("\n\t\t\t by\n");
printf("\tK.Suresh,MSD,IGCAR,Kalpakkam,TamilNadu-603102,India");
dport= peek(0x40,8);/*Check up for availability of Printer Port*/
if (dport==0)
{
printf("\n\n LPT NOT AVIAILABLE! EXITING........");
exit(1);
}
printf("\n\nAddress of the printer port found =0x%X",dport);
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 Word for DAC*/
d2b(ACTUALDATA,c);
LOAD_DACDATA(c);
return 0;
}
版權(quán)與免責(zé)聲明
凡本網(wǎng)注明“出處:維庫電子市場網(wǎng)”的所有作品,版權(quán)均屬于維庫電子市場網(wǎng),轉(zhuǎn)載請(qǐng)必須注明維庫電子市場網(wǎng),http://www.hbjingang.com,違反者本網(wǎng)將追究相關(guān)法律責(zé)任。
本網(wǎng)轉(zhuǎn)載并注明自其它出處的作品,目的在于傳遞更多信息,并不代表本網(wǎng)贊同其觀點(diǎn)或證實(shí)其內(nèi)容的真實(shí)性,不承擔(dān)此類作品侵權(quán)行為的直接責(zé)任及連帶責(zé)任。其他媒體、網(wǎng)站或個(gè)人從本網(wǎng)轉(zhuǎn)載時(shí),必須保留本網(wǎng)注明的作品出處,并自負(fù)版權(quán)等法律責(zé)任。
如涉及作品內(nèi)容、版權(quán)等問題,請(qǐng)?jiān)谧髌钒l(fā)表之日起一周內(nèi)與本網(wǎng)聯(lián)系,否則視為放棄相關(guān)權(quán)利。
- LM317:高效構(gòu)建電壓源及電流源電路方案1
- 如何使用多相轉(zhuǎn)換器平衡電流2
- LTC4365 如何實(shí)現(xiàn)敏感電路過壓與反接保護(hù)3
- MOS 管邏輯電路五種門電路特性4
- 點(diǎn)動(dòng)正轉(zhuǎn)控制電路簡介5
- 單鍵開關(guān)機(jī)電路與輕觸開關(guān)的創(chuàng)新設(shè)計(jì)解析6
- 二極管的恒壓降模型7
- MC34063電路計(jì)算公式及應(yīng)用講解8
- 3.3V - 1.8V 電平雙向轉(zhuǎn)換:多場景配置及獨(dú)特優(yōu)勢(shì)剖析9
- 液晶電視機(jī)電路結(jié)構(gòu)的關(guān)鍵要點(diǎn)10














