TA的每日心情 | 开心 2024-10-14 08:33 |
---|
签到天数: 2451 天 连续签到: 1 天 [LV.Master]伴坛终老
|
本帖最后由 limale 于 2017-1-17 20:23 编辑
Fireduino开发板板载一款RTC芯片HYM8563就是如图左下角所指示的芯片,今天我们就来测试一下它的功能。从官方的例程来看操作起来很是方便,主要就是一个时间的结构体,然后就是getTime()和setTime()操作这两个函数即可。
RTC -- HYM5863
HYM8563是一款低功耗CMOS实时时钟/日历芯片,它提供一个可编程的时钟输出,一个中断输出和一个掉电检测器,所有的地址和数据都通过I2C总线接口串行传递。最大总线速度为400Kbit/s,每次读写数据后,内嵌的字地址寄存器会自动递增。
Fireduino RTC
Fireduino RTC 使用外接设备为I2C 接口的HYM5863,挂接在Wire1 接口
Fireduino RTCTime 相关结构体
//datetimeInfo struct
typedef struct
{
unsigned short year;//year (1900 ~ 2099)
unsigned char mon;//month,begin from 1 to 12
unsigned char week;//week (0:Sunday 1:Monday ... 6:Saturday)
unsigned char day;//day,begin from 1 to 31
unsigned char hour;//hour,24-hour
unsigned char min;//minute
unsigned char sec;//second
}RTCTime;
Fireduino RTC API
getTime(RTCTime *time)
说明
获取RTCTime
语法
RTC.getTime(&time);
参数
RTCTime 类型指针
返回
无
setTime(RTCTime *time)
说明
设置RTCTime
语法
RTC.setTime(&time);
参数
RTCTime 类型指针
返回
无
初始化的时候设置一个时间点
然后主循环里边得到时间显示出来
主要的初始化和循环代码:- #include <Arduino.h>
- #include "Wire.h"
- #include "oled.h"
- #include "oledfont.h"
- #include "RTC.h"
- RTCTime time;
- //板载led
- #define LED_GREEN 13
- #define LED_BLUE 3
- #define Trigger_T_measuremnet_hold_master 0xe3
- #define Trigger_RH_measuremnet_hold_master 0xe5
- extern int16_t SHT20_Read_value(uint8_t value);
- uint16_t SHT20_val;
- float SHT20_val_temp;
- float SHT20_val_humi;
- char str[15] = {};
- void Sys_Init(void)
- {
- pinMode(OLED_GND, OUTPUT);
- pinMode(OLED_VCC, OUTPUT);
- pinMode(OLED_CLK, OUTPUT);
- pinMode(OLED_DIN, OUTPUT);
- pinMode(OLED_RES, OUTPUT);
- pinMode(OLED_DC, OUTPUT);
- pinMode(OLED_CS, OUTPUT);
- digitalWrite(OLED_GND,LOW);
- digitalWrite(OLED_VCC,HIGH);
-
- pinMode(LED_GREEN, OUTPUT);
- digitalWrite(LED_GREEN,HIGH);
- Wire.begin();
- OLED_Init();
- OLED_Clear();
-
- Serial.begin(115200);
- Serial.print("\r\n FireDuino Setup ...\r\n");
- time.year = 2016;//year (1900 ~ 2099)
- time.mon = 12;//month,begin from 1 to 12
- time.week = 6 ;//week (0:Sunday 1:Monday ... 6:Saturday)
- time.day = 31;//day,begin from 1 to 31
- time.hour = 14;//hour,24-hour
- time.min = 10;//minute
- time.sec = 50;//second
- Wire1.begin();
- RTC.setTime(&time);
- }
- void Main(void)
- {
- uint8_t i = 4;
- while(1)
- {
- RTC.getTime(&time);
- OLED_ShowString_4DEC(0, 0, time.year, 16);
- OLED_ShowChar(32, 0, '/', 16);
- OLED_ShowString_2DEC(40, 0, time.mon, 16);
- OLED_ShowChar(56, 0, '/', 16);
- OLED_ShowString_2DEC(64, 0, time.day, 16);
- OLED_ShowString_2DEC(96, 0, time.week, 16);
-
- OLED_ShowString_2DEC(16, 2, time.hour, 16);
- OLED_ShowChar(32, 2, ':', 16);
- OLED_ShowString_2DEC(40, 2, time.min, 16);
- OLED_ShowChar(56, 2, ':', 16);
- OLED_ShowString_2DEC(64, 2, time.sec, 16);
-
- SHT20_val = SHT20_Read_value(Trigger_RH_measuremnet_hold_master);
- SHT20_val &= ~0x0003;
- SHT20_val_humi = -6.0 + 125.0 / 65536 * (float)SHT20_val;
- sprintf(str, "= %5.2f RH ", SHT20_val_humi);
- OLED_ShowCHinese(0, 4, 4);
- OLED_ShowCHinese(16, 4, 5);
- OLED_ShowString(32, 4, str, 16);
-
- SHT20_val = SHT20_Read_value(Trigger_T_measuremnet_hold_master);
- SHT20_val &= ~0x0003;
- SHT20_val_temp = -46.85 + 175.72 / 65536 * (float)SHT20_val;
- sprintf(str, "= %5.2f C ", SHT20_val_temp);
- OLED_ShowCHinese(0, 6, 6);
- OLED_ShowCHinese(16, 6, 7);
- OLED_ShowString(32, 6, str, 16);
- }
- }
复制代码 显示效果图,可以看到秒数已经在递增了,加到60之后分钟递增。
RTC操作起来还是很容易的,后边加了按键之后就可以对时间进行校准了。
程序源码:
RTC.rar
(7.56 KB, 下载次数: 4)
|
评分
-
查看全部评分
|