OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 6686|回复: 6

使用 ADC对NTC热敏电阻查表,数组设置出错

[复制链接]

1

主题

4

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2017-1-12
在线时间
3 小时
发表于 2017-5-11 23:15:09 | 显示全部楼层 |阅读模式
1金钱
使用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);                                                                  
        };  
}

最佳答案

查看完整内容[请看2#楼]

main.c(29): error: #146: too many initializer values 这个已经解决了,数组数量定义错了,不是89个,应该是94个。 有没有其他方便点的方法可以点出数量呢?
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

1

主题

4

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2017-1-12
在线时间
3 小时
 楼主| 发表于 2017-5-11 23:15:10 | 显示全部楼层
main.c(29): error:  #146: too many initializer values
这个已经解决了,数组数量定义错了,不是89个,应该是94个。
有没有其他方便点的方法可以点出数量呢?
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2017-5-12 00:44:22 | 显示全部楼层
ljhtao 发表于 2017-5-11 23:24
main.c(29): error:  #146: too many initializer values
这个已经解决了,数组数量定义错了,不是89个, ...

不写数组的容量,直接定义成[]
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

1

主题

4

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2017-1-12
在线时间
3 小时
 楼主| 发表于 2017-5-12 09:07:55 | 显示全部楼层
正点原子 发表于 2017-5-12 00:44
不写数组的容量,直接定义成[]

temp_position=Fine_data_position(temperature_table[TempSize],TempSize,temp);
现在是这条函数报错了,temperature_table[TempSize]这个数组定义出问题了,
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);
回复

使用道具 举报

69

主题

978

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
3774
金钱
3774
注册时间
2015-4-26
在线时间
766 小时
发表于 2017-5-12 09:51:16 | 显示全部楼层
ljhtao 发表于 2017-5-12 09:07
temp_position=Fine_data_position(temperature_table[TempSize],TempSize,temp);
现在是这条函数报错了 ...

形参类型错误
我有故事,你有酒吗
回复

使用道具 举报

1

主题

4

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2017-1-12
在线时间
3 小时
 楼主| 发表于 2017-5-12 13:23:53 | 显示全部楼层

大神,能指点下吗??感激不尽
回复

使用道具 举报

69

主题

978

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
3774
金钱
3774
注册时间
2015-4-26
在线时间
766 小时
发表于 2017-5-12 14:15:21 | 显示全部楼层
ljhtao 发表于 2017-5-12 13:23
大神,能指点下吗??感激不尽

这玩意你自己看看就好了。错误就是形参应该是指针变量,你调用给的是一个u16类型的
我有故事,你有酒吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-8-21 08:22

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表