本帖最后由 缥缈九哥 于 2012-9-14 12:19 编辑
今天用MO516 IO口模拟SPI 向74HC595 发送数据,正常. 然后用SPI1 向74HC595 发送数据 没有反应,请大侠们帮我看下是那出了问题了?
只用了 SPI1MOSI, SPI1CLK, RCK是用IO口模拟的,
void SPI1_Init()
{
P0_MFP &= ~(P05_AD5_SPI1MOSI |P07_AD7_SPI1CLK) ;
P0_MFP |= (SPI1MOSI | SPI1CLK) ;
APBCLK|= SPI1_CLKEN; SPI1_SSR&= ~LVL_H;
SPI1_CNTRL &= ~LSB_FIRST; SPI1_CNTRL &= ~CLKP_IDLE_H;
SPI1_CNTRL |= TX_NEG_F;
SPI1_CNTRL &= ~RX_NEG_F; CLKDIV &= 0xFFFFFFF0; SPI1_DIVIDER &= 0xFFFF0000;
SPI1_DIVIDER |= 3;(SPI_VARCLK =0) SPI1_CNTRL&= ~SPI_MODE_SLAVE;
SPI1_SSR&= ~ASS_AUTO;
}
void SPI1_Send_1W(uint8_t ulData) { SPI1_CNTRL &= TX_NUM_ONE; SPI1_CNTRL|= LEN_8BIT; SPI1_TX0 = ulData;
SPI1_CNTRL|= GO_BUSY; }
void TMR0_Delay1ms(uint32_t ulCNT)
{TCMPR0= 12000;
TCSR0|= CEN;
while (ulCNT --)
{while (!(TISR0&TMR_TIF))
TISR0 |= TMR_TIF;
}
TCSR0 &= ~CEN;
}
void Timer0_Init()
{APBCLK |= TMR0_CLKEN;
CLKSEL1 = ((CLKSEL1 & (~TM0_CLK)) | TM0_12M);
CLKSEL1=0;
TCSR0= 0x00000001;
TCSR0 &= ~TMR_MODE;
TCSR0 |=MODE_PERIOD;
TCSR0 |= TMR_IE;
TCSR0 |= CRST;
TCMPR0.CRST=1
}
main(void)
{ uint8_t np,s; Un_Lock_Reg(); PWRCON|= XTL12M_EN; while(!(CLKSTATUS& XTL12M_STB)); CLKSEL0= (CLKSEL0 & (~HCLK)) | HCLK_12M; Timer0_Init();
while(1)
{
for(s=0;s<255;s++) { SPI1_Send_1W(s); while((SPI1_CNTRL & GO_BUSY)!=0); RCK=0; np=10; while(np--); RCK=1;
np=10; while(np--) ; RCK=0; np=10;
while(np--)
TMR0_Delay1ms(100); }
} }
|
| |
|