找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1913|回复: 1
打印 上一主题 下一主题
收起左侧

PT100的单片机程序

[复制链接]
跳转到指定楼层
楼主
ID:410355 发表于 2020-4-16 20:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这是PT100温度测试程序
  1. #include<reg52.h>
  2. #include  <intrins.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. sbit dula=P2^6;          //  数码管的
  6. sbit wela=P2^7;

  7. sbit dclk=P1^0;  //  串行时钟
  8. sbit din=P1^1;   //  串行数据输入
  9. sbit dout=P1^2;  //  串行数据输出
  10. sbit cs=P1^4;    //  片选
  11. sbit busy=P1^5;  //  转换状态信号

  12. uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
  13.                           0x39,0x5e,0x79,0x71};
  14. uchar code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,                 //带小数点
  15.                         0x87,0xff,0xef};

  16. uint wendu;

  17. void start() //启动ad芯片
  18. {
  19.         dclk=0;           
  20.         cs=1;
  21.         din=1;
  22.         dclk=1;
  23.         cs=0;

  24. }

  25. /*void xieshuju(unsigned char num) //SPI写数据
  26. {
  27.         unsigned char count=0;
  28.         dclk=0;
  29.         for(count=0;count<16;count++)
  30.         {
  31.                 num<<=1;
  32.                 din=CY;
  33.                 _nop_();
  34.                 dclk=0; _nop_();_nop_();_nop_(); //上升沿有效 ??????0
  35.                 dclk=1; _nop_();_nop_();_nop_();
  36.         }
  37. }            */
  38. void xieshuju(unsigned char num)                  //写数据 16位
  39. {
  40.         unsigned char count=0;
  41.         dclk=0;
  42.         for(count=0;count<16;count++)
  43.         {
  44.                 num<<=1;
  45.                 _nop_();
  46.                 din=CY;
  47.                 _nop_();
  48.                 dclk=1; _nop_();_nop_();_nop_(); //
  49.                 dclk=0; _nop_();_nop_();_nop_();
  50.         }
  51. }
  52. void xiemingling(uchar num)         //    写命令8位
  53. {
  54.         uchar count=0;
  55.         dclk=0;
  56.         for(count=0;count<8;count++)
  57.         {
  58.                 num<<=1;
  59.                 _nop_();
  60.                 din=CY;
  61.                 _nop_();
  62.                 dclk=1; _nop_();_nop_();_nop_(); //
  63.                 dclk=0; _nop_();_nop_();_nop_();
  64.         }
  65. }
  66. uint dushuju() // 读数据 16位
  67. {
  68.         unsigned char count=0;
  69.         unsigned int Num=0;
  70.         dclk=0;
  71.         for(count=0;count<16;count++)
  72.         {
  73.                 Num=(Num<<=1)|dout;
  74.                 _nop_();                   ////   
  75.                 dclk=1; _nop_();_nop_();_nop_(); //
  76.                 dclk=0; _nop_();_nop_();_nop_();
  77.         }
  78.         return(Num);
  79. }

  80. void delay(uchar x)           //延迟
  81. {
  82.         uchar i,j;
  83.         for(i=x;i>0;i--)
  84.                 for(j=110;j>0;j--);
  85. }

  86. void display(unsigned int wendu)                        //数码管显示程序
  87. {
  88.         unsigned int A1,A2,A3,A4;

  89.         A1=wendu/1000;
  90.         A2=wendu%1000/100;
  91.     A3=wendu%100/10;
  92.     A4=wendu%10;

  93.     dula=1;
  94.     P0=table[A1];                //显示千位
  95.     dula=0;
  96.     P0=0xff;
  97.         wela=1;
  98.     P0=0xfe;
  99.     wela=0;
  100.     delay(10);

  101.     dula=1;
  102.     P0=table[A2];                //显示百位
  103.     dula=0;
  104.         P0=0xff;
  105.         wela=1;
  106.     P0=0xfd;
  107.     wela=0;
  108.     delay(10);

  109.     dula=1;
  110.         P0=table[A3];                //显示十位
  111.     dula=0;
  112.         wela=1;
  113.         P0=0xfb;
  114.     wela=0;
  115.     delay(10);

  116.         dula=1;
  117.         P0=table[A4];                //显示个位
  118.     dula=0;
  119.         wela=1;
  120.         P0=0x77;
  121.     wela=0;
  122.     delay(10);
  123. }

  124. int jzzh(int a )        //   进制转换 2进制转换成10进制
  125. {
  126.         int b=0;
  127.         while(a)
  128.         {
  129.                 if(a%2)
  130.                 b++;
  131.                 a=a/2;
  132.         }
  133.         return b;
  134. }


  135. void main()
  136. {
  137.          uint w,ady,sdy;
  138.          start();
  139.          xiemingling(0x08);      //   写模式寄存器
  140.          delay(10);
  141.          xieshuju(0x000a);             //  默认值 复位值
  142.          delay(10);
  143.          xiemingling(0x10);             //   写配置寄存器
  144.          delay(10);
  145.          xieshuju(0x1100);                 //   
  146.          delay(10);
  147.          xiemingling(0x28);                 //  写 io寄存器
  148.          delay(10);
  149.          xiemingling(0x01);             //   10uA电流
  150.          delay(10);
  151.          xiemingling(0x5c);             //  连续读取模式
  152.          delay(10);
  153.          while(1)
  154.          {
  155. //                  if(dout==0)
  156. //                 {
  157.                  sdy=dushuju();//}
  158.                  delay(20);
  159.                  sdy=jzzh(sdy);
  160.                  ady=sdy/65536;
  161.                  w=2.5806*ady-258.1234;
  162.                  display(w);
  163.                  delay (10);
  164.                  xiemingling(0xff);                 ////  复位
  165.                  xiemingling(0xff);
  166.          }

  167. }
复制代码

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1 发表于 2020-4-17 16:53 | 只看该作者
本帖需要重新编辑补全电路原理图,源码,详细说明与图片即可获得100+黑币(帖子下方有编辑按钮)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表