標(biāo)題: MAX6675數(shù)字溫度轉(zhuǎn)換芯片驅(qū)動代碼 [打印本頁]

作者: jims9809303    時間: 2024-9-5 11:09
標(biāo)題: MAX6675數(shù)字溫度轉(zhuǎn)換芯片驅(qū)動代碼
MAX6675數(shù)字溫度轉(zhuǎn)換芯片是由Maxim公司生產(chǎn)的器件,以下是其驅(qū)動代碼,供參考。


#define Max6675SCK_Pin GPIO_PIN_3
#define Max6675SCK_GPIO_Port GPIOB
#define Max6675MISO_Pin GPIO_PIN_4
#define Max6675MISO_GPIO_Port GPIOB
#define Max6675SC_Pin GPIO_PIN_5
#define Max6675SC_GPIO_Port GPIOB

//////////////////////////////////////////////////////////////////////////////////////////////////
uint16_t Max6675ReadRoutine(void)
{
    uint16_t temp;uint8_t i;
    HAL_GPIO_WritePin(Max6675SC_GPIO_Port,Max6675SC_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);   
    for(i=0;i<16;i++)
    {   
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_SET);
        temp<<=1;
        if(HAL_GPIO_ReadPin(Max6675MISO_GPIO_Port,Max6675MISO_Pin)==GPIO_PIN_SET)temp|=0x0001;else temp&=(~0x0001);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);        
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
        HAL_GPIO_WritePin(Max6675SCK_GPIO_Port,Max6675SCK_Pin,GPIO_PIN_RESET);
    }
    HAL_GPIO_WritePin(Max6675SC_GPIO_Port,Max6675SC_Pin,GPIO_PIN_SET);
    temp>>=3;
    temp&=0x0FFF;
    return temp;
}

//main.c
void main ()
{
  int temperature;
  temperature=(Max6675ReadRoutine()>>2);//溫度攝氏度。

}







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