標(biāo)題:
MC96F6508A測溫程序(含線路圖,原碼,注解)
[打印本頁]
作者:
daviddavid
時間:
2020-4-5 20:27
標(biāo)題:
MC96F6508A測溫程序(含線路圖,原碼,注解)
MC96F6508A測溫電路原理圖如下:
51hei.png
(53.5 KB, 下載次數(shù): 67)
下載附件
2020-4-6 01:30 上傳
單片機(jī)源程序如下:
/*****************************************************************
* *
* temperature *
* *
* MCU 芯片: MC96F6508A 工作頻率: 16MHz *
******************************************************************/
#include <mc96f6508a.h>
#include <intrins.h>
#include "MC96F6508A.h"
#include "func_def.h"
#include "lcd.h"
#include "temp.h"
#define uchar unsigned char
#define uint unsigned int
void LcdDisplay(int);
/*******************************************************************************
* 函數(shù)名 : main
* 函數(shù)功能 : 主函數(shù)
* 輸入 : 無
* 輸出 : 無
*******************************************************************************/
main()
{
P1IO = 0xff; // 輸出P1 Direction Register
P1OD = 0xff; //漏極開路輸出 P1 Open-drain Selection Register
P1PU = 0xff; // 內(nèi)部上拉電阻P1 Pull-up Resistor Selection Register
P1DB = 0xff; //消抖
P2IO = 0xf0; // 輸出P1 Direction Register
P2OD = 0x00; //漏極開路輸出 P1 Open-drain Selection Register
P2PU = 0xff; // 內(nèi)部上拉電阻P1 Pull-up Resistor Selection Register
P2FSR = 0x00; //
P3IO = 0xff; // 輸出P1 Direction Register
P3OD = 0x00; //漏極開路輸出 P1 Open-drain Selection Register
P3PU = 0xff; // 內(nèi)部上拉電阻P1 Pull-up Resistor Selection Register
P3FSR = 0x00; //消抖
P4IO = 0xff; // 輸出P1 Direction Register
P4OD = 0xff; //漏極開路輸出 P1 Open-drain Selection Register
P4PU = 0xff; // 內(nèi)部上拉電阻P1 Pull-up Resistor Selection Register
P4FSR = 0x00; //消抖
P5IO = 0xff; // 輸出P1 Direction Register
P5OD = 0xff; //漏極開路輸出 P1 Open-drain Selection Register
P5PU = 0xf0; // 內(nèi)部上拉電阻P1 Pull-up Resistor Selection Register
P5FSRH = 0xff; //
P5FSRL = 0xff;
P6IO = 0xff; // 輸出P1 Direction Register
P6OD = 0xff; //漏極開路輸出 P1 Open-drain Selection Register
P6PU = 0xff; // 內(nèi)部上拉電阻P1 Pull-up Resistor Selection Register
P6FSR = 0x0f; // 設(shè)置為Xin/Xout
P0IO = 0x00; // 輸出P1 Direction Register
P0OD = 0xff; //漏極開路輸出 P1 Open-drain Selection Register
P0PU = 0xff; // 內(nèi)部上拉電阻P1 Pull-up Resistor Selection Register
P0DB = 0xff; //消抖
P4=0xff;
// internal RC clock (16.000000MHz)
OSCCR = 0x08; // Set Int. OSC
SCCR = 0x00; // Use Int. OSC
//P4=0x00;
//DSPORT=0;
//OSCCR = 0x28; // 外部主時鐘
//SCCR = 0x00; // 打開外部主時鐘
LcdInit(); //初始化LCD1602
LcdWriteCom(0x88); //寫地址 80表示初始地址
LcdWriteData('C');
while(1)
{
LcdDisplay(Ds18b20ReadTemp());
//Delay1ms(1000);//1s鐘刷一次
}
}
/*******************************************************************************
* 函數(shù)名 : LcdDisplay()
* 函數(shù)功能 : LCD顯示讀取到的溫度
* 輸入 : v
* 輸出 : 無
*******************************************************************************/
void LcdDisplay(int temp) //lcd顯示
{
unsigned char datas[] = {0, 0, 0, 0, 0}; //定義數(shù)組
float tp;
if(temp< 0) //當(dāng)溫度值為負(fù)數(shù)
{
LcdWriteCom(0x80); //寫地址 80表示初始地址
LcdWriteData('-'); //顯示負(fù)
//因為讀取的溫度是實際溫度的補(bǔ)碼,所以減1,再取反求出原碼
temp=temp-1;
temp=~temp;
tp=temp;
temp=tp*0.0625*100+0.5;
//留兩個小數(shù)點(diǎn)就*100,+0.5是四舍五入,因為C語言浮點(diǎn)數(shù)轉(zhuǎn)換為整型的時候把小數(shù)點(diǎn)
//后面的數(shù)自動去掉,不管是否大于0.5,而+0.5之后大于0.5的就是進(jìn)1了,小于0.5的就
//算由?.5,還是在小數(shù)點(diǎn)后面。
}
else
{
LcdWriteCom(0x80); //寫地址 80表示初始地址
LcdWriteData('+'); //顯示正
tp=temp;//因為數(shù)據(jù)處理有小數(shù)點(diǎn)所以將溫度賦給一個浮點(diǎn)型變量
//如果溫度是正的那么,那么正數(shù)的原碼就是補(bǔ)碼它本身
temp=tp*0.0625*100+0.5;
//留兩個小數(shù)點(diǎn)就*100,+0.5是四舍五入,因為C語言浮點(diǎn)數(shù)轉(zhuǎn)換為整型的時候把小數(shù)點(diǎn)
//后面的數(shù)自動去掉,不管是否大于0.5,而+0.5之后大于0.5的就是進(jìn)1了,小于0.5的就
//算加上0.5,還是在小數(shù)點(diǎn)后面。
}
datas[0] = temp / 10000;
datas[1] = temp % 10000 / 1000;
datas[2] = temp % 1000 / 100;
datas[3] = temp % 100 / 10;
datas[4] = temp % 10;
LcdWriteCom(0x82); //寫地址 80表示初始地址
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
temperature.zip
(76.23 KB, 下載次數(shù): 16)
2020-4-5 20:27 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
temperature.pdf
(56.3 KB, 下載次數(shù): 16)
2020-4-5 20:27 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1