#include "msp430x14x.h"
#define SCLK_OUT P3DIR|=BIT0;
#define DIN_OUT P3DIR|=BIT1;
#define CS_OUT P3DIR|=BIT2;
#define FS_OUT P3DIR|=BIT3;
#define SCLK_H P3OUT|=BIT0;
#define SCLK_L P3OUT&=~BIT0;
#define DIN_H P3OUT|=BIT1;
#define DIN_L P3OUT&=~BIT1;
#define CS_H P3OUT|=BIT2;
#define CS_L P3OUT&=~BIT2;
#define FS_H P3OUT|=BIT3;
#define FS_L P3OUT&=~BIT3;
void delay(void);
void WRITE1byte(unsigned int data);
void WRITE0(void);
void WRITE1(void);
void SPI_STOP(void);
void SPI_START(void);
void IO(void);
int main( void )
{
P1DIR = 0XFF;P1OUT = 0XFF;
P2DIR = 0XFF;P2OUT = 0XFF;
P3DIR = 0XFF;P3OUT = 0XFF;
P4DIR = 0XFF;P4OUT = 0XFF;
P5DIR = 0XFF;P5OUT = 0XFF;
P6DIR = 0XFF;P6OUT = 0XFF;
//unsigned int i;
// Stop watchdog
timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
/*
BCSCTL1&=~XT2OFF;//打开时钟震荡
do
{
IFG1&=~OFIFG;
for(i=0xff;i>0;i--);
}
while((IFG1&OFIFG)!=0);
BCSCTL2=SELM_2;
*/
IO();
SPI_START();
WRITE1byte(0x4fff);
//SPI_STOP();
for(;;)
{
}
}
void IO(void)//io设置
{
SCLK_OUT;
DIN_OUT;
CS_OUT;
FS_OUT;
}
void SPI_START(void)//开启
{
CS_H;
FS_H;
delay();
CS_L;
delay();
FS_L;
delay();
}
void SPI_STOP(void)//停止
{
CS_L;
FS_L;
delay();
FS_H;
delay();
CS_H;
delay();
}
void WRITE1(void)//写入1
{
SCLK_H;
DIN_H;
delay();
SCLK_L;
delay();
//SCLK_L;
//delay();
}
void WRITE0(void)//写入0
{
SCLK_H;
DIN_L;
delay();
SCLK_L;
delay();
//SCLK_L;
//delay();
}
void WRITE1byte(unsigned int data)
{
unsigned int n;
for(n=16;n>0;n--)
{
if(data&0x8000)
WRITE1();
else
WRITE0();
data<<=1;
delay();
}
}
void delay(void)//延时
{
unsigned char i;
for(i = 0;i < 100;i++)
_NOP();
}
这是我自己编的一个TLV5616的DA转换个程序,但是始终都没输出,为什么呢?求大神帮忙啊,,,,,,,,,,,,
一周热门 更多>