#endif/*********************************************模式一 寫數(shù)據(jù)*********************************************/#if _CPOL==0_CPHA==1 //MODE 0 1void SPI_Send_Dat(unsigned char dat){unsigned char n;SCK_D(0);for(n=0;n8;n++){SCK_D(1);if(dat0x80)MOSI_D(1);else MOSI_D(0);dat=1;SCK_D(0);}}/*********************************************模式一 讀數(shù)據(jù)*********************************************/unsigned char SPI_Receiver_Dat(void){unsigned char n ,dat,bit_t;for(n=0;n8;n++){SCK_D(1);dat=1;if(MISO_I())dat|=0x01;else dat=0xfe;SCK_D(0);}SCK_D(0);return dat;}#endif//////////////////////////////////////////////////////////////////////////////////////////////////////////////#if _CPOL==1_CPHA==1 //MODE 1 1void SPI_Send_Dat(unsigned char dat){unsigned char n;SCK_D(1);for(n=0;n8;n++){SCK_D(0);if(dat0x80)MOSI_D(1);else MOSI_D(0);dat=1;SCK_D(1);}}/************************************模式三 讀數(shù)據(jù)************************************/unsigned char SPI_Receiver_Dat(void){unsigned char n ,dat,bit_t;SCK_D(0);for(n=0;n8;n++){ SCK_D(0);dat=1;if(MISO_I())dat|=0x01;else dat=0xfe;SCK_D(1);}SCK_D(1);return dat;}#endif/**************************************************************************/void main(){SPI_Init();DDRB = 0XFF;//#if _CPOL//SCK_D(0);//#endifwhile(1){//SSEL_D(0);//SPI_Send_Dat(0x01);//SPI_Send_Dat(0x31);//SSEL_D(1);SSEL_D(0);SPI_Send_Dat(0x81);PORTB =SPI_Receiver_Dat();SSEL_D(1);//delay();}}
51單片機(jī)相關(guān)文章:51單片機(jī)教程
評(píng)論