標題:
PT100的單片機程序
[打印本頁]
作者:
ddfha1
時間:
2020-4-16 20:29
標題:
PT100的單片機程序
這是PT100溫度測試程序
#include<reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6; // 數(shù)碼管的
sbit wela=P2^7;
sbit dclk=P1^0; // 串行時鐘
sbit din=P1^1; // 串行數(shù)據(jù)輸入
sbit dout=P1^2; // 串行數(shù)據(jù)輸出
sbit cs=P1^4; // 片選
sbit busy=P1^5; // 轉(zhuǎn)換狀態(tài)信號
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd, //帶小數(shù)點
0x87,0xff,0xef};
uint wendu;
void start() //啟動ad芯片
{
dclk=0;
cs=1;
din=1;
dclk=1;
cs=0;
}
/*void xieshuju(unsigned char num) //SPI寫數(shù)據(jù)
{
unsigned char count=0;
dclk=0;
for(count=0;count<16;count++)
{
num<<=1;
din=CY;
_nop_();
dclk=0; _nop_();_nop_();_nop_(); //上升沿有效 ??????0
dclk=1; _nop_();_nop_();_nop_();
}
} */
void xieshuju(unsigned char num) //寫數(shù)據(jù) 16位
{
unsigned char count=0;
dclk=0;
for(count=0;count<16;count++)
{
num<<=1;
_nop_();
din=CY;
_nop_();
dclk=1; _nop_();_nop_();_nop_(); //
dclk=0; _nop_();_nop_();_nop_();
}
}
void xiemingling(uchar num) // 寫命令8位
{
uchar count=0;
dclk=0;
for(count=0;count<8;count++)
{
num<<=1;
_nop_();
din=CY;
_nop_();
dclk=1; _nop_();_nop_();_nop_(); //
dclk=0; _nop_();_nop_();_nop_();
}
}
uint dushuju() // 讀數(shù)據(jù) 16位
{
unsigned char count=0;
unsigned int Num=0;
dclk=0;
for(count=0;count<16;count++)
{
Num=(Num<<=1)|dout;
_nop_(); ////
dclk=1; _nop_();_nop_();_nop_(); //
dclk=0; _nop_();_nop_();_nop_();
}
return(Num);
}
void delay(uchar x) //延遲
{
uchar i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void display(unsigned int wendu) //數(shù)碼管顯示程序
{
unsigned int A1,A2,A3,A4;
A1=wendu/1000;
A2=wendu%1000/100;
A3=wendu%100/10;
A4=wendu%10;
dula=1;
P0=table[A1]; //顯示千位
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(10);
dula=1;
P0=table[A2]; //顯示百位
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(10);
dula=1;
P0=table[A3]; //顯示十位
dula=0;
wela=1;
P0=0xfb;
wela=0;
delay(10);
dula=1;
P0=table[A4]; //顯示個位
dula=0;
wela=1;
P0=0x77;
wela=0;
delay(10);
}
int jzzh(int a ) // 進制轉(zhuǎn)換 2進制轉(zhuǎn)換成10進制
{
int b=0;
while(a)
{
if(a%2)
b++;
a=a/2;
}
return b;
}
void main()
{
uint w,ady,sdy;
start();
xiemingling(0x08); // 寫模式寄存器
delay(10);
xieshuju(0x000a); // 默認值 復位值
delay(10);
xiemingling(0x10); // 寫配置寄存器
delay(10);
xieshuju(0x1100); //
delay(10);
xiemingling(0x28); // 寫 io寄存器
delay(10);
xiemingling(0x01); // 10uA電流
delay(10);
xiemingling(0x5c); // 連續(xù)讀取模式
delay(10);
while(1)
{
// if(dout==0)
// {
sdy=dushuju();//}
delay(20);
sdy=jzzh(sdy);
ady=sdy/65536;
w=2.5806*ady-258.1234;
display(w);
delay (10);
xiemingling(0xff); //// 復位
xiemingling(0xff);
}
}
復制代碼
作者:
admin
時間:
2020-4-17 16:53
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1