3190|5

6841

帖子

11

TA的资源

版主

楼主
 

【国民技术N32G457评测】RTC + 温度计 [复制链接]

 

        评测国民技术N32G457快一个月了,今天把前面几个项目整合了一下,合并成一个显示日历+温度,前面准备做一个电子烟测试系统的,因为手头上的硬件全部发走了,所以就没有能够展示。

     温度测量是用一个100K的NTC电阻+100K分压电阻组成的测度电路。LCD屏是1.8寸128*160的TFT LCD屏,9.9元买的,分辨率有点低。

    RTC是RT—thread Studio的软RTC实现。

具体配如置如下:

   把ADC、ST7735文件夹放到packages下面。

 ntc.c

/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-02-13     Administrator       the first version
 */
#include "ntc.h"
#include <stdio.h>
#include <stdint.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <rtconfig.h>
#include <drv_adc.h>


/*************************************************************
函数:  static int16_t get_ntc_temperature(uint16_t ad_data)
功能:
参数:  ad_data: 的ADC采集到的NTC电路分压AD值
返回:  根据单位换算成摄氏度/华氏度,返回温度值*10
描述:  100K与NTC串联,接到3V3电源上
**************************************************************/
static int16_t get_ntc_temperature(uint16_t ad_data)
{
  float Rntc,t;

  uint8_t index;

  Rntc = 100.0*ad_data/(4095 - ad_data);//求出Rntc阻值,单位为Komh

  for(index = 0;index < (N-1);index++)
    {
      if(Rntc > ntc[index])
        {
          break;
        }
    }

  if(index <= 0)                       //temp lower than -20℃
    {
      t = -20.0;                       //rail at -20℃
    }
  else
  if(index >= (N-1))                   //temp higher than 170℃
    {
      t = 170.0;                       //rail at 170℃
    }
  else                                 //temp between -20℃ and 170℃
    {
      t = (-20 + index) - (Rntc-ntc[index])/(ntc[index]-ntc[index-1]);
    }
      t= t-3;
      t = t*100;                        // 温度扩大10倍

  return (int16_t)t;                  // 类型转换为int16_t
}

char v[6] = {'0','0','.','0','0','C'};

void adc_temp_sample(void)
{
    rt_adc_device_t adc_temp_dev;
    rt_uint32_t value, vol;
    double temperate;
    rt_err_t ret = RT_EOK;


    adc_temp_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
    if(adc_temp_dev == RT_NULL)
    {
        rt_kprintf("adc_temp run failed ! can't find %s device!\n",ADC_DEV_NAME);
        //return RT_ERROR;
    }
    /*使能设备 */

    ret = rt_adc_enable(adc_temp_dev, ADC_DEV_CHANNEL);

    if(ret == RT_EOK)
        {
            rt_kprintf("adc sample run success!  find %s device!\n", ADC_DEV_NAME);
        }
        while(1)
        {
            value = rt_adc_read(adc_temp_dev, ADC_DEV_CHANNEL);
            temperate = get_ntc_temperature((rt_uint32_t)value);              //得到气温X10
            vol = (rt_uint32_t)temperate;
            v[0] = vol/1000 + '0';
            v[1] = vol/100%10 +'0';
            v[3] = vol/10%10 +'0';
            v[4] = vol%10 +'0';
            //LCD_ShowIntNum(20,110,vol,4,BLACK,WHITE,16);
            //LCD_ShowString(20,110,v, BROWN ,WHITE,16,0);
            rt_thread_mdelay(500);
        }
}

ntc.h

/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-02-13     Administrator       the first version
 */
#ifndef PACKAGES_ADC_NTC_H_
#define PACKAGES_ADC_NTC_H_
#include <stdio.h>
#define ADC_DEV_NAME     "adc1"
#define ADC_DEV_CHANNEL  2  //PA1

#define N 191 //NTC温度对应阻值个数,即ntc[]数组大小

