|
包含MAX6675資料
0.png (59.12 KB, 下載次數(shù): 86)
下載附件
2018-4-30 01:31 上傳
stm32單片機(jī)源程序如下:
- /*********************************************************************************
- * 文件名 :main.c
- * 描述 :通過stm32的spi1讀取max6675的溫度值,并通過uart1發(fā)送出來
- *
- * 實(shí)驗(yàn)平臺:STM32開發(fā)板
- * 庫版本 :ST3.0.0
- * 硬件連接: ------------------------------------
- * |PA6-SPI1-MISO:MAX6675-SO |
- * |PA7-SPI1-MOSI:MAX6675-SI |
- * |PA5-SPI1-SCK :MAX6675-SCK |
- * |PA4-SPI1-NSS :MAX6675-CS |
- * ------------------------------------
- **********************************************************************************/
- #include "stm32f10x.h"
- #include "usart1.h"
- #define MAX6675_CS GPIO_Pin_4
- #define MAX6675_CSL() GPIOA->BRR = MAX6675_CS;
- #define MAX6675_CSH() GPIOA->BSRR = MAX6675_CS;
- /*
- * 函數(shù)名:SPI1_Init
- * 描述 MAX6675 接口初始化
- * 輸入 :無
- * 輸出 :無
- * 返回 :無
- */
- void SPI_MAX6675_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- SPI_InitTypeDef SPI_InitStructure;
-
- /* 使能 SPI1 時(shí)鐘 */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);
- /* ---------通信I/O初始化----------------
- * PA5-SPI1-SCK :MAX6675_SCK
- * PA6-SPI1-MISO:MAX6675_SO
- * PA7-SPI1-MOSI:MAX6675_SI
- */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // 復(fù)用輸出
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* ---------控制I/O初始化----------------*/
- /* PA4-SPI1-NSS:MAX6675_CS */ // 片選
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推免輸出
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_SetBits(GPIOA, GPIO_Pin_4); // 先把片選拉高,真正用的時(shí)候再拉低
-
- /* SPI1 配置 */
- SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
- SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
- SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
- SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
- SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
- SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
- SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
- SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
- SPI_InitStructure.SPI_CRCPolynomial = 7;
- SPI_Init(SPI1, &SPI_InitStructure);
-
-
- /* 使能 SPI1 */
- SPI_Cmd(SPI1, ENABLE);
- }
- /*
- *
- *
- *
- */
- unsigned char MAX6675_ReadByte(void)
- {
-
- /* Loop while DR register in not emplty */
- while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE) == RESET);
-
- /* Send byte through the SPI1 peripheral */
- SPI_I2S_SendData(SPI1, 0xff);
-
- /* Wait to receive a byte */
- while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
-
- /* Return the byte read from the SPI bus */
- return SPI_I2S_ReceiveData(SPI1);
- }
- /*
- * 函數(shù)名:main
- * 描述 :主函數(shù)
- * 輸入 :無
- * 輸出 :無
- */
- main (void)
- {
- unsigned int t,i;
- unsigned char c;
- unsigned char flag;
- float temprature;
- /* 配置系統(tǒng)時(shí)鐘為72M */
- SystemInit();
-
- /* MAX6675 SPI 接口初始化 */
- SPI_MAX6675_Init();
- USART1_Config();
-
- while(1)
- {
-
- MAX6675_CSL();
- c = MAX6675_ReadByte();
- i = c;
- i = i<<8;
- c = MAX6675_ReadByte();
- MAX6675_CSH();
-
- i = i|((unsigned int)c); //i是讀出來的原始數(shù)據(jù)
- flag = i&0x04; //flag保存了熱電偶的連接狀態(tài)
- t = i<<1;
- t = t>>4;
- temprature = t*0.25;
- if(i!=0) //max6675有數(shù)據(jù)返回
- {
- if(flag==0) //熱電偶已連接
- {
- printf("原始數(shù)據(jù)是:%04X, 當(dāng)前溫度是:%4.2f。\r\n",i,temprature);
- }
- else //熱電偶掉線
- {
- printf("未檢測到熱電偶,請檢查。\r\n");
- }
-
- }
- else //max6675沒有數(shù)據(jù)返回
- {
- printf("max6675沒有數(shù)據(jù)返回,請檢查max6675連接。\r\n");
- }
- for(i=0;i<0x2fffff;i++); //max6675的轉(zhuǎn)換時(shí)間是0.2秒左右,所以兩次轉(zhuǎn)換間隔不要太近
- ……………………
- …………限于本文篇幅 余下代碼請從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)
2018-4-29 17:26 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|