标题:
51单片机实现MAX517芯片的D/A转换 程序+电路图。按一次KO键,数字量加一
[打印本页]
作者:
hongniu
时间:
2015-6-24 01:13
标题:
51单片机实现MAX517芯片的D/A转换 程序+电路图。按一次KO键,数字量加一
/*****************************************************************************/
/*功能:实现MAX517芯片的D/A转换。没按一次KO键,数字量加一,******************/
/*显示的模拟量增加一个单位*/
/****************************************************************************/
#include <reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit SCL=P1^0;
sbit SDA=P1^1;
sbit K0=P2^0;
void start(void)
{
SDA=1;
SCL=1;
_nop_();
SDA=0;
_nop_();
}
void stop(void)
{
SDA=0;
SCL=1;
_nop_();
SDA=1;
_nop_();
}
void ack(void)
{
SDA=0;
_nop_();
SCL=1;
_nop_();
SCL=0;
}
void send(uchar ch)
{
uchar BitCountter =8;
uchar tmp;
do
{
tmp=ch;
SCL=0;
_nop_();
if((tmp&0x80)==0x80)
SDA=1;
else
SDA=0;
SCL=1;
tmp=ch<<1;
ch=tmp;
BitCountter--;
}
while(BitCountter);
SCL=0;
}
void DACout(uchar ch)
{
start();
send(0x58);
ack();
send(0x00);
ack();
send(ch);
ack();//
stop();
}
void main(void)
{
uchar i;
i=0xff;
while(1)
{
if(!K0)
{
i++;
while(!K0);
}
DACout(i);
}
}
复制代码
psb.png
(8.5 KB, 下载次数: 72)
下载附件
2015-6-24 01:13 上传
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1