新手入门
积分 18
金钱 18
注册时间 2021-2-3
在线时间 4 小时
5 金钱
STM32F407
unsigned char MAX6675_ReadByte(void)
{
u8 temp;
temp = SPI1_ReadWriteByte(0xff);
return temp;
}
u8 SPI1_ReadWriteByte(u8 TxData)
{
u8 Rxdata;
HAL_SPI_TransmitReceive(&SPI1_Handler,&TxData,&Rxdata,1, 1000);
return Rxdata;
}
#define MAX6675_CS PBout(14)
int main(void)
{
u16 x=0;
u32 t,i;
u8 c;
u8 flag;
float temprature;
HAL_Init();
Stm32_Clock_Init(336,8,2,7);
delay_init(168);
uart_init(115200);
usmart_dev.init(84);
LCD_Init();
MAX6675_Init();
LCD_Clear(WHITE);
POINT_COLOR=RED;
while(1)
{
MAX6675_CS = 0;
c = MAX6675_ReadByte();
i = c;
i = i<<8;
c = MAX6675_ReadByte();
MAX6675_CS = 1;
i = i|((unsigned int)c); //i读取原始数据
flag = i&0x04; //保存热电偶状态
t = i<<1;
t = t>>4;
temprature = t*0.25;
if(i!=0) //max6675有返回数据
{
if(flag==0) //热电偶已连接
{
printf("原始数据是:o%04X, 当前温度是:%4.2f。\r\n",i,temprature);
LCD_ShowxNum(103,70,temprature,4,16,0);
}
else //掉线
{
printf("未检测到\r\n");
}
}
else //max6675无返回数据
{
printf("未连接\r\n");
}
for(i=0;i<0x2fffff;i++); //max6675转换时间0.2s左右
x++;
delay_ms(10);
if(x==20)
{
LED0=!LED0;
x=0;
}
}
}
我来回答