K-type thermocouple program Proteus test based on ATMEGA8A microcontroller + MAX6675

Publisher:快乐之源Latest update time:2022-01-13 Source: 51heiKeywords:ATMEGA8A Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Adopting avr series ATMEGA8A microcontroller, digital tube adopts 74hc595 static drive, reads MAX6675 chip and performs temperature conversion.



Cold junction compensation potassium thermocouple digital converter (0℃ to +1024℃)
MAX6675 performs cold junction compensation and digitizes the signal of K-type thermocouple. The data is output in 12-bit resolution, SPI compatible, read-only format. The converter can resolve the temperature to 0.25°C, the reading can reach up to +1024°C, and the thermocouple accuracy is 8 LSb in the range of 0°C to +700°C. MAX 6675 adopts small 8-pin SO4 package. Application ● Industry ● Home appliances ● HVAC

Features ● Direct digital conversion of K-type thermocouple output ● Cold junction compensation ● Simple SPI compatible serial interface ● 12 bits, 0.25°C resolution ● Open thermocouple detection



Simply put, read 16 binary, only the middle 3 to 14 are valid, take them out, and then multiply by the resolution 0.25 to get how many degrees Celsius.


The microcontroller source program is as follows:

  1. #include

  2. #include


  3. #include


  4. #define Date16 PORTD.5

  5. #define CLK PORTD.7

  6. #define RCLK PORTD.6



  7. #define DateIN PINB.0

  8. #define MCLK PORTB.1

  9. #define CS PORTB.2


  10. const unsigned char Dis_Code[] = {0xFC, 0x60, 0xDA, 0xF2, 0x66, 0XB6, 0xBE, 0xE0, 0XFE, 0xF6};


  11. unsigned char Blk_Flg,Blk_Bit;

  12. unsigned char Disp_Timer, Dis_Buffer[8];


  13. unsigned int wendu,T_Timer;





  14. unsigned int Read6675(void)

  15. {

  16. unsigned int date6675=0;

  17. unsigned char i;

  18.      CS=0;

  19.      delay_us(15);

  20.      MCLK=0;

  21.      delay_us(15);

  22.      for(i=0;i<16;i++)

  23.      {


  24.        date6675<<=1;

  25.        delay_us(15);

  26.        MCLK=1;

  27.        delay_us(15);

  28.        if(DateIN==1) date6675|=0X01;

  29.        delay_us(15);

  30.        MCLK=0;

  31.        delay_us(15);

  32.      }

  33.      CS=1;

  34.      delay_us(15);

  35. //     MCLK=1;

  36.      if((date6675&0X0004)!=0)   date6675=4095;

  37.      else  date6675>>=3;

  38.      return  date6675;


  39. }



  40. void T_zhuanhuan(void)

  41. {

  42.    float temp;

  43.    temp=Read6675();

  44.    temp*=2.5;

  45.    wendu=(unsigned int)temp;

  46. }



  47. int EEPROMwrite( int location, unsigned char byte)

  48. {

  49.     unsigned char oldSREG;


  50.     while (EECR & 0x02);


  51.     EEAR = location;


  52.     EEDR = byte;


  53.     oldSREG = SREG;

  54.     SREG &= ~0x80;


  55.     EECR |= 0x04;

  56.     EECR |= 0x02;


  57.     SREG = oldSREG;

  58.     return 0;

  59. }

  60. unsigned char EEPROMread( int location)

  61. {

  62.     while (EECR & 0x02);


  63.     EEAR = location;


  64.     EECR |= 0x01;


  65.     return (EEDR);

  66. }



  67. void Disp_Led(void)

  68. {

  69.     unsigned char Dis_Temp_B1,Dis_Temp_B2,Dis_Temp_B3 ;

  70.     RCLK=1 ;

  71.     for(Dis_Temp_B1=0;Dis_Temp_B1<5;Dis_Temp_B1++)

  72.     {

  73.         Dis_Temp_B3=1 ;

  74.         for(Dis_Temp_B2=0;Dis_Temp_B2<8;Dis_Temp_B2++)

  75.         {

  76.             if((Dis_Buffer[Dis_Temp_B1]&Dis_Temp_B3)!=0)

  77.             Date16=1 ;

  78.             else

  79.             Date16=0 ;

  80.             CLK=0 ;

  81.             CLK=1 ;

  82.             Dis_Temp_B3*=2 ;

  83.         }

  84.     }

  85.     RCLK=0 ;

  86.     RCLK=1 ;

  87. }

  88. void Dex_To_Bcd(int Dis_Value,unsigned char Blk_En,unsigned char Bcd_T_B1)

  89. {

  90.     Dis_Buffer[4]=Dis_Code[Dis_Value/10000];

  91.     Dis_Value%=10000 ;

  92.     Dis_Buffer[3]=Dis_Code[Dis_Value/1000];

  93.     Dis_Value%=1000 ;

  94.     Dis_Buffer[2]=Dis_Code[Dis_Value/100];

  95.     Dis_Value%=100 ;

  96.     Dis_Buffer[1]=Dis_Code[Dis_Value/10];

  97.     Dis_Value%=10 ;

  98.     Dis_Buffer[0]=Dis_Code[Dis_Value];

  99.     if((Blk_Flg==1)&&(Blk_En!=0))

  100.     {

  101.         switch(Blk_Bit)

  102.         {

  103.             /*0*/

  104.             case 0 :

  105.             break ;

  106.             /*1*/

  107.             case 1 :

  108.             if(Bcd_T_B1==4)Bcd_T_B1=3 ;

  109.             break ;

  110.             /*2*/

  111.             case 2 :

  112.             if(Bcd_T_B1==3||Bcd_T_B1==4)Bcd_T_B1=2 ;

  113.             break ;

  114.             /*3*/

  115.             case 3 :

  116.             if(Bcd_T_B1==2||Bcd_T_B1==3||Bcd_T_B1==4)Bcd_T_B1=1 ;

  117.             break ;

  118.             /*4*/

  119.             case 4 :

  120.             Bcd_T_B1=0 ;

  121.             break ;

  122.             default :

  123.             break ;

  124.         }

  125.     }


  126.     if(Bcd_T_B1==1&&Dis_Buffer[4]==0xFC)Dis_Buffer[4]=0x00 ;

  127.     if(Bcd_T_B1==2&&Dis_Buffer[4]==0xFC)

  128.     {

  129.         Dis_Buffer[4]=0x00 ;

  130.         if(Dis_Buffer[3]==0xFC)

  131.         

  132. ……………………


Keywords:ATMEGA8A Reference address:K-type thermocouple program Proteus test based on ATMEGA8A microcontroller + MAX6675

Previous article:AVR MCU fuse configuration and related solutions
Next article:ICCV7 For AVR Tutorial Atmega16 MCU

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号