標(biāo)題: MAX6675+STM32與51單片機(jī)用K型熱電偶的溫度控制源碼與資料下載 [打印本頁]

作者: lcj1360510480    時(shí)間: 2018-4-29 17:27
標(biāo)題: MAX6675+STM32與51單片機(jī)用K型熱電偶的溫度控制源碼與資料下載
包含MAX6675資料


stm32單片機(jī)源程序如下:
  1. /*********************************************************************************
  2. * 文件名  :main.c
  3. * 描述    :通過stm32的spi1讀取max6675的溫度值,并通過uart1發(fā)送出來
  4. *         
  5. * 實(shí)驗(yàn)平臺(tái):STM32開發(fā)板
  6. * 庫版本  :ST3.0.0
  7. * 硬件連接: ------------------------------------
  8. *           |PA6-SPI1-MISO:MAX6675-SO          |
  9. *           |PA7-SPI1-MOSI:MAX6675-SI          |
  10. *           |PA5-SPI1-SCK :MAX6675-SCK         |
  11. *           |PA4-SPI1-NSS :MAX6675-CS          |
  12. *            ------------------------------------
  13. **********************************************************************************/
  14. #include "stm32f10x.h"
  15. #include "usart1.h"

  16. #define         MAX6675_CS                         GPIO_Pin_4
  17. #define         MAX6675_CSL()                GPIOA->BRR = MAX6675_CS;
  18. #define         MAX6675_CSH()                GPIOA->BSRR = MAX6675_CS;

  19. /*
  20. * 函數(shù)名:SPI1_Init
  21. * 描述 MAX6675 接口初始化
  22. * 輸入  :無
  23. * 輸出  :無
  24. * 返回  :無
  25. */                                                                                                                                                                                  
  26. void SPI_MAX6675_Init(void)
  27. {
  28.         GPIO_InitTypeDef GPIO_InitStructure;
  29.         SPI_InitTypeDef  SPI_InitStructure;       
  30.        
  31.         /* 使能 SPI1 時(shí)鐘 */                        
  32.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);

  33.         /* ---------通信I/O初始化----------------
  34.          * PA5-SPI1-SCK :MAX6675_SCK
  35.          * PA6-SPI1-MISO:MAX6675_SO
  36.          * PA7-SPI1-MOSI:MAX6675_SI         
  37.          */
  38.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  39.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  40.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                        // 復(fù)用輸出
  41.         GPIO_Init(GPIOA, &GPIO_InitStructure);

  42.         /* ---------控制I/O初始化----------------*/
  43.         /* PA4-SPI1-NSS:MAX6675_CS */                                                        // 片選
  44.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  45.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  46.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                // 推免輸出
  47.         GPIO_Init(GPIOA, &GPIO_InitStructure);                                                  
  48.         GPIO_SetBits(GPIOA, GPIO_Pin_4);                                                // 先把片選拉高,真正用的時(shí)候再拉低


  49.         /* SPI1 配置 */
  50.         SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  51.         SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  52.         SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  53.         SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  54.         SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  55.         SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  56.         SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
  57.         SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  58.         SPI_InitStructure.SPI_CRCPolynomial = 7;
  59.         SPI_Init(SPI1, &SPI_InitStructure);
  60.        
  61.        
  62.         /* 使能 SPI1  */
  63.         SPI_Cmd(SPI1, ENABLE);
  64. }

  65. /*
  66. *
  67. *
  68. *
  69. */
  70. unsigned char MAX6675_ReadByte(void)
  71. {
  72.        
  73.         /* Loop while DR register in not emplty */
  74.         while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE) == RESET);
  75.        
  76.         /* Send byte through the SPI1 peripheral */
  77.         SPI_I2S_SendData(SPI1, 0xff);
  78.        
  79.         /* Wait to receive a byte */
  80.         while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
  81.        
  82.         /* Return the byte read from the SPI bus */
  83.         return SPI_I2S_ReceiveData(SPI1);
  84. }
  85. /*
  86. * 函數(shù)名:main
  87. * 描述  :主函數(shù)
  88. * 輸入  :無
  89. * 輸出  :無       
  90. */
  91. main (void)
  92. {
  93.         unsigned int t,i;
  94.         unsigned char c;
  95.         unsigned char flag;
  96.         float temprature;
  97.         /* 配置系統(tǒng)時(shí)鐘為72M */
  98.         SystemInit();
  99.   
  100.         /* MAX6675 SPI 接口初始化 */
  101.         SPI_MAX6675_Init();
  102.         USART1_Config();
  103.        
  104.         while(1)
  105.         {
  106.        
  107.                 MAX6675_CSL();
  108.                 c = MAX6675_ReadByte();
  109.                 i = c;
  110.                 i = i<<8;
  111.                 c = MAX6675_ReadByte();
  112.                 MAX6675_CSH();
  113.                
  114.                 i = i|((unsigned int)c);                        //i是讀出來的原始數(shù)據(jù)
  115.                 flag = i&0x04;                                                //flag保存了熱電偶的連接狀態(tài)
  116.                 t = i<<1;
  117.                 t = t>>4;
  118.                 temprature = t*0.25;
  119.                 if(i!=0)                                                        //max6675有數(shù)據(jù)返回
  120.                 {
  121.                         if(flag==0)                                                //熱電偶已連接
  122.                         {
  123.                                 printf("原始數(shù)據(jù)是:%04X,  當(dāng)前溫度是:%4.2f。\r\n",i,temprature);
  124.                         }       
  125.                         else                                                        //熱電偶掉線
  126.                         {
  127.                                 printf("未檢測到熱電偶,請檢查。\r\n");
  128.                         }
  129.                
  130.                 }
  131.                 else                                                                //max6675沒有數(shù)據(jù)返回
  132.                 {
  133.                         printf("max6675沒有數(shù)據(jù)返回,請檢查max6675連接。\r\n");
  134.                 }
  135.                 for(i=0;i<0x2fffff;i++);                        //max6675的轉(zhuǎn)換時(shí)間是0.2秒左右,所以兩次轉(zhuǎn)換間隔不要太近
  136. ……………………

  137. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
MAX6675_51例程\
MAX6675_STM32例程\
K型熱電偶和MAX6675簡介.doc
MAX6675.pdf
MAX6675的原理及應(yīng)用.pdf
一種簡易的高精度測溫系統(tǒng)研制.pdf
關(guān)于MAX6675應(yīng)用的實(shí)驗(yàn).doc
利用熱電偶轉(zhuǎn)換器的單片機(jī)溫度測控系統(tǒng)_max6675[2頁].pdf
單片K型熱電偶放大與數(shù)字轉(zhuǎn)換器MAX6675.pdf
基于89C51的溫度控制器設(shè)計(jì)_文獻(xiàn)檢索[1].doc
基于K型熱電偶與MAX6675多路溫度采集系統(tǒng).pdf
基于MAX6675的分布式高精度溫度采集系統(tǒng)(1).pdf
基于MAX6675的溫度采集系統(tǒng)的設(shè)計(jì)(1).pdf
基于_MAX6675的溫度控制器設(shè)計(jì).pdf
基于單片機(jī)的發(fā)動(dòng)機(jī)尾氣參數(shù)采集系統(tǒng)的設(shè)計(jì).pdf
基于單片機(jī)的注塑機(jī)溫度采集系統(tǒng)的設(shè)計(jì).pdf
基于單片機(jī)的電阻爐溫度控制系統(tǒng)設(shè)計(jì).pdf
熱電偶溫度表測量電路的設(shè)計(jì).doc
電阻加熱爐溫度控制系統(tǒng).doc

所有資料51hei提供下載:
MAX6675.zip (6.71 MB, 下載次數(shù): 501)



作者: wyj841224    時(shí)間: 2018-5-2 17:20
謝謝樓主的無私奉獻(xiàn)
作者: tianmaduxing    時(shí)間: 2018-5-7 11:33
太好了
作者: 海嵌    時(shí)間: 2018-12-15 22:51
謝謝分享
作者: xmch    時(shí)間: 2018-12-20 11:51
感謝分享。
作者: 明棋M    時(shí)間: 2019-4-19 17:19
先看一下
作者: stchxgb    時(shí)間: 2019-4-20 07:17
謝謝樓主的無私奉獻(xiàn)
作者: msyeh    時(shí)間: 2019-10-2 18:31
感謝分享。
作者: WFX777888    時(shí)間: 2019-10-3 04:52
謝謝分享資料
作者: 炎亞綸    時(shí)間: 2019-10-3 08:39
非常感謝你的分享!謝謝,對我非常有幫助!
作者: 江上遠(yuǎn)帆    時(shí)間: 2019-10-31 13:16
謝謝樓主分享
作者: 小太陽111    時(shí)間: 2019-11-26 18:45
謝謝樓主分享
作者: 噗噗噗p    時(shí)間: 2020-4-12 22:27
感謝感謝,現(xiàn)在正需要溫度控制的相關(guān)資料
作者: fenkella    時(shí)間: 2020-5-11 17:07
請教樓主,我用了PA456腳,PA7沒用,用了你的代碼,讀出來的還是亂七八糟的,硬件我檢查了,應(yīng)該不存在問題,有什么建議嗎?
作者: QQ820270087    時(shí)間: 2020-6-22 15:42
fenkella 發(fā)表于 2020-5-11 17:07
請教樓主,我用了PA456腳,PA7沒用,用了你的代碼,讀出來的還是亂七八糟的,硬件我檢查了,應(yīng)該不存在問題 ...

spi 沒調(diào)試好
作者: yang03777    時(shí)間: 2021-5-10 17:05

非常感謝你的分享!謝謝,對我非常有幫助!
作者: ctx_ok    時(shí)間: 2021-6-25 22:07
非常的資料,下載學(xué)習(xí)學(xué)習(xí)。
作者: jxdianqi    時(shí)間: 2021-6-25 23:07
謝謝分享,做溫度檢測不難,還沒吃透pid控制,下載參考一下
作者: 12332323    時(shí)間: 2023-9-12 22:59
6675有3個(gè)IO口,程序定義了4個(gè)IO口,為什么?




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1