新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > SPI總線驅動(C語言源程序)

        SPI總線驅動(C語言源程序)

        作者: 時間:2013-01-07 來源:網絡 收藏

        unsigned char eral_46()
        {
        data unsigned char temp1;
        data unsigned int temp2;
        cs_93=0;
        sk_93=0;
        //spi_org=1;
        cs_93=1;
        ewen46();
        _nop_();
        cs_93=1;
        _nop_();
        high46();
        wd46(0x20);
        wd46(0x20);
        cs_93=0;
        _nop_();
        cs_93=1;
        temp1=1;
        temp2=50000;
        while(!do_93)
        {
        temp2=temp2-1;
        if(temp2==0)
        {
        temp1=0;
        break;
        }
        }
        cs_93=0;
        return temp1;
        }


        unsigned int read93c46_word(unsigned char address)
        {
        unsigned int dat;
        unsigned char dat0,dat1;
        //gnd_93a=0;
        //gnd_93=0;
        cs_93=sk_93=0;
        //org_93=1;
        cs_93=1;_nop_();
        //address=address1;
        //address=address>>1;
        address=address|0x80;
        address=address|0x80;
        high46();
        wd46(address);
        dat1=rd46();
        dat0=rd46();
        cs_93=0;
        dat=dat1*256+dat0;
        return(dat);
        }
        bit write93c46_word(unsigned char address,unsigned int dat)
        {
        unsigned char e,time,temp=address;
        e=0;
        while (e3)
        {
        //gnd_93a=0;
        //gnd_93=0;
        cs_93=sk_93=0;
        org_93=1;
        cs_93=1;
        ewen46();
        _nop_();
        cs_93=1;
        _nop_();
        high46();
        address=1;//??
        address|=0x80;
        address>>=1;//??
        address|=0x40;
        wd46(address);
        wd46(dat/256);
        wd46(dat%256);
        cs_93=0;
        _nop_();
        cs_93=1;
        time=0;
        do_93=1;
        while (1)
        {
        if (do_93==1)
        break;
        if (time>20)
        break;
        time++;
        }
        cs_93=0;
        if (read93c46_word(temp)==dat)
        {
        return(0);
        }
        e++;
        }
        return(1);
        }
        /*-----------------------------------------------------
        93c57系列函數調用(舉例)
        調用方式:bit write93c57_word(unsigned int address,unsigned int dat) ﹫2001/05/12
        函數說明:私有函數,專用
        -----------------------------------------------------
        void ewen57(void)
        {
        _nop_();
        cs_93=1;
        dip7=0;
        high46();
        low46();
        wd46(0x60);
        cs_93=0;
        }
        unsigned int read93c57_word(unsigned int address)
        {
        unsigned int dat;
        unsigned char dat0,dat1;
        gnd_93=0;
        cs_93=sk_93=0;
        org_93=1;
        cs_93=1;
        address=address>>1;
        high46();
        high46();
        wd46(address);
        dat1=rd46();
        dat0=rd46();
        cs_93=0;
        dat=dat1*256+dat0;
        return(dat);
        }
        bit write93c57_word(unsigned int address,unsigned int dat)
        {
        unsigned char e;
        unsigned int temp=address;
        e=0;
        while (e3)
        {
        gnd_93=0;
        cs_93=sk_93=0;
        org_93=1;
        cs_93=1;
        ewen57();
        cs_93=1;
        _nop_();
        high46();
        low46();
        address>>=1;
        address|=0x80;
        wd46(address);
        wd46(dat/256);
        wd46(dat%256);
        cs_93=0;
        _nop_();
        cs_93=1;
        time=0;
        do_93=1;
        while (1)
        {
        if (do_93==1) break;
        if (time>20) break;
        }
        cs_93=0;
        if (read93c57_word(temp)==dat)
        {
        return(0);
        }
        e++;
        }
        return(1);
        }
        /*-----------------------------------------------------
        93c56系列函數調用(舉例)
        調用方式:bit write93c56_word(unsigned int address,unsigned int dat) ﹫2001/05/12
        函數說明:私有函數,SPI專用
        -----------------------------------------------------
        void ewen56(void)
        {
        _nop_();
        cs_93=1;
        high46();
        low46();
        low46();
        wd46(0xc0);
        cs_93=0;
        }
        unsigned int read93c56_word(unsigned char address)
        {
        unsigned int dat;
        unsigned char dat0,dat1;
        gnd_93=0;
        cs_93=sk_93=0;
        org_93=1;
        cs_93=1;
        address=address>>1;
        high46();
        high46();
        low46();
        wd46(address);
        dat1=rd46();
        dat0=rd46();
        cs_93=0;
        dat=dat1*256+dat0;
        return(dat);
        }
        bit write93c56_word(unsigned char address,unsigned int dat)
        {
        unsigned char e;
        unsigned int temp=address;
        e=0;
        while (e3)
        {
        gnd_93=0;
        cs_93=sk_93=0;
        org_93=1;
        cs_93=1;
        ewen56();
        _nop_();
        cs_93=1;
        _nop_();
        high46();
        low46();
        high46();
        address>>=1;
        wd46(address);
        wd46(dat/256);
        wd46(dat%256);
        cs_93=0;
        _nop_();
        cs_93=1;
        TH0=0;
        time=0;
        do_93=1;
        while (1)
        {
        if (do_93==1) break;
        if (time) break;
        }
        cs_93=0;
        if (read93c56_word(temp)==dat)
        {
        return(0);
        }
        e++;
        }
        return(1);
        }

        c語言相關文章:c語言教程


        晶振相關文章:晶振原理


        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 汉沽区| 高碑店市| 巴塘县| 新巴尔虎左旗| 龙陵县| 伊春市| 徐汇区| 余姚市| 承德市| 金沙县| 廉江市| 汉川市| 枞阳县| 巴彦淖尔市| 武强县| 资阳市| 奈曼旗| 钟山县| 黄大仙区| 北海市| 耿马| 卢氏县| 囊谦县| 永和县| 金堂县| 甘孜| 穆棱市| 高邮市| 樟树市| 安丘市| 东兴市| 宣恩县| 郸城县| 芦山县| 大邑县| 宜章县| 徐汇区| 顺义区| 沙雅县| 禹州市| 龙游县|