在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)IO口模擬SPI四種模式的程序

            單片機(jī)IO口模擬SPI四種模式的程序

            作者: 時(shí)間:2016-11-19 來源:網(wǎng)絡(luò) 收藏

            本文引用地址:http://www.biyoush.com/article/201611/318342.htm

            #include "iom8535v.h"#define _CPOL     1#define _CPHA     0#define SCK_IO    DDRA|=0X01#define MOSI_IO   DDRA|=0X02#define MISO_IO   DDRA&=0XFB#define SSEL_IO   DDRA|=0X08#define SCK_D(X)   (X?(PORTA|=0X01):(PORTA&=0XFE))#define MOSI_D(X)  (X?(PORTA|=0X02):(PORTA&=0XFD))#define SSEL_D(X)  (X?(PORTA|=0X08):(PORTA&=0XF7))#define MISO_I()  (PINA&0X04)  void delay(){unsigned char m,n;for(n=0;n<5;n++);for(m=0;m<100;m++);}/端口方向配置  與輸出初始化/void SPI_Init(void){SCK_IO   ; MOSI_IO  ;MISO_IO  ; SSEL_IO  ;SSEL_D(1);MOSI_D(1);#if _CPOL==0SCK_D(0);#elseSCK_D(1);#endif}/模式零           寫數(shù)據(jù)*/#if _CPOL==0&&_CPHA==0          //MODE   0  0   void SPI_Send_Dat(unsigned char dat){unsigned char n;for(n=0;n<8;n++){SCK_D(0);if(dat&0x80)MOSI_D(1);else MOSI_D(0);dat<<=1;SCK_D(1);}SCK_D(0);}/*模式零         讀數(shù)據(jù)*/unsigned char SPI_Receiver_Dat(void){unsigned char n ,dat,bit_t;for(n=0;n<8;n++){SCK_D(0);dat<<=1;if(MISO_I())dat|=0x01;else dat&=0xfe;SCK_D(1);}SCK_D(0);return dat;}#endif/模式二           寫數(shù)據(jù)*/#if _CPOL==1&&_CPHA==0           //MODE   1  0void SPI_Send_Dat(unsigned char dat){unsigned char n;for(n=0;n<8;n++){SCK_D(1);if(dat&0x80)MOSI_D(1);else MOSI_D(0);dat<<=1;SCK_D(0);}SCK_D(1);}/*模式二          讀數(shù)據(jù)*/unsigned char SPI_Receiver_Dat(void){unsigned char n ,dat,bit_t;for(n=0;n<8;n++){SCK_D(1);dat<<=1;if(MISO_I())dat|=0x01;else dat&=0xfe;SCK_D(0);}SCK_D(1);return dat;}#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;n<8;n++){SCK_D(1);if(dat&0x80)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;n<8;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;n<8;n++){SCK_D(0);if(dat&0x80)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;n<8;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();}}


            評論


            技術(shù)專區(qū)

            關(guān)閉