void loop()
{
//print received data. Data was received in serialEvent;
Serial.print("Time:20");Serial.print(JY901.stcTime.ucYear);Serial.print("-");Serial.print(JY901.stcTime.ucMonth);Serial.print("-");Serial.print(JY901.stcTime.ucDay);
Serial.print(" ");Serial.print(JY901.stcTime.ucHour);Serial.print(":");Serial.print(JY901.stcTime.ucMinute);Serial.print(":");Serial.println((float)JY901.stcTime.ucSecond+(float)JY901.stcTime.usMiliSecond/1000);
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent()
{
while (Serial.available())
{
JY901.CopeSerialData(Serial.read()); //Call JY901 data cope function
}
}[/code]
步骤很简单,首先初始化串口,然后在串口中断里面调用JY901的数据处理函数即可。其实大部分都是在打印输出,数据解析都是在库里面完成的。非常简洁明了。测试结果如下:
IIC的接线方法也很简单,接上VCC和GND以后,将JY901的SCL和SDA分别接上UnoR3的SCL和SDA上面即可。
void loop()
{
//print received data. Data was received in serialEvent;
JY901.GetTime();
Serial.print("Time:20");Serial.print(JY901.stcTime.ucYear);Serial.print("-");Serial.print(JY901.stcTime.ucMonth);Serial.print("-");Serial.print(JY901.stcTime.ucDay);
Serial.print(" ");Serial.print(JY901.stcTime.ucHour);Serial.print(":");Serial.print(JY901.stcTime.ucMinute);Serial.print(":");Serial.println((float)JY901.stcTime.ucSecond+(float)JY901.stcTime.usMiliSecond/1000);