电子工程师的网站
首 页 | 新闻资讯 | 最新产品 | 解决方案 | 技术参数 | 设计应用
电路图
技术资料 | 芯片资料 | 技术论坛
现在位置: 首页 > 电路图 > 微机单片机 > 单片机制作 > 详细信息
用打印机端口做可编程频率发生器电路
来源:   时间: 2007-10-15 9:29:17    

相关元件PDF下载:


MAX5130   OP07   AD537   

#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;
}

相关信息
发表评论
打印本页 关闭本页
已有(
)位对此新闻感兴趣的网发发表了看法 >>更多评论
内 容:
     
关于我们 | 服务项目 | 付款方式 | 广告服务 | 联系我们 | 友情链接 | 投诉 建议 合作 | 网站地图 | 加入收藏
Copyright © 2007-2008 WEEQOO.COM Corp.All Rights Reserved. 版权所有 经营许可证编号:浙B2-20050339 法律声明
维库电子旗下网站:维库电子市场网 | ChinaICMart | 维库电子开发网 | 维库电子人才网
总部:杭州市下城区朝晖路182号国都发展大厦1号楼80A
电话:0571-85889139-8007 QQ:303939539 | MSN:zh1226@hotmail.com |  邮箱:laz8258@163.com dzsc51@163.com