[程序源码]

哪个大佬能给看看我这单片机热电偶测温程序哪里有问题吗?

[复制链接]
700|3
手机看帖
扫描二维码
随时随地手机跟帖
珊瑚海521|  楼主 | 2020-5-6 18:27 | 显示全部楼层 |阅读模式
这是个52单片机热电偶测温的程序,通过MAX6675转换温度数据的。具体功能就是热电偶测量温度然后读到单片机里再显示到数码管上,如果温度高于某个值就报警。
写到Proteus仿真里面数码管就从右往左闪烁,不能稳定显示,然后读的数据也不对。求大佬帮忙看看是程序哪里有问题吗 万分感谢!
#include "reg52.h"
#include "absacc.h"
#include "math.h"
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^0;   //数码管段选
sbit wei=P2^1;    //数码管位选
sbit S0=P1^0;    //MAX6675位定义
sbit SCK=P1^1;  //
sbit CS=P1^2;   //
sbit beep=P1^3;  //蜂鸣器位定义
sbit Work=P1^4;  //工作LED灯位定义
uint Re_Convert (void);    //热电偶温度转换
void Disp_temp();           //数码管显示
void Baojing();              //蜂鸣器报警
void delay(uchar);    ///延时
uint P_Temp;  
uint wendu,t1;
uint ge,shi,bai,qian;
uchar code tab1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x7f};
uchar code tab2[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};

void main(void)  //主函数
{
beep=0;
  while(1)
  {
  Disp_temp();
  delay(500);
  Baojing();
  P_Temp=0;
  }   
}

void delay(uchar t)   //延时函数
{
uchar x;
uchar y;
for(x=0;x<t;x++)
for(y=0;y<110;y++);
}

uint Re_Convert()    //热电偶温度读取
{
  uchar i;
  unsigned long P_Temp2;
  CS=1;       //MAX6675温度转换
  delay(10);    //
  CS=0;       //MAX6675使能
  delay(1);
  SCK=1;    //
  P_Temp2=0;

  for(i=0;i<16;i++)
  {
  SCK =0;    //拉低电平 给一个时钟信号
  P_Temp2=P_Temp2<<1;
  if(S0==1)   
   P_Temp2|=0x0001;
  else  
   P_Temp2&=0xffff;
  SCK=1;
  delay(10);
}   
  CS =1;
  return(P_Temp2);  
}
void Baojing(void)   //报警函数
{
  if(t1<=100&&t1>=400)   //温度小于100大于400报警
  {
   delay(20);
   beep=1;
  }
}
void Disp_temp()   //显示函数
{
   
  P_Temp=Re_Convert();
  P_Temp=P_Temp<<1;   
  P_Temp=P_Temp>>4;
  t1=P_Temp/4;//P_Temp =(1024*P_Temp)/4096

t1=t1*10;
ge=t1%10;
t1=t1/10;
shi=t1%10;
t1=t1/10;
bai=t1%10;
qian=t1/10;

P0=tab1[ge];  //&cedil;&ouml;&Icirc;&raquo;
dula=1;
dula=0;
P0=0x08;
wei=1;
wei=0;
delay(10);

P0=tab2[shi];  //&Ecirc;&reg;&Icirc;&raquo;
dula=1;
dula=0;
P0=0x04;
wei=1;
wei=0;
delay(10);

P0=tab1[bai];  //°&Ugrave;&Icirc;&raquo;
dula=1;
dula=0;
P0=0x02; //0000 0010
  wei=1;
wei=0;
delay(10);

  P0=tab1[qian];   //&Ccedil;§&Icirc;&raquo;
  dula=1;
dula=0;
P0=0x01; //&Icirc;&raquo;&Ntilde;&iexcl; &Ccedil;§&Icirc;&raquo; 0000 0001
  wei=1;
wei=0;
delay(10);
}

使用特权

评论回复

相关帖子

maximQ820270087| | 2020-5-6 21:34 | 显示全部楼层
为什么选用max6675啊 这款老芯片,很难调适,而且面临停产, 推荐你换用max31855K 成熟的电路 案子

使用特权

评论回复
海洋无限| | 2020-5-9 15:24 | 显示全部楼层
数码管显示程序有问题吧,不知道你硬件是怎么接的,而且main中的延时,能显示稳定基本不可能啊

使用特权

评论回复
maximQ820270087| | 2020-5-27 11:09 | 显示全部楼层
#include    "MAX31855_local.h"  
  
MAX31855::MAX31855(unsigned char SO, unsigned   char CS, unsigned char SCK)  
{  
    so = SO;  
    cs = CS;  
    sck = SCK;  
      
    // MAX31855 data output pin  
    pinMode(so, INPUT);  
    // MAX31855 chip select input pin  
    pinMode(cs, OUTPUT);  
    // MAX31855 clock input pin  
    pinMode(sck, OUTPUT);  
      
    // Default output pins state  
    digitalWrite(cs, HIGH);  
    digitalWrite(sck, LOW);  
}  
  
/*******************************************************************************
* Name: readThermocouple
* Description: Read the thermocouple temperature either in Degree Celsius or
*                            Fahrenheit. Internally, the conversion takes place in the
*                            background within 100 ms. Values are updated only when the CS
*                            line is high.
*
* Argument      Description
* =========     ===========
* 1. unit       Unit of temperature required: CELSIUS or FAHRENHEIT
*
* Return            Description
* =========     ===========
*   temperature Temperature of the thermocouple either in Degree Celsius or  
*                           Fahrenheit. If fault is detected, FAULT_OPEN, FAULT_SHORT_GND or
*                           FAULT_SHORT_VCC will be returned. These fault values are outside
*                           of the temperature range the MAX31855 is capable of.
*******************************************************************************/      
double  MAX31855::readThermocouple(unit_t   unit)  
{  
    unsigned long data;  
    double temperature;  
      
    // Initialize temperature  
    temperature = 0;  
      
    // Shift in 32-bit of data from MAX31855  
    data = readData();  
      
    // If fault is detected  
    if (data & 0x00010000)  
    {  
        // Check for fault type (3 LSB)  
        switch (data & 0x00000007)  
        {  
            // Open circuit   
            case 0x01:  
                temperature = FAULT_OPEN;  
                break;  

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

4

帖子

0

粉丝