本文來源電子發(fā)燒友社區(qū),作者:李元江, 帖子地址:https://bbs.elecfans.com/jishu_2021769_1_1.html
今天來寫一篇關(guān)于使用顯示板的帖子。主要完成溫濕度傳感器數(shù)據(jù)采集,把采集到的數(shù)據(jù)顯示到OELD顯示屏,顯示時(shí)鐘。
今天來寫一篇關(guān)于使用顯示板的帖子。主要完成溫濕度傳感器數(shù)據(jù)采集,把采集到的數(shù)據(jù)顯示到OELD顯示屏,顯示時(shí)鐘。
一、硬件介紹
通過查看環(huán)境監(jiān)測板的原理圖,發(fā)現(xiàn)該板子主要有兩個(gè)種資源:12864OLED顯示屏,兩個(gè)模擬按鍵。兩個(gè)模擬按鍵分別按下時(shí),因?yàn)?a target="_blank">電阻分壓,在SWITCH端的電壓都一樣,根據(jù)測量這個(gè)SWITCH端電壓值,可以讀取到按鍵的狀態(tài)。
它們使用主控的GPIO口分別為:AHT20溫濕度傳感器SDA --》 GPIO13 可復(fù)用為I2C0_SDASCL --》 GPIO14 可復(fù)用為I2C0_SCL模擬按鍵ADC --》 GPIO05 可復(fù)用為ADC2
二、軟件設(shè)計(jì)1、新建文件
其中aht20.c、aht20.h、envrionment_demo.c。是從上一篇帖子移植過來的,主要跟環(huán)境監(jiān)測板有關(guān)。oled_demo.c 、oled_fonts.h 、 oled_ssd1306.h 、oled_ssd1306.c從許思維老師例程中移植過來。timeconv.c timeconv.h與時(shí)間轉(zhuǎn)換有關(guān)。
2、timeconv.c
該c文件主要跟時(shí)間戳轉(zhuǎn)換有關(guān),在這個(gè)例程中,每一秒時(shí)間戳數(shù)值加1,然后再把時(shí)間戳轉(zhuǎn)換為北京時(shí)間即可到的時(shí)間戳對應(yīng)的北京時(shí)間。
- #include "timeconv.h"
- #include
- #include
- ?
- static uint8_t month_day[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //平年
- static uint8_t Leap_month_day[12]={31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //閏年
- const uint16_t dayPerYear[4] = {365, 365, 365, 366};
- // 判斷是否是閏年
- // year: 需要判斷的年
- // return:1:閏年
- // 0: 平年
- uint8_t isLeapYear(uint16_t year)
- {
- uint8_t res=0;
- if(year%4 == 0) // 能夠被4整除
- {
- if((year%100 == 0) && (year%400 != 0)) //能夠被100整除,但是不能夠被400整除
- {
- res = 0;
- }
- else
- {
- res =1;
- }
- }
- return res;
- }
- // 將Unix時(shí)間戳轉(zhuǎn)換為北京時(shí)間
- // unixTime: 需要判斷的Unix時(shí)間戳
- // *tempBeijing:返回的北京時(shí)間
- // return:none
- // note:沒對輸入參數(shù)正確性做判斷
- void covUnixTimeStp2Beijing(uint32_t unixTime, rtc_time_t *tempBeijing)
- {
- uint32_t totleDaynum=0, totleSecNum=0;
- uint16_t remainDayofYear;
- uint8_t *pr, tempYear=0;
- totleDaynum = (uint32_t)unixTime/(((uint32_t)24*60*60)); //總天數(shù)(注意加括號(hào))
- totleSecNum = (uint32_t)unixTime%((uint32_t)24*60*60); //當(dāng)天剩余的秒速
- memset(tempBeijing, 0x00, sizeof(rtc_time_t));
- // 1.計(jì)算哪一年
- tempBeijing->ui8Year = 1970 + (totleDaynum/((uint32_t)FOURYEARDAY))*4;
- remainDayofYear = totleDaynum%((uint32_t)FOURYEARDAY)+1;
- //Delay_1ms(1000);
- while(remainDayofYear > dayPerYear[tempYear])
- {
- remainDayofYear -= dayPerYear[tempYear];
- tempBeijing->ui8Year++;
- tempYear++;
- }
- //2.計(jì)算哪一月的哪一天
- pr = isLeapYear(tempBeijing->ui8Year)?Leap_month_day:month_day;
- while(remainDayofYear > *(pr+tempBeijing->ui8Month))
- {
- remainDayofYear -= *(pr+tempBeijing->ui8Month);
- tempBeijing->ui8Month++;
- }
- tempBeijing->ui8Month++; //month
- tempBeijing->ui8DayOfMonth = remainDayofYear; //day
- //3.計(jì)算當(dāng)天時(shí)間
- tempBeijing->ui8Hour = (totleSecNum)/3600;
- tempBeijing->ui8Minute = (totleSecNum%3600)/60; //error:變量搞錯(cuò)
- tempBeijing->ui8Second = (totleSecNum%3600)%60;
- //4.時(shí)區(qū)調(diào)整
- tempBeijing->ui8Hour +=TIMEZONE;
- if(tempBeijing->ui8Hour>23){
- tempBeijing->ui8Hour -= 24;
- tempBeijing->ui8DayOfMonth++;
- }
- }
- // 將北京時(shí)間轉(zhuǎn)換為Unix時(shí)間戳
- // year: 需要判斷的年
- // return:Unix時(shí)間戳(從1970/1/1 00:00:00 到現(xiàn)在的秒數(shù))
- // note:沒對輸入?yún)?shù)正確性做判斷
- uint32_t covBeijing2UnixTimeStp(rtc_time_t *beijingTime)
- {
- uint32_t daynum=0, SecNum=0; //保存北京時(shí)間到起始時(shí)間的天數(shù)
- uint16_t tempYear=1970, tempMonth=0;
- //1.年的天數(shù)
- while(tempYear < beijingTime->ui8Year)
- {
- if(isLeapYear(tempYear)){
- daynum += 366;
- }
- else{
- daynum += 365;
- }
- tempYear++;
- }
- //2.月的天數(shù)
- while(tempMonth < beijingTime->ui8Month-1)
- {
- if(isLeapYear(beijingTime->ui8Year)){ //閏年
- daynum += Leap_month_day[tempMonth];
- }
- else{
- daynum += month_day[tempMonth];
- }
- tempMonth++;
- }
- //3.天數(shù)
- daynum += (beijingTime->ui8DayOfMonth-1);
- //4.時(shí)分秒
- SecNum = daynum*24*60*60; //s
- SecNum += beijingTime->ui8Hour*60*60;
- SecNum += beijingTime->ui8Minute*60;
- SecNum += beijingTime->ui8Second;
- //5.時(shí)區(qū)調(diào)整
- SecNum -= TIMEZONE*60*60;
- return SecNum;
- }
- #ifndef __TIMECONV_H
- #define __TIMECONV_H
- ?
- #include
- #include
- #include
- #include "ohos_init.h"
- #include "cmsis_os2.h"
- #define FOURYEARDAY (((uint32_t)365+365+365+366))//4年一個(gè)周期內(nèi)的總天數(shù)(1970~2038不存在2100這類年份,故暫不優(yōu)化)
- #define TIMEZONE (8) //北京時(shí)區(qū)調(diào)整
- ?
- typedef struct rtc_time_struct
- {
- uint16_t ui8Year; // 1970~2038
- uint8_t ui8Month; // 1~12
- uint8_t ui8DayOfMonth;// 1~31
- uint8_t ui8Week;
- uint8_t ui8Hour; // 0~23
- uint8_t ui8Minute; // 0~59
- uint8_t ui8Second; // 0~59
- }rtc_time_t;
- ?
- uint8_t isLeapYear(uint16_t year);
- void covUnixTimeStp2Beijing(uint32_t unixTime, rtc_time_t *tempBeijing);
- uint32_t covBeijing2UnixTimeStp(rtc_time_t *beijingTime);
- ?
- #endif /*__TIMECONV_H*/
- ?
該c文件主要是oled顯示屏顯示程序、包括時(shí)間轉(zhuǎn)換顯示、溫濕度顯示。
- extern float humidity;
- extern float temperature;
- static void OledTask(void *arg)
- {
- rtc_time_t mData;
- (void)arg;
- ?
- GpioInit();
- ?
- OledInit();
- OledFillScreen(0x00);
- while (1) {
- static char text[128] = {0};
- unsigned short data = 0;
- AdcRead(analog_KEY_CHAN_NAME, &data, WIFI_IOT_ADC_EQU_MODEL_4, WIFI_IOT_ADC_CUR_BAIS_DEFAULT, 0);
- float voltage = ConvertToVoltage(data);
- snprintf(text, sizeof(text), "voltage: %.3f!", voltage);
- //OledShowString(0, 5, text, 1);
- ?
- OLED_ShowCHinese(0,3,0);//溫
- OLED_ShowCHinese(16,3,2);//度
- OledShowChar(32,3,':',2);
- sprintf((char *)TimeStr,"%02d",
- (uint32_t)temperature);
- OledShowString(40,3,(char *)TimeStr,2);
- OLED_ShowCHinese(64,3,1);//濕
- OLED_ShowCHinese(80,3,2);//度
- OledShowChar(96,3,':',2);
- sprintf((char *)TimeStr,"%02d",
- (uint32_t)humidity);
- OledShowString(104,3,(char *)TimeStr,2);
- timedata++;
- covUnixTimeStp2Beijing(timedata, &mData);
- sprintf((char *)TimeStr,"%04d-%02d-%02d",
- mData.ui8Year, mData.ui8Month, mData.ui8DayOfMonth);
- OledShowString(24,0,(char *)TimeStr,1);
- sprintf((char *)TimeStr,"%02d:%02d:%02d",
- mData.ui8Hour,mData.ui8Minute,mData.ui8Second);
- OledShowString(32,1,(char *)TimeStr,1);
- sleep(1);
- }
- }
原來例程上是不能中文的,現(xiàn)在把顯示中文功能加上,但是需要提前使用取模軟件把字取模。
- //顯示漢字
- void OLED_ShowCHinese(uint8_tx,uint8_ty,uint8_tno)
- {
- uint8_tt,adder=0;
- OledSetPosition(x,y);
- for(t=0;t<16;t++)
- {
- WriteData(Hzk[2*no][t]);
- adder+=1;
- }
- OledSetPosition(x,y+1);
- for(t=0;t<16;t++)
- {
- WriteData(Hzk[2*no+1][t]);
- adder+=1;
- }
- }
字模數(shù)組
- static const unsigned charHzk[][16]={
- {0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00},
- {0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00},/*"溫",0*/
- /* (16 X 16 , 宋體 )*/
- {0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00},
- {0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00},/*"濕",1*/
- /* (16 X 16 , 宋體 )*/
- {0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00},
- {0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00},/*"度",2*/
- };
BUILD.gn內(nèi)容為
- # Copyright (c) 2020, HiHope Community.
- #
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions are met:
- #
- # 1. Redistributions of source code must retain the above copyright notice, this
- # list of conditions and the following disclaimer.
- #
- # 2. Redistributions in binary form must reproduce the above copyright notice,
- # this list of conditions and the following disclaimer in the documentation
- # and/or other materials provided with the distribution.
- #
- # 3. Neither the name of the copyright holder nor the names of its
- # contributors may be used to endorse or promote products derived from
- # this software without specific prior written permission.
- #
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ?
- static_library("oled_example") {
- sources = [
- "oled_demo.c",
- "oled_ssd1306.c",
- "timeconv.c",
- "envrionment_demo.c",
- "aht20.c"
- ]
- ?
- include_dirs = [
- "http://utils/native/lite/include",
- "http://kernel/liteos_m/components/cmsis/2.0",
- "http://base/iot_hardware/inteRFaces/kits/wifiiot_lite",
- ]
- }
這樣還不行,還要修改app文件夾下的BUILD.gn。在features下增加"OLED:oled_example",
- lite_component("app") {
- features = [
- "startup",
- "SSL:ssl_example",
- "EM:em_example",
- "OLED:oled_example"
- ]
- }
演示結(jié)果
顯示的時(shí)間是沒有進(jìn)行對時(shí)的,下一篇講寫關(guān)于如何連接網(wǎng)絡(luò),并且如何獲取網(wǎng)絡(luò)時(shí)間。然后把顯示屏上時(shí)間更新為網(wǎng)絡(luò)時(shí)間。
`
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。
舉報(bào)投訴
-
wi-fi
+關(guān)注
關(guān)注
14文章
2147瀏覽量
124612 -
HarmonyOS
+關(guān)注
關(guān)注
79文章
1979瀏覽量
30274 -
HiSpark
+關(guān)注
關(guān)注
1文章
156瀏覽量
6938
發(fā)布評(píng)論請先 登錄
相關(guān)推薦
Wi-Fi 8要來了!未來Wi-Fi技術(shù)演進(jìn)方向揭秘
產(chǎn)品銷售中,雖然Wi-Fi 7產(chǎn)品的銷量份額快速從年初的個(gè)位數(shù)百分比增長至14%,但Wi-Fi 6產(chǎn)品的銷量份額依然穩(wěn)定在60%左右。如果從存量設(shè)備來看,那么Wi-Fi 7路由器的占比將遠(yuǎn)遠(yuǎn)小于這個(gè)數(shù)。 ? 智能手機(jī)等終端設(shè)備已
華為海思正式進(jìn)入Wi-Fi FEM賽道?
大家都知道了,2018年11 月離開銳迪科(RDA),前往福建晉江創(chuàng)立三伍微,專注于Wi-Fi射頻前端芯片,從路由器Wi-Fi FEM,到手機(jī)Wi-Fi FEM,再到IoT FEM全覆
發(fā)表于 12-11 17:42
從Wi-Fi 4到Wi-Fi 7:網(wǎng)速飆升40倍的無線革命
1 Wi-Fi技術(shù)的快速發(fā)展 每一代新的Wi-Fi協(xié)議發(fā)布,都會(huì)帶來更高的無線速率。 ? 從Wi-Fi 4到Wi-Fi 7:無線網(wǎng)絡(luò)技術(shù)顯著提升,實(shí)現(xiàn)了網(wǎng)速的巨大飛躍。 ? ?
Wi-Fi 7與Wi-Fi 6E有什么區(qū)別
也許很多人還在考慮是否要將使用的Wi-Fi設(shè)備升級(jí)到Wi-Fi 6或Wi-Fi 6E,而這些標(biāo)準(zhǔn)的繼任者卻已經(jīng)開始“登堂入室”了。Wi-Fi 7是新一代
IR900 Wi-Fi聯(lián)網(wǎng)的配置過程
, 通過SSID掃描可以查看;輸入密碼,點(diǎn)擊保存;
在SSID掃描頁面中查看是否連接成功, 如果沒有請檢查認(rèn)證方式、加密方式、密碼是否輸入正確;
Wi-Fi掃描顯示“已連接”,進(jìn)入“快速向?qū)?新建WAN
發(fā)表于 07-25 06:09
未來的Wi-Fi路由器
轉(zhuǎn)載自——鐘林談芯 沒有創(chuàng)新就沒有未來,Wi-Fi路由器也是如此。 進(jìn)入2024年以后,Wi-Fi路由器市場變得更加艱難,利潤大幅下滑,BOM成本價(jià)高于市場價(jià),接不接訂單,都陷入兩難。 國內(nèi)主芯片
DA16200 超低功耗 Wi-Fi 模塊開發(fā)套件 Pro數(shù)據(jù)手冊
電子發(fā)燒友網(wǎng)站提供《DA16200 超低功耗 Wi-Fi 模塊開發(fā)套件 Pro數(shù)據(jù)手冊.rar》資料免費(fèi)下載
發(fā)表于 05-30 17:53
?1次下載
DA16200 超低功耗 Wi-Fi 模塊開發(fā)套件數(shù)據(jù)手冊
電子發(fā)燒友網(wǎng)站提供《DA16200 超低功耗 Wi-Fi 模塊開發(fā)套件數(shù)據(jù)手冊.rar》資料免費(fèi)下載
發(fā)表于 05-30 17:13
?0次下載
華為獲得全球首個(gè)國際Wi-Fi聯(lián)盟WFA企業(yè)級(jí)Wi-Fi 7認(rèn)證!
Wi-Fi聯(lián)盟已發(fā)布Wi-Fi 7認(rèn)證標(biāo)準(zhǔn),華為是第一批送測廠商,獲得業(yè)界首個(gè)企業(yè)級(jí)Wi-Fi 7 的Wi-Fi聯(lián)盟官方認(rèn)證。
驗(yàn)證物聯(lián)網(wǎng)Wi-Fi HaLow用例的MM6108-EKH08開發(fā)套件來啦
驗(yàn)證物聯(lián)網(wǎng)Wi-Fi HaLow用例的MM6108-EKH08開發(fā)套件來啦 MM6108-EKH08開發(fā)套件專為驗(yàn)證物聯(lián)網(wǎng)Wi-Fi HaLow用例而設(shè)計(jì)。該
Wi-Fi的誕生與發(fā)展
和5GHz兩個(gè)頻段,承載著不斷增長的網(wǎng)絡(luò)需求。ABIResearch顯示,2022年Wi-Fi上傳流量激增80%,Wi-Fi數(shù)據(jù)流量已超過蜂窩流量,且成為流量增量貢
Wi-Fi HaLow和傳統(tǒng)Wi-Fi的區(qū)別
Wi-Fi HaLow和傳統(tǒng)Wi-Fi的區(qū)別? Wi-Fi是一種無線網(wǎng)絡(luò)技術(shù),可以連接到互聯(lián)網(wǎng)或局域網(wǎng),為用戶提供無線上網(wǎng)的便利。隨著科技的發(fā)展和互聯(lián)網(wǎng)的普及,Wi-Fi也在不斷演進(jìn)和
康普攜手Wi-Fi聯(lián)盟,RUCKUS Wi-Fi 7系列接入點(diǎn)成Wi-Fi
康普高級(jí)副總裁兼網(wǎng)絡(luò)、智能蜂窩和安全解決方案總裁Bart Giordano對此表示: “我們非常榮幸能與Wi-Fi Alliance形成長期合作伙伴關(guān)系,將我們的RUCKUS Wi-Fi 7 接入點(diǎn)平臺(tái)作為Wi-Fi CERT
BT Wi-Fi模式是否可以通過ModustoolBox對套件進(jìn)行編程來實(shí)現(xiàn)?
想配置用于分析 CYW43439 的 CY8CPROTO-062S2-43439 原型開發(fā)套件。
瀏覽文檔我無法弄清楚如何在不同的 Wi-Fi 和藍(lán)牙模式(電源模式、連接模式等)下配置套件。
在
發(fā)表于 01-22 06:19
評(píng)論