新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > MSP430F149單片機驅動DS2762讀寫操作C語言程序

        MSP430F149單片機驅動DS2762讀寫操作C語言程序

        作者: 時間:2016-12-01 來源:網絡 收藏
        基于作C語言程序,能夠對按鍵或著其他信號響應,讀出電流以及電壓量,并進行相應處理。
        //#include
        #define uchar unsigned char
        #define uint unsigned int
        uint A,B,C,D,E,F,G,H,I,J;//此處對io430x14x中的宏定義C進行了注釋,需注意
        #define IO_OUT P3DIR |= BIT0;
        #define IO_INP P3DIR &= ~BIT0;
        uint data;
        /******************************************************************************
        對讀寫時間進行規范化
        初始調試采用standard=1的參數
        // Pause for exactly tick number of ticks = 0.25us
        實際測的A延時14Us
        B125US
        ******************************************************************************/
        void SetSpeed(uint standard)
        {
        // Adjust tick values depending on speed
        if (standard)
        {
        // Standard Speed
        A = 6 * 4 / 2;
        B = 64 * 4 / 2;
        C = 60 * 4 / 2;
        D = 10 * 4 / 2;
        E = 9 * 4 / 2;
        F = 55 * 4 / 2;
        G = 0 / 2;
        H = 480 * 4 / 2;
        I = 70 * 4 / 2;
        J = 410 * 4 / 2;
        }
        else
        {
        // Overdrive Speed
        A = 1.5 * 4;
        B = 7.5 * 4;
        C = 7.5 * 4;
        D = 2.5 * 4;
        E = 0.75 * 4;
        F = 7 * 4;
        G = 2.5 * 4;
        H = 70 * 4;
        I = 8.5 * 4;
        J = 40 * 4;
        }
        }
        /******************************************************************************
        延時程序
        注意,需要選用8M晶振,時鐘周期125ns
        ******************************************************************************/
        void tickDelay(uint tick) // Implementation is platform specific
        {
        for(;tick>0;tick--);
        }
        /******************************************************************************
        主機復位脈沖
        當接收結果result為0時,表明從機應答
        ******************************************************************************/
        uchar OWTouchReset(void)
        {
        uchar result;
        IO_OUT;
        tickDelay(G);
        P30 = 0; // Drives DQ low
        tickDelay(H);
        P30 = 1; // Releases the bus
        tickDelay(I);
        IO_INP;
        result = P3IN & 0X01; // Sample for presence pulse from slave
        tickDelay(J); // Complete the reset sequence recovery
        return result; // Return sample presence pulse result
        }
        /******************************************************************************
        像寫DS2762寫入一位
        Send a 1-Wire write bit. Provide 10us recovery time.
        ******************************************************************************/
        void OWWriteBit(uchar bit)
        {
        if (bit)
        {
        // Write 1 bit
        P30 = 0; // Drives DQ low
        tickDelay(A);
        P30 = 1; // Releases the bus
        tickDelay(B); // Complete the time slot and 10us recovery
        }
        else
        {
        // Write 0 bit
        P30 = 0; // Drives DQ low
        tickDelay(C);
        P30 = 1; // Releases the bus
        tickDelay(D);
        }
        }
        上一頁 1 2 下一頁

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 哈巴河县| 龙井市| 厦门市| 泸溪县| 岱山县| 集安市| 福州市| 横山县| 城固县| 曲靖市| 沭阳县| 桑植县| 岳普湖县| 屯留县| 青浦区| 桐城市| 齐河县| 韶山市| 高唐县| 永登县| 仪陇县| 湖北省| 岱山县| 清苑县| 尼玛县| 谷城县| 行唐县| 图片| 深圳市| 土默特右旗| 富民县| 海城市| 左贡县| 佛教| 拜城县| 溧水县| 栖霞市| 大方县| 库伦旗| 盘山县| 大丰市|