单片机AD-DA转换

单片机AD-DA转换
#include 
#include "../iic/iic.h"

unsigned char AD_read()
{
    unsigned char temp;

    iic_start();
	
	iic_send_byte(0x90);
	if(0 == ack)
	{
	    return ERR;
	}
	
	iic_send_byte(0x40);    //设置通道和工作方式
	if(0 == ack)
	{
	    return ERR;
	}
	
	iic_start();
	iic_send_byte(0x90 + 1);
	if(0 == ack)
	{
	    return ERR;
	}
	
	temp = iic_receive_byte();
	iic_noack();
	iic_stop();
	
	return temp;
}

unsigned char DA_write(unsigned char num)
{
    iic_start();
	
	iic_send_byte(0x90);
	if(0 == ack)
	{
	    return ERR;
	}
	
	iic_send_byte(0x40);
	if(0 == ack)
	{
	    return ERR;
	}
	
	iic_send_byte(num);
	if(0 == ack)
	{
	    return ERR;
	}
	
	iic_stop();
	
	return SUCC;
}

你可能感兴趣的:(单片机)