⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 新建 文本文档 (3).txt

📁 低功耗、四路、12位、电压输出DAC
💻 TXT
字号:
#define SET_MAX525_CS PORTB|=0x10
#define CLR_MAX525_CS PORTB&=~0x10

void spi_init(void)
{
//spi初始化
DDRB=0xbf;
PORTB=0x0F;
SPCR = 0x53;
SPSR = 0x00;
}


//使用SPI发送一个字节
void spi_write(uchar sData)
{
SPDR = sData;
while(!(SPSR & BIT(SPIF)));
//sData=SPDR;//读从机发回来的数据
}

void max525_write(unsigned int A,unsigned int B,unsigned int C,unsigned int D)
{

unsigned char i,tempAH,tempAL,tempBH,tempBL,tempCH,tempCL,tempDH,tempDL;
unsigned int mytemp1,mytemp2;
CLI();
mytemp1=A&0x0fff;
mytemp2=A;
tempAH=(mytemp1&0xff00)>>8;
tempAL=(mytemp2&0x00ff);
mytemp1=B&0x0fff;
mytemp2=B;
tempBH=(mytemp1&0xff00)>>8;
tempBL=(mytemp2&0x00ff);
mytemp1=A&0x0fff;
mytemp2=A;
tempCH=(mytemp1&0xff00)>>8;
tempCL=(mytemp2&0x00ff);
mytemp1=D&0x0fff;
mytemp2=D;
tempDH=(mytemp1&0xff00)>>8;
tempDL=(mytemp2&0x00ff);



CLR_MAX525_CS;
delay_nus(20);

spi_write(tempAH+0x30);
spi_write(tempAL);
SET_MAX525_CS;
delay_nus(20);
CLR_MAX525_CS;
delay_nus(20);

spi_write(tempBH+0x70);
spi_write(tempBL);
SET_MAX525_CS;
delay_nus(20);
CLR_MAX525_CS;
delay_nus(20);

spi_write(tempCH+0xB0);
spi_write(tempCL);
SET_MAX525_CS;
delay_nus(20);
CLR_MAX525_CS;
delay_nus(20);

spi_write(tempDH+0xF0);
spi_write(tempDL);
SET_MAX525_CS;
delay_nus(20);

SEI();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -