使用ADC的对NTC热敏电阻查表得出实际温度。通过excel表格已经得出温度和AD值的关系,思路是通过获取AD值和表中AD值对比,得知获取AD值在表中的位置,从而得知实际温度。
但是在rebuild时有两个error和一个warning。搞了两天,看了很多资料,还是不能解决。期望论坛的大神可以帮忙看看。
本人在Github上开源了这个项目:https://github.com/jack0915/PWM_fan_controller 有兴趣的同可以去看看。
github地址
错误信息如下:
main.c(29): error: #146: too many initializer values
const static u16 temperature_table[TempSize]={3891,3820,3748,3676,3603,3531,3458,3386,3314,3242,3171,3100,3029,2959,2890,2821,2753,2686,2619,2554,2489,2426,2363,2302,2241,2182,2123,2066,2010,1955,1902,1849,1798,1748,1698,1651,1604,1558,1514,1471,1429,1388,1348,1309,1217,1234,1198,1164,1130,1097,1065,1034,1004,975,947,919,893,867,842,817,794,771,749,771,749,727,706,686,667,648,629,611,594,577,561,545,530,515,501,487,474,461,448,436,424,412,401,390,380,370,360,350,341};
main.c(88): warning: #175-D: subscript out of range
temp_position=Fine_data_position(temperature_table[TempSize],TempSize,temp);
main.c(88): error: #167: argument of type "u16" is incompatible with parameter of type "u16 *"
temp_position=Fine_data_position(temperature_table[TempSize],TempSize,temp);
以下为主函数代码
int main(void)
{
const int temp_A=10;
u8 temp_position=0;
const int TempSize=89;
//temp_position = temperature_table;
const static u16 temperature_table[TempSize]={3891,3820,3748,3676,3603,3531,3458,3386,3314,3242,3171,3100,3029,2959,2890,2821,2753,2686,2619,2554,2489,2426,2363,2302,2241,2182,2123,2066,2010,1955,1902,1849,1798,1748,1698,1651,1604,1558,1514,1471,1429,1388,1348,1309,1217,1234,1198,1164,1130,1097,1065,1034,1004,975,947,919,893,867,842,817,794,771,749,771,749,727,706,686,667,648,629,611,594,577,561,545,530,515,501,487,474,461,448,436,424,412,401,390,380,370,360,350,341};// ADC值数组
//u16 *temp_position ;
//temp_position = temperature_table;
short temperature;
u8 NTC_temperature=0;
u32 current_t=0;
u32 previous_t=0;
uc8 interval=1;
u8 t=0;
u16 adcx;
float temp;
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
LED_Init();
LCD_Init();
Adc_Init();
usmart_dev.init(SystemCoreClock/1000000);
RTC_Init();
POINT_COLOR=RED;
LCD_ShowString(60,50,200,16,16,"WarShip STM32");
LCD_ShowString(60,70,200,16,16,"PWM fan controller");
LCD_ShowString(60,90,200,16,16,"By Jack");
//LCD_ShowString(60,110,200,16,16,"2015/1/14");
POINT_COLOR=BLUE;
LCD_ShowString(60,130,200,16,16," - - ");
LCD_ShowString(60,162,200,16,16," : : ");
LCD_ShowString(60,180,200,16,16,"ADC_CH0_VAL:");
LCD_ShowString(60,200,200,16,16,"ADC_CH0_VOL:0.000V");
LCD_ShowString(60,240,200,16,16,"Temp: . C");
while(DS18B20_Init()) //DS18B203õê¼»ˉ
{
LCD_ShowString(30,220,200,16,16,"DS18B20 Error");
delay_ms(200);
LCD_Fill(30,130,239,130+16,WHITE);
delay_ms(200);
}
LCD_ShowString(60,220,200,16,16,"DS18B20 OK");
while(1)
{
if(current_t-previous_t>=interval) //set 1 second interval to read the ADC value and temperature
{
adcx=Get_Adc_Average(ADC_Channel_1,10);
LCD_ShowxNum(156,180,adcx,4,16,0);//ÏÔê¾ADCμÄÖμ
temp=(float)adcx*(3.3/4096);
adcx=temp;
LCD_ShowxNum(156,200,adcx,1,16,0);//ÏÔê¾μçÑ1Öμ
temp-=adcx;
temp*=1000;
LCD_ShowxNum(172,200,temp,3,16,0X80);
temperature=DS18B20_Get_Temp();
temp_position=Fine_data_position(temperature_table[TempSize],TempSize,temp);
NTC_temperature=Get_RTC_Temperature(temp_A,temp_position);
if(temperature<0)
{
LCD_ShowChar(30+40,240,'-',16,0);
temperature=-temperature;
}else LCD_ShowChar(30+40,240,' ',16,0);
LCD_ShowNum(30+40+8+30,240,temperature/10,2,16);
LCD_ShowNum(30+40+32+30,240,temperature%10,1,16);
LCD_ShowNum(30+40+32+30,260,NTC_temperature,1,16);
previous_t=current_t;
}
delay_ms(10);
current_t=RTC_GetCounter();
//LED0=!LED0;
//delay_ms(250);
if(t!=calendar.sec)
{
t=calendar.sec;
//previous_t=t;
LCD_ShowNum(60,130,calendar.w_year,4,16);
LCD_ShowNum(100,130,calendar.w_month,2,16);
LCD_ShowNum(124,130,calendar.w_date,2,16);
switch(calendar.week)
{
case 0:
LCD_ShowString(60,148,200,16,16,"Sunday ");
break;
case 1:
LCD_ShowString(60,148,200,16,16,"Monday ");
break;
case 2:
LCD_ShowString(60,148,200,16,16,"Tuesday ");
break;
case 3:
LCD_ShowString(60,148,200,16,16,"Wednesday");
break;
case 4:
LCD_ShowString(60,148,200,16,16,"Thursday ");
break;
case 5:
LCD_ShowString(60,148,200,16,16,"Friday ");
break;
case 6:
LCD_ShowString(60,148,200,16,16,"Saturday ");
break;
}
LCD_ShowNum(60,162,calendar.hour,2,16);
LCD_ShowNum(84,162,calendar.min,2,16);
LCD_ShowNum(108,162,calendar.sec,2,16);
LED0=!LED0;
}
delay_ms(10);
};
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
这个已经解决了,数组数量定义错了,不是89个,应该是94个。
有没有其他方便点的方法可以点出数量呢?
一周热门 更多>