不废话 直接上代码 单片机 msp430f2132 求高手看哪错了?
#define UZ2400_MOSI_bit BIT1
#define UZ2400_SPI_CLK_bit BIT3
void WriteSPIData(unsigned char data)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(data&0x80)
{
P3OUT|=UZ2400_MOSI_bit;
}
else
{
P3OUT&=~UZ2400_MOSI_bit;
}
P3OUT|=UZ2400_SPI_CLK_bit;
data<<=1;
P3OUT&=~UZ2400_SPI_CLK_bit;
}
}
void WriteSPIDatal(unsigned int data)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(data&0x80)
{
P3OUT|=UZ2400_MOSI_bit;
}
else
{
P3OUT&=~UZ2400_MOSI_bit;
}
P3OUT|=UZ2400_SPI_CLK_bit;
data<<=1;
P3OUT&=~UZ2400_SPI_CLK_bit;
}
}
unsigned char ReadSPIData()
{
unsigned char data,i;
for(i=0;i<8;i++)
{
data<<=1;
P3OUT|=UZ2400_SPI_CLK_bit;
if(0x04 & P3IN)data|=0x01;
P3OUT&=~UZ2400_SPI_CLK_bit;
}
return data;
}
|