ds1868(數(shù)字電位器) c 驅(qū)動(dòng)程序
****************DS1868 數(shù)字字電位器調(diào)試******************/
//注意:ds1868的管腳 調(diào)試是我用P2口的 5、6、7 腳 發(fā)現(xiàn)不好用
//另外線性效果也不是很理想,但是能夠滿足一般的要求了
#i nclude " reg51.h "
#i nclude " absacc.h "
#define LSB 0x01
#define HIGH 1
#define LOW 0
#define BUZZER_OFF BUZZER=1
sbit DS1868_RST=P3^5; //pin 5
sbit DS1868_CLK=P3^6; //pin 6
sbit DS1868_DQ =P3^7; //pin 8
sbit BUZZER=P0^4;
void DS1868_communication(unsigned char potentiometer_1,unsigned char potentiometer_0);
void main(void)
{
BUZZER_OFF;
while(1)
{
DS1868_communication(0x55,0x55);
}
}
void DS1868_communication(unsigned char potentiometer_1,unsigned char potentiometer_0)
{
unsigned char i;
bit stack=1;
DS1868_RST=HIGH;
DS1868_DQ = stack;
DS1868_CLK=HIGH;
DS1868_CLK=LOW;
for(i=0;i<8;i++)
{
DS1868_DQ=(bit)(potentiometer_1&LSB);
DS1868_CLK=HIGH;
DS1868_CLK=LOW;
potentiometer_1>>=1;
}
for(i=0;i<8;i++)
{
DS1868_DQ=(bit)(potentiometer_0&LSB);
DS1868_CLK=HIGH;
DS1868_CLK=LOW;
potentiometer_0>>=1;
}
DS1868_RST=LOW;
}