新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 基于單片機的溫度測量方案

        基于單片機的溫度測量方案

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

        三、電路圖

        我在這里用的是芯片PIC18F2550,它可以與任何其他規(guī)模較小的PIC微控制器實現(xiàn)I2C通信。溫度由TC74傳感器讀取并顯示在LCD字符。別忘 了把兩個上拉電阻(1K)連接在SDA和SCL線I2C總線上。在本實驗中采用PIC18F2550單片機PIC板來自于StartUSB for PIC board.。

        圖4 電路圖

        圖5 實物圖

        圖6 TC74溫度傳感器

        四、軟件

        PIC18F2550固件是在C使用MikroC Pro for PIC編譯開發(fā)的。MikroC Pro for PIC編譯器提供的內(nèi)置支持I2C庫。單片機讀取TC74內(nèi)部溫度寄存器溫度字并顯示在LCD。下面的程序顯示,TC74的整個工作范圍內(nèi)在40 至125°C。

        程序:

        /* Project: Using TC74 with PIC microcontroller

        for temperature measurement

        MCU: PIC18F2550 on-board StartUSB for PIC

        Clock 48.0 MHz using HS + PLL

        MCLR Enabled

        */

        // Define LCD module connections.

        sbit LCD_RS at RC6_bit;

        sbit LCD_EN at RC7_bit;

        sbit LCD_D4 at RB4_bit;

        sbit LCD_D5 at RB5_bit;

        sbit LCD_D6 at RB6_bit;

        sbit LCD_D7 at RB7_bit;

        sbit LCD_RS_Direction at TRISC6_bit;

        sbit LCD_EN_Direction at TRISC7_bit;

        sbit LCD_D4_Direction at TRISB4_bit;

        sbit LCD_D5_Direction at TRISB5_bit;

        sbit LCD_D6_Direction at TRISB6_bit;

        sbit LCD_D7_Direction at TRISB7_bit;

        // End LCD module connection definition

        unsigned char Temp;

        unsigned short num;

        const int TC74A0 = 0x90;

        void check_device(unsigned short dev_address){ I2C1_Start();

        if (I2C1_Wr(dev_address)){ Lcd_Out(1,1,"Device not found");

        }

        else Lcd_Out(1,1,"TC74 device");

        I2C1_Stop();

        }

        unsigned short Read_Temp(){

        unsigned short result; I2C1_Start(); // Issue start signal

        I2C1_Wr(TC74A0); // Address + Write bit

        I2C1_Wr(0x00); // Read Temp

        I2C1_Repeated_Start(); // Issue start signal

        I2C1_Wr(TC74A0+1); // Address + Read bit

        result = I2C1_Rd(0u); return result;

        }



        關(guān)鍵詞: mikroCmicrochipTC74溫度測

        評論


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

        關(guān)閉
        主站蜘蛛池模板: 泾源县| 铜陵市| 大埔县| 河北省| 精河县| 东平县| 江油市| 中江县| 斗六市| 寻乌县| 桃源县| 汕头市| 靖西县| 米易县| 登封市| 衡南县| 中方县| 沾化县| 五原县| 夏河县| 吴堡县| 昌邑市| 富裕县| 曲水县| 黄浦区| 舟山市| 元江| 茶陵县| 买车| 民权县| 伊吾县| 颍上县| 察雅县| 酉阳| 泰宁县| 河源市| 合山市| 延安市| 祁连县| 麦盖提县| 杭锦后旗|