查看“MCookie-RTC”的源代码
←
MCookie-RTC
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{Language|mCookie-RTC}} {| style="width: 800px;" |- | [[file:mCookie-rtc-rect.jpg|400px|thumb|right|mCookie-RTC]] mCookie-RTC is a clock module adopting IIC interface communication, which can acquire time. With an onboard capacitor, RTC module can keep timing for several times after power disconnected. ==Features== *With century mark, second, minute, hour, day, week, month and year; *Adopt I2C interface to communication with the core modules; *Use EEPROM memory chip with I2C interface; *Low-power clock chip with typical 0.25μA current value and a super capacitor, capable of keeping running after power-fail; ==Specification== *Clock chip: PCF8563 **Low-power CMOS real-time clock/calendar chip; **Offer a programmable clock output, an interruption output and a power-fail detector. All addresses and data can have a serial transmission through I2C bus interface; **The maximum bus speed is 400Kbits/s. The embedded word address register will generate increment after reading and writing data every time. *EEPROM chip:AT24C32 **Provide 32,768 EPROM serial power, which can be organized with a length of 4096 words × 8-bit; **Cascade feature allows AT24C32 to articulate eight devices on the same I2C bus, to have the replication cycle of millions times and save the data to 100 years with a write-protect function. *Super capacitor:XH414 **Provide a power-down timing function in a time slot. [[File:mCookie-RTC-Pinout-1Big1.jpg|800px|thumb|center|mCookie-RTC-Pinout1]] ==Document== ==Development== ==Application== ===Detect Power-down Time Duration=== <source lang="cpp"> #include <Wire.h> #include <Rtc_Pcf8563.h> //init the real time clock Rtc_Pcf8563 rtc; void setup() { Serial.begin(9600); settime(15, 8, 10, 4, 15, 57, 36);//Year, month, day, week, hour, minute and second } void loop() { //both format functions call the internal getTime() so that the //formatted strings are at the current time/date. Serial.println("CODE_1:"); Serial.print(rtc.formatDate());//Acquire data Serial.print(" "); Serial.println(rtc.formatTime());//Acquire time Serial.println("CODE_2:"); Serial.print("20"); Serial.print(rtc.getYear());//Acquire year Serial.print("/"); Serial.print(rtc.getMonth());//Acquire month Serial.print("/"); Serial.print(rtc.getDay());//Acquire day Serial.print(" "); Serial.print(rtc.getHour());//Acquire hour Serial.print(":"); Serial.print(rtc.getMinute());//Acquire minute Serial.print(":"); Serial.println(rtc.getSecond());//Acquire second delay(1000); Serial.print("\r\n"); } void settime(int _year, int _month, int _day, int _week, int _hour, int _min, int _sec) { //clear out the registers rtc.initClock(); //set a time to start with. //day, weekday, month, century(1=1900, 0=2000), year(0-99) rtc.setDate(_day, _week, _month, 0, _year); //hr, min, sec rtc.setTime(_hour, _min, _sec); } </source> *Download program **Stack mCookie-BT and mCookie-CoreUSB, plug USB cable into mCookie-CoreUSB, then connect to PC with the other end; **Start Arduino IDE, copy the program above to IDE and set time in " settime(15, 8, 10, 4, 15, 57, 36);"; **Select Microduino-CoreUSB in (Tools) -> (Board) and the corresponding serial number in (Tools) ->(Serial); **Click the icon(√)on top left of IDE and compile the program. After that, please click Download (->) and burn the program to the RTC board; *Result **Open serial monitor after download and you can see the time. [[File:mCookie-RTC-res.jpg|800px|thumb|center]] **Add "//"before " settime(15, 8, 10, 4, 15, 57, 36);" to comment out the function and download program again. Open serial monitor and you'll see the time. **Cut off the power and connect to PC after several minutes, open serial monitor and you'll the running time after blackout rather than initialized time. **'''(Note: RTC is programmable clock output, which can be set by settime() function. By setting time through settime() function, you need to comment out settime() so that you can take blackout timing next time. Otherwise, you have to reset the value after power-on and restart. ) ''' ===Test EEPROM Read/Write=== <source lang="cpp"> #include <EEPROM.h> long randNumber, data; //Define random number using the name of data //EEPROM configuration #define EEPROM_write(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) EEPROM.write(address+i, pp[i]);} #define EEPROM_read(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) pp[i]=EEPROM.read(address+i);} //Define EEPROMdata struct config_type { int EEPROMdata; }; void setup() { Serial.begin(115200); /*EEPROM read evaluation*/ config_type config_readback; EEPROM_read(0, config_readback); data = config_readback.EEPROMdata; } void loop() { randNumber = random(10, 100);//Random function: The values of randNumber change from 10 to 99. delay(1000);//Rrefresh one time every second if (randNumber != data) //Judge if EEPROM data is changed, if yes, then write in. eeprom_write();//EEPROM write function Serial.print("EEPROM Write:"); Serial.println(randNumber); Serial.print("EEPROM Read:"); Serial.println(data); delay(1000); Serial.println(""); } //=======================EEPROM Write Function===========================// void eeprom_write() { config_type config; // Define config and its content config.EEPROMdata = randNumber; EEPROM_write(0, config); //Save "config" to EEPROM and write address 0 } </source> *Copy the program above to IDE, download program, open serial monitor and you'll see EEPROM writing and reading data. [[File:mCookie-RTC-eeprom.jpg|800px|thumb|center]] *By unplugging power and then plugging in during testing, you can see that " EEPROM Read " is the value of " EEPROM Write " from serial monitor. ==Purchase== ==Picture== [[file:mCookie-rtc-t.jpg|thumb|600px|center|Front]] [[file:mCookie-rtc-B.jpg|thumb|600px|center|Back]] |}
该页面使用的模板:
模板:Language
(
查看源代码
)
模板:Nmbox
(
查看源代码
)
返回至
MCookie-RTC
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息