微控制器AD-DA轉換

Aikenlan發表於2016-09-18
微控制器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;
}

相關文章