//注意:调试时 应该把 Vref 和 Vout 连接到一起
#i nclude " reg51.h "
sbit MAX532_CS=P1^0;
sbit MAX532_DIN=P1^1;
sbit MAX532_SCLK=P1^2;
void MAX532_OUT(unsigned char daout1,unsigned char daout2,unsigned char daout3);
void delay()
{
unsigned int i,j;
for(i=0;i<1000;i++)
for(j=100;j>0;j--)
;
}
void main(void)
{
while(1)
{
MAX532_OUT(0x80,0x08,0x00); // 二分之一的Vref
MAX532_OUT(0x80,0x08,0x00); // 二分之一的Vref
MAX532_OUT(0x80,0x08,0x00); // 二分之一的Vref
}
}
// 为了保证 DA 输出速度 采用直接送数据的方法
void MAX532_OUT(unsigned char daout1,unsigned char daout2,unsigned char daout3)
{
//MAX532_CS=1;
//MAX532_DIN=1;
//MAX532_SCLK=1;
MAX532_CS=0;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout1&0x80);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout1&0x40);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout1&0x20);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout1&0x10);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout1&0x08);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout1&0x04);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout1&0x02);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout1&0x01);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout2&0x80);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout2&0x40);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout2&0x20);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout2&0x10);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout2&0x08);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout2&0x04);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout2&0x02);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout2&0x01);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout3&0x80);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout3&0x40);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout3&0x20);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout3&0x10);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout3&0x08);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout3&0x04);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout3&0x02);
MAX532_SCLK=1;
MAX532_SCLK=0;
MAX532_DIN=(bit)(daout3&0x01);
MAX532_SCLK=1;
MAX532_CS=1;
}
上一篇:DS12887(时钟日历芯片) c语言驱动程序
下一篇:X25045驱动程序
推荐阅读最新更新时间:2024-03-16 15:18