#include "msp430x14x.h"
#define uint unsigned int
#define uchar unsigned char
#define CPU_F ((double)8000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define clk_clc P1OUT&=~BIT0;
#define clk_set P1OUT|=BIT0;
#define cs_clc P1OUT&=~BIT1;
#define cs_set P1OUT|=BIT1;
#define fs_clc P1OUT&=~BIT2;
#define fs_set P1OUT|=BIT2;
uint current=4000;
void Clock_Init()
{
uchar i;
BCSCTL1&=~XT2OFF; //打开XT2振荡器
BCSCTL2|=SELM1+SELS; //MCLK为8MHZ,SMCLK为8MHZ
do{
IFG1&=~OFIFG; //清楚振荡器错误标志
for(i=0;i<100;i++)
_NOP();
}
while((IFG1&OFIFG)!=0); //如果标志位1,则继续循环等待
IFG1&=~OFIFG;
}
void tlv5616_da(uint da)
{
uchar i;
//da<<=4;
clk_set;
cs_clc;
fs_clc;
for(i=0;i<16;i++){ _NOP();_NOP();
if(da&0x8000)
P1OUT|=BIT3;
else
P1OUT&=~BIT3;
clk_clc;
_NOP();_NOP();
da<<=1;
clk_set;
_NOP();_NOP();
}
//delay_us(10) ;
clk_set;
cs_set;
fs_set;
_NOP();
// clk_clc;
}
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
Clock_Init();
P1DIR=0x0f;
// P1IE|=BIT4+BIT5;
// P1IES|=BIT4+BIT5;
for(;;)
{
tlv5616_da(4000);
delay_ms(50);
}
}
/*#pragma vector=PORT1_VECTOR
__interrupt void ad(void )
{
switch(P1IFG)
{
case(0x10):current+=4;break;
case(0x20): current-=4;break;
}
}*/
此帖出自
小平头技术问答
一周热门 更多>