標(biāo)題:
實(shí)現(xiàn)MAX517芯片的D/A轉(zhuǎn)換程序。按一次KO鍵,數(shù)字量加一
[打印本頁]
作者:
benbens
時(shí)間:
2015-7-14 19:49
標(biāo)題:
實(shí)現(xiàn)MAX517芯片的D/A轉(zhuǎn)換程序。按一次KO鍵,數(shù)字量加一
00000000.png
(15.84 KB, 下載次數(shù): 105)
下載附件
2015-7-14 19:49 上傳
/*****************************************************************************/
/*功能:實(shí)現(xiàn)MAX517芯片的D/A轉(zhuǎn)換。沒按一次KO鍵,數(shù)字量加一,******************/
/*顯示的模擬量增加一個(gè)單位*/
/****************************************************************************/
#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);
}
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1