[code=C/C++][/code]
/*程序功能:利用TLC5615的DA转换功能,输出一个5V直流电压
#include <reg51.h>
#include <intrins.h>
sfr P4 = 0xC0;
sbit DIN = P4^6;
sbit SCLK =P4^5;
sbit CS = P4^4;
sfr P4SW = 0xBB;
void delay(unsigned char z)
{
unsigned char i,j;
for (i = 0; i<z; i++)
for (j = 0; j<100; j++);
}
void TLC_5615(unsigned int da)
{
unsigned char i ;
CS = 1 ;
SCLK =0 ;
CS = 0 ;
da=da&0x03ff;
for(i=0;i<12;i++)
{
if((bit)(da&0x0200)==1)
DIN = 1;
else
DIN = 0;
SCLK = 1;
da<<=1;
SCLK = 0;
}
SCLK = 0;
CS = 1;
_nop_();
_nop_();
}
void main ()
{
unsigned char i;
P4SW = 0X70; //调用正弦函数并产生码表
while(1)
{
TLC_5615(0x03ff);
delay(1);
}
}
[code=C/C++][/code]
------解决方案--------------------
- C/C++ code
/*程序功能:利用TLC5615的DA转换功能,输出一个5V直流电压#include <reg51.h>#include <intrins.h>sfr P4 = 0xC0;sbit DIN = P4^6;sbit SCLK =P4^5;sbit CS = P4^4;sfr P4SW = 0xBB;void delay(unsigned char z){unsigned char i,j;for (i = 0; i<z; i++)for (j = 0; j<100; j++);}void TLC_5615(unsigned int da){unsigned char i ;CS = 1 ;SCLK =0 ;CS = 0 ;da=da&0x03ff;for(i=0;i<12;i++){if((bit)(da&0x0200)==1)DIN = 1;elseDIN = 0;SCLK = 1;da<<=1;SCLK = 0;}SCLK = 0;CS = 1;_nop_();_nop_();}void main (){ unsigned char i;P4SW = 0X70; //调用正弦函数并产生码表while(1){TLC_5615(0x03ff);delay(1);}}