标题:
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; // 数码管的
sbit wela=P2^7;
sbit dclk=P1^0; // 串行时钟
sbit din=P1^1; // 串行数据输入
sbit dout=P1^2; // 串行数据输出
sbit cs=P1^4; // 片选
sbit busy=P1^5; // 转换状态信号
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, //带小数点
0x87,0xff,0xef};
uint wendu;
void start() //启动ad芯片
{
dclk=0;
cs=1;
din=1;
dclk=1;
cs=0;
}
/*void xieshuju(unsigned char num) //SPI写数据
{
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) //写数据 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() // 读数据 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) //数码管显示程序
{
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 ) // 进制转换 2进制转换成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); // 连续读取模式
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.51hei.com/bbs/)
Powered by Discuz! X3.1