const static float ntc[N]=
{
    //-20℃  //-19    //-18    //-17    //-16    //-15    //-14    //-13    //-12    //-11
    975.8038,920.5962,868.8615,820.3603,774.8710,732.1889,692.1238,654.4999,619.1540,585.9346,
    //-10℃  //-9     //-8     //-7     //-6     //-5     //-4     //-3     //-2     //-1
    554.7016,525.3245,497.6821,471.6621,447.1599,424.0781,402.3264,381.8204,362.4818,344.2375,
    //0℃    //1      //2      //3      //4      //5      //6      //7      //8      //9
    327.0195,310.7640,295.4121,280.9084,267.2014,254.2428,241.9877,230.3940,219.4224,209.0361,
    //10℃   //11     //12     //13     //14     //15     //16     //17     //18     //19
    199.2007,189.8841,181.0559,172.6881,164.7540,157.2290,150.0898,143.3144,136.8825,130.7749,
    //20℃   //21     //22     //23     //24     //25     //26     //27     //28     //29
    124.9734,119.4612,114.2223,109.2417,104.5053,100.0000,95.7132, 91.6333, 87.7492, 84.0505,
    //30℃   //31     //32     //33     //34     //35     //36     //37     //38     //39
    80.5274, 77.1707, 73.9717, 70.9222, 68.0144, 65.2411, 62.5954, 60.0707, 57.6610, 55.3604,
    //40℃   //41     //42     //43     //44     //45     //46     //47     //48     //49
    53.1635, 51.0651, 49.0602, 47.1443, 45.3130, 43.5621, 41.8878, 40.2862, 38.7539, 37.2876,
    //50℃   //51     //52     //53     //54     //55     //56     //57     //58     //59
    35.8842, 34.5405, 33.2538, 32.0214, 30.8408, 29.7096, 28.6253, 27.5860, 26.5895, 25.6338,
    //60℃   //61     //62     //63     //64     //65     //66     //67     //68     //69
    24.7171, 23.8376, 22.9937, 22.1836, 21.4061, 20.6594, 19.9424, 19.2537, 18.5920, 17.9562,
    //70℃   //71     //72     //73     //74     //75     //76     //77     //78     //79
    17.3452, 16.7578, 16.1930, 15.6499, 15.1276, 14.6251, 14.1417, 13.6764,13.2286, 12.7976,
    //80℃   //81     //82     //83     //84     //85     //86     //87     //88     //89
    12.3825, 11.9828, 11.5978, 11.2270, 10.8697, 10.5254, 10.1935, 9.8736, 9.5652,  9.2678,
    //90℃   //91     //92     //93     //94     //95     //96     //97     //98     //99
    8.9809,  8.7042,  8.4373,  8.1797,  7.9312, 7.6912,   7.4596,  7.2360, 7.0201,  6.8115,
    //100℃  //101    //102    //103    //104    //105    //106    //107    //108    //109
    6.6101,  6.4155, 6.2274,  6.0457,   5.8701,  5.7003,  5.5362,  5.3775,  5.2240, 5.0755,
    //110℃  //111    //112    //113    //114    //115    //116    //117    //118    //119
    4.9319,  4.7930, 4.6586,  4.5285,   4.4026,  4.2807,  4.1627,  4.0484, 3.9378,  3.8306,
    //120℃  //121    //122    //123    //124    //125    //126    //127    //128    //129
    3.7268, 3.6263,  3.5289,  3.4345,   3.3430,  3.2543,  3.1683,  3.0850,  3.0042,  2.9258,
    //130℃  //131    //132    //133    //134    //135    //136    //137    //138    //139
    2.8498, 2.7761,  2.7045,  2.6352,   2.5678,  2.5025, 2.4391,   2.3775,  2.3178,  2.2598,
    //140℃  //141    //142    //143    //144    //145    //146    //147    //148    //149
    2.2034, 2.1487, 2.0956,  2.0440,    1.9939,  1.9452,  1.8978,  1.8518,  1.8071, 1.7637,
    //150℃  //151    //152    //153    //154    //155    //156    //157    //158    //159
    1.7215, 1.6804, 1.6405,  1.6017,   1.5640,  1.5273,  1.4915,  1.4568,  1.4230,  1.3901,
    //160℃  //161    //162    //163    //164    //165    //166    //167    //168    //169
    1.3582, 1.3270, 1.2967,  1.2672,   1.2385,  1.2106,  1.1833,  1.1568,  1.1310,  1.1059,
    //170℃
    1.0814
};
extern char v[6] ;
void adc_temp_sample();
#endif /* PACKAGES_ADC_NTC_H_ */

然后main.c如下:

#include <stdint.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "lcd_init.h"
#include "lcd.h"
#include "pic.h"
#include "ntc.h"
#include <time.h>
/* defined the LED1 pin: PB5 */
#define LED1_PIN    91
#define THREAD_PRIORITY         25
#define THREAD_STACK_SIZE       512
#define THREAD_TIMESLICE        5
extern char v[6] ;

static void rtc_sample(void)
{

    time_t now;
    char da_buf[12];
    char time_buf[12];
    struct tm *t;
    while(1)
    {
        now = time(RT_NULL);
        t=localtime(&now);
        rt_sprintf(da_buf, "%d-%2d-%2d",(t->tm_year)+1900,(t->tm_mon)+1,t->tm_mday);
        rt_sprintf(time_buf,"%2d:%2d:%2d",t->tm_hour,t->tm_min,t->tm_sec);
        LCD_ShowString(24,110,da_buf, BLACK ,WHITE,16,0);
        LCD_ShowString(30,90,time_buf, BLACK ,WHITE,16,0);
        LCD_ShowString(10,56,v,BLACK,WHITE,32,0);
        rt_thread_mdelay(100);
    }
}

int main(void)
{
    uint32_t Speed = 200;
    static rt_thread_t tid1 = RT_NULL;
    static rt_thread_t tid_adc = RT_NULL;
    rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
    int day;
    LCD_Init();//LCD初始化
    LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
    LCD_ShowString(10,0,"RTTDEMO",BLUE,WHITE,32,0);
    LCD_ShowString(24,36,"N32G45XVL",RED,WHITE,16,0);
    //LCD_ShowPicture(74,110,40,40,gImage_1);
    /* 创建线程1,名称是thread1,入口是thread1_entry*/
    tid1 = rt_thread_create("thread1",
                                rtc_sample, RT_NULL,
                                THREAD_STACK_SIZE,
                                THREAD_PRIORITY, THREAD_TIMESLICE);

        /* 如果获得线程控制块,启动这个线程 */
        if (tid1 != RT_NULL)
            rt_thread_startup(tid1);
        tid_adc = rt_thread_create("thread2",
                adc_temp_sample, RT_NULL,
                                       THREAD_STACK_SIZE,
                                       THREAD_PRIORITY, THREAD_TIMESLICE);

       /* 如果获得线程控制块,启动这个线程 */
       if (tid_adc != RT_NULL)
           rt_thread_startup(tid_adc);
    while (1)
    {
        rt_pin_write(LED1_PIN, PIN_LOW);
        rt_thread_mdelay(Speed);
        rt_pin_write(LED1_PIN, PIN_HIGH);
        rt_thread_mdelay(Speed);
    }
}

效里如下:


 

最新回复

不错哟,谢谢分享!   详情 回复 发表于 2022-2-23 17:43
点赞 关注(2)
 
 

回复
举报

6587

帖子

0

TA的资源

五彩晶圆(高级)

沙发
 

看到了,效果还行

 

点评

同时买的另一款,分辨率要高一些,只是没有货,3月才发货,为了测评开发板,得买好多附件。  详情 回复 发表于 2022-2-23 08:58
 
 
 

回复

6841

帖子

11

TA的资源

版主

板凳
 
Jacktang 发表于 2022-2-23 07:18 看到了,效果还行  

同时买的另一款,分辨率要高一些,只是没有货,3月才发货,为了测评开发板,得买好多附件。

点评

nmg
赞,你一般都在哪里买附件  详情 回复 发表于 2022-2-23 09:09
 
 
 

回复

5220

帖子

239

TA的资源

管理员

4
 
lugl4313820 发表于 2022-2-23 08:58 同时买的另一款,分辨率要高一些,只是没有货,3月才发货,为了测评开发板,得买好多附件。

赞,你一般都在哪里买附件

加EE小助手好友,
入技术交流群
EE服务号
精彩活动e手掌握
EE订阅号
热门资讯e网打尽
聚焦汽车电子软硬件开发
认真关注技术本身
 
 
 

回复

6841

帖子

11

TA的资源

版主

5
 

某宝上呀,有时上闲鱼,产品上线在嘉立创!反正做单片机感就是一个穷人。

 
 
 

回复

7452

帖子

2

TA的资源

五彩晶圆(高级)

6
 

不错哟,谢谢分享!

个人签名

默认摸鱼,再摸鱼。2022、9、28

 
 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
推荐帖子
用单片机做电子钟详解(转)

电路特点 这里介绍的电子钟,电路可称得上极简,它仅使用单片的20引脚单片机完成电子钟的全部功能,而笔者见到的其它设计方案均 ...

微带线常用介质板材料

氧化铝9.0-9.9(纯度不同)氧化铍6.1聚四氟乙烯玻璃纤维2.55硅11.7砷化镓13.3复合介质板3-16甚至更大范围内任意选择

我国自主研发----北斗导航系统核心芯片

我国又一自主研发的核心芯片又新鲜出炉了!。“领航一号”是我国自主开发的完全国产化的首个卫星导航基带处理芯片,并将替代“北 ...

电机驱动控制精华汇总帖

本版创立以来,有很多网友在这里发了很多非常有价值的帖子。小管利用这次疫情在家期间,阅读了本版这两年的帖,觉得应该把这些帖 ...

离散序列的卷积运算和相关运算的快速傅里叶变换

# 离散序列的卷积运算和相关运算的快速傅里叶变换 # 离散序列卷积运算与快速傅里叶变换 #### 离散序列信号f(n),g(n)的卷积为 ...

芯片制造4-半导体清洗

501800

【非接触式自动消杀系统】物料开箱——小惊喜

历经漫长的等待,终于收到了心心念念的物料!!!(其中曲折待下回分解) 收到快递挺大一个箱子,打开一看这么多物料还是 ...

花高价淘了俩宝,拆出来一看居然是俩80266的电脑

路过废品站,总是忍不住进去瞟两眼,结果见了俩车机的玩意儿,于是幻想着拆几个芯片DIY用,毕竟现在芯片还是辣么贵。和老板一番 ...

阻容并联接在电路中滤波的原理?

看到一个高速电路,两个运放之间有一个阻容并联结构,目的是为了滤波,搭建了一个简单的电路仿真一下,分别用方波作为输入信号源 ...

【Follow me第二期】任务汇总帖

本帖最后由 Aclicee 于 2024-11-16 14:26 编辑 大家好,我是Aclicee,很高兴能够参加EEworld和DigiKey的Follow me活动。今天 ...

关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表