极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

楼主: 尕老汉

发个DS3231的简易时钟,1602液晶显示、串口修改时间

  [复制链接]
发表于 2015-3-10 22:39:02 | 显示全部楼层
如何用DS3231模块唤醒MCU?
回复 支持 反对

使用道具 举报

发表于 2015-3-27 21:13:55 | 显示全部楼层
本帖最后由 codeeditor 于 2015-3-27 21:15 编辑

有需要观看的访客,请登陆xinpian://D:/360安全浏览器下载\DS3231

  1. #include <DS3231.h>
  2. #include <Wire.h>

  3. DS3231 Clock;
  4. bool Century=false;
  5. bool h12;
  6. bool PM;
  7. byte ADay, AHour, AMinute, ASecond, A/P, ABits;
  8. bool ADy, A12h, Apm;

  9. int year, month, date, DoW,week , hour, minute, second,temperature;

  10. String comdata = "";
  11. int numdata[7] = {0},  mark = 0;
  12. /*1602液晶与UNO连接引脚
  13. 6 -> D7
  14. 7 -> D6
  15. 8 -> D5
  16. 9 -> D4
  17. */

  18. int LCD1602_RS=12;   
  19. int LCD1602_RW=11;   
  20. int LCD1602_EN=10;   
  21. int DB[] = { 6, 7, 8, 9};

  22. char dis1[16]={0},dis2[16]={0};

  23. char self_char[]={                               //1602液晶自定义符号   
  24.         0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02, //年
  25.         0x0f,0x09,0x0f,0x09,0x0f,0x09,0x13,0x01, //月
  26.         0x0f,0x09,0x09,0x0f,0x09,0x09,0x0f,0x00, //日
  27.         0x00,0x04,0x0e,0x1f,0x0e,0x04,0x00,0x00,0x0c, //符号=0cH(◆)
  28.         0x18,0x18,0x07,0x08,0x08,0x08,0x07,0x00, //温度标志— —摄氏度
  29.         0x9c,0x45,0x5c,0x55,0x43,0x44,0x81,0x00, //温度标志— —华氏度
  30.         0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, //全开
  31.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //
  32.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00         //
  33.                                            };

  34. void LCD_Command_Write(int command)             //写指令
  35. {
  36. int i,temp;
  37. digitalWrite( LCD1602_RS,LOW);
  38. digitalWrite( LCD1602_RW,LOW);
  39. digitalWrite( LCD1602_EN,LOW);

  40. temp=command & 0xf0;
  41. for (i=DB[0]; i <= 9; i++)
  42. {
  43.    digitalWrite(i,temp & 0x80);
  44.    temp <<= 1;
  45. }

  46. digitalWrite( LCD1602_EN,HIGH);
  47. delayMicroseconds(1);
  48. digitalWrite( LCD1602_EN,LOW);

  49. temp=(command & 0x0f)<<4;
  50. for (i=DB[0]; i <= 9; i++)
  51. {
  52.    digitalWrite(i,temp & 0x80);
  53.    temp <<= 1;
  54. }

  55. digitalWrite( LCD1602_EN,HIGH);
  56. delayMicroseconds(1);
  57. digitalWrite( LCD1602_EN,LOW);
  58. }

  59. void LCD_Data_Write(int dat)                //写数据
  60. {
  61. int i=0,temp;
  62. digitalWrite( LCD1602_RS,HIGH);
  63. digitalWrite( LCD1602_RW,LOW);
  64. digitalWrite( LCD1602_EN,LOW);

  65. temp=dat & 0xf0;
  66. for (i=DB[0]; i <= 9; i++)
  67. {
  68.    digitalWrite(i,temp & 0x80);
  69.    temp <<= 1;
  70. }

  71. digitalWrite( LCD1602_EN,HIGH);
  72. delayMicroseconds(1);
  73. digitalWrite( LCD1602_EN,LOW);

  74. temp=(dat & 0x0f)<<4;
  75. for (i=DB[0]; i <= 9; i++)
  76. {
  77.    digitalWrite(i,temp & 0x80);
  78.    temp <<= 1;
  79. }

  80. digitalWrite( LCD1602_EN,HIGH);
  81. delayMicroseconds(1);
  82. digitalWrite( LCD1602_EN,LOW);
  83. }

  84. void LCD_SET_XY( int x, int y )//指定坐标,x为列,0~15,y为行,0为第一行,1为第二行。
  85. {
  86.   int address;
  87.   if (y ==0)    address = 0x80 + x;
  88.   else          address = 0xC0 + x;
  89.   LCD_Command_Write(address);
  90. }

  91. void LCD_Write_Char( int x,int y,int dat)  //指定位置一个字符
  92. {
  93.   LCD_SET_XY( x, y );
  94.   LCD_Data_Write(dat);
  95. }

  96. void LCD_Write_String(int X,int Y,char *s)  //指定位置字符串
  97. {
  98.     LCD_SET_XY( X, Y );    //设置地址
  99.     while (*s)             //写字符串
  100.     {
  101.       LCD_Data_Write(*s);   
  102.       s ++;
  103.     }
  104. }

  105. void setup (void)
  106. {
  107.   Serial.begin(9600);
  108.   int i = 0;
  109.   for (i=6; i <= 12; i++)
  110.    {
  111.      pinMode(i,OUTPUT);
  112.    }

  113.   delay(100);
  114.   LCD_Command_Write(0x28);//4线 2行 5x7
  115.   delay(50);
  116.   LCD_Command_Write(0x06);
  117.   delay(50);
  118.   LCD_Command_Write(0x0c);
  119.   delay(50);
  120.   LCD_Command_Write(0x80);
  121.   delay(50);
  122.   LCD_Command_Write(0x01);
  123.   delay(50);

  124.     diy();              //开机问候
  125.   //Wire.begin();
  126.   Serial.println("set_time :");
  127.   Serial.println("year mouth day week hour minute second AM/PM");
  128.   Serial.println();
  129.   Serial.println("week : 1 -> Sunday; 2 -> Monday; 3 -> Tuesday:  ....7 -> Saturday");
  130.   Serial.println();
  131.   Serial.println("for example :2015-3-27 Fri 8:42:50 PM  ");
  132.   Serial.println("set_time :");
  133.   Serial.println("15 3 27 5 8 42 50 1");
  134.   Serial.println();
  135. }
  136.        

  137. void diy()
  138. {
  139.      char a;
  140.   LCD_Command_Write(0x40);   
  141.      for(a=0;a<64;a++)
  142.         {
  143.           LCD_Data_Write(self_char[a]);
  144.           delay(1);
  145.         }
  146.     delay(50);
  147.   LCD_Write_String(0,0," Digital Clock  ");
  148.   LCD_Write_String(0,1," Geek-workshop  ");
  149.   delay(2000);
  150.   LCD_Command_Write(0x01);  
  151.   delay(10);
  152.   LCD_Write_String(0,0,"Today is new day");
  153.   LCD_Write_String(0,1,"Dream come true!");
  154.   delay(2000);
  155.   LCD_Command_Write(0x01);
  156. delay(10);           
  157. }

  158. void ReadDS3231()          //读取DS3231 参数
  159. {
  160.   Wire.begin();

  161.   second=Clock.getSecond();
  162.   minute=Clock.getMinute();
  163.   hour=Clock.getHour(h12,PM);
  164.   week=Clock.getDoW();   
  165.   date=Clock.getDate();
  166.   month=Clock.getMonth(Century);
  167.   year=Clock.getYear();
  168.   temperature=Clock.getTemperature();
  169.   
  170. }

  171. void get_dis()          //1602液晶上每一位上显示的数据
  172. {
  173.   ReadDS3231();
  174.   dis1[0]='2';
  175.   dis1[1]='0';
  176.   dis1[2]=0x30+year/10;
  177.   dis1[3]=0x30+year%10;
  178.   dis1[4]=0;
  179.   dis1[5]=0x30+month/10;
  180.   dis1[6]=0x30+month%10;
  181.   dis1[7]=1;
  182.   dis1[8]=0x30+date/10;
  183.   dis1[9]=0x30+date%10;
  184.   dis1[10]=2;
  185.   dis1[11]=' ';
  186.   dis1[12]=' ';
  187.   switch(week)
  188.   {
  189.         case 2: {
  190.                           dis1[13]='M';
  191.                           dis1[14]='o';
  192.                           dis1[15]='n';
  193.                         }
  194.                         break;
  195.         case 3: {
  196.                           dis1[13]='T';
  197.                           dis1[14]='u';
  198.                           dis1[15]='e';
  199.                         }
  200.                         break;
  201.         case 4: {
  202.                           dis1[13]='W';
  203.                           dis1[14]='e';
  204.                           dis1[15]='d';
  205.                         }
  206.                         break;
  207.         case 5: {
  208.                           dis1[13]='T';
  209.                           dis1[14]='h';
  210.                           dis1[15]='u';
  211.                         }
  212.                         break;
  213.         case 6: {
  214.                           dis1[13]='F';
  215.                           dis1[14]='r';
  216.                           dis1[15]='i';
  217.                         }
  218.                         break;
  219.         case 7: {
  220.                           dis1[13]='S';
  221.                           dis1[14]='a';
  222.                           dis1[15]='t';
  223.                         }
  224.                         break;
  225.         case 8: {
  226.                           dis1[13]='S';
  227.                           dis1[14]='u';
  228.                           dis1[15]='n';
  229.                         }
  230.                         break;
  231.   }
  232.   dis2[0]=' ';
  233.   dis2[1]=0x30+hour/01;
  234.   dis2[2]=0x30+hour%01;
  235.   dis2[3]=':';
  236.   dis2[4]=0x30+minute/10;
  237.   dis2[5]=0x30+minute%10;
  238.   dis2[6]=':';
  239.   dis2[7]=0x30+second/10;
  240.   dis2[8]=0x30+second%10;
  241.   dis2[9]=':';
  242.   dis2[10]=0x30+a/p;
  243.   dis2[11]=' ';
  244.   
  245.         dis2[10]=' ';
  246.   dis2[12]=0x30+temperature/10;
  247.   dis2[13]=0x30+temperature%10;
  248.   dis2[14]='.';
  249.   dis2[15]=0x30+0;
  250.   dis2[16]=3;
  251. }
  252. void play()                  //1602显示完整时间
  253. {
  254.        get_dis();

  255.             int k;      
  256.             LCD_SET_XY( 0,0);
  257.             for(k=0;k<16;k++)
  258.             LCD_Data_Write(dis1[k]);
  259.             LCD_SET_XY( 0,1);
  260.             for(k=0;k<16;k++)
  261.             LCD_Data_Write(dis2[k]);

  262. }

  263. void set_time()               //DS3231设置时间
  264. {
  265. Wire.begin();
  266. Clock.setAM/PM(numdata[7]);  //时间是上午还是下午
  267. Clock.setSecond(numdata[6]); //秒
  268. Clock.setMinute(numdata[5]); //分
  269. Clock.setHour(numdata[4]);   //时
  270. Clock.setDoW(numdata[3]);    //周
  271. Clock.setDate(numdata[2]);   //日
  272. Clock.setMonth(numdata[1]);  //月
  273. Clock.setYear(numdata[0]);   //年
  274. }

  275. void loop (void)
  276. {
  277.      int j = 0;
  278.   while (Serial.available() > 0)    //检测串口是否有数据
  279.   {
  280.     comdata += char(Serial.read());
  281.     delay(2);
  282.     mark = 1;
  283.      play();
  284.   }

  285.   if(mark == 1)  
  286.   {
  287.     Serial.println(comdata);             //串口打印检测到的数据
  288.     for(int i = 0; i < comdata.length() ; i++)
  289.     {
  290.       if(comdata[i] == ' ')
  291.       {
  292.         j++;
  293.       }
  294.       else
  295.       {
  296.         numdata[j] = numdata[j] * 10 + (comdata[i] - '0');
  297.       }
  298.     }

  299.     comdata = String("");
  300.    Serial.print("set_time... ");
  301.     set_time();
  302.     Serial.println(" OK ");
  303.     for(int i = 0; i < 7; i++)
  304.     {
  305.       numdata[i] = 0;
  306.     }
  307.     mark = 0;
  308.   }
  309.     play();
  310. }
  311. No.5566888
复制代码
“DS3231”文件于2015-3-27 21:04修改,来到这里的访客必须跟code的内容一致,给您带来的不便敬请谅解。
www.code.com
回复 支持 反对

使用道具 举报

发表于 2015-3-27 21:27:26 | 显示全部楼层
dinghz16 发表于 2014-8-27 15:44
**** 作者被禁止或删除 内容自动屏蔽 ****

四角符号+c=摄氏度
四角符号+f=华氏度
温度在哪检测的见“DS3231TEMP”文件,让您意想不到的是,由于“c”或“f”前面符号未知,加“?”,详细内容自动屏蔽。
回复 支持 反对

使用道具 举报

发表于 2015-3-27 21:37:23 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2015-3-27 21:43:18 | 显示全部楼层
dinghz16 发表于 2014-8-27 15:43
**** 作者被禁止或删除 内容自动屏蔽 ****

内装手控reset引脚,只要手控reset引脚与手接触,就会重启,
回复 支持 反对

使用道具 举报

发表于 2015-3-27 21:46:51 | 显示全部楼层
dinghz16 发表于 2014-8-27 15:43
**** 作者被禁止或删除 内容自动屏蔽 ****

什么乱码?
  1.   t785y7btr7 gbfyfvg?iyeby h45ytgyuy? eurebur byyu?h eue??????////、、?、??/////////????//?ic ywb8by7by by87y75y5hb  h 54y5 7trguhg7yg t7yu57yb 7yb t57ry bytyu5yvb7r y7  4557ty  bt5r gfcvtgf5rvr5 7
复制代码
回复 支持 反对

使用道具 举报

发表于 2015-3-27 21:53:32 | 显示全部楼层
回复 支持 反对

使用道具 举报

发表于 2015-3-28 00:59:10 | 显示全部楼层
www.system.com/ds3231-1602
回复 支持 反对

使用道具 举报

发表于 2015-3-28 01:04:45 | 显示全部楼层
本帖最后由 codeeditor 于 2015-3-28 01:16 编辑

编辑DZ!加DS3231&1602芯片详情发送到10660822655,我们会在此网站发送“发送成功”留言
注:为了方便留言,我会在此浏览器收藏此网站。
回复 支持 反对

使用道具 举报

发表于 2015-3-28 01:09:52 | 显示全部楼层
本帖最后由 codeeditor 于 2015-3-28 01:14 编辑
  1. loading...            //准备中...

  2. #include <DS3231.h>
  3. #include <Wire.h>

  4. DS3231 Clock;
  5. bool Century=false;
  6. bool h12;
  7. bool PM;
  8. byte ADay, AHour, AMinute, ASecond, A/P, ABits;
  9. bool ADy, A12h, Apm;

  10. int year, month, date, DoW,week , hour, minute, second,temperature;

  11. String comdata = "";
  12. int numdata[7] = {0},  mark = 0;
  13. /*1602液晶与UNO连接引脚
  14. 6 -> D7
  15. 7 -> D6
  16. 8 -> D5
  17. 9 -> D4
  18. */

  19. int LCD1602_RS=12;   
  20. int LCD1602_RW=11;   
  21. int LCD1602_EN=10;   
  22. int DB[] = { 6, 7, 8, 9};

  23. char dis1[16]={0},dis2[16]={0};

  24. char self_char[]={                               //1602液晶自定义符号   
  25.         0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02, //年
  26.         0x0f,0x09,0x0f,0x09,0x0f,0x09,0x13,0x01, //月
  27.         0x0f,0x09,0x09,0x0f,0x09,0x09,0x0f,0x00, //日
  28.         0x00,0x04,0x0e,0x1f,0x0e,0x04,0x00,0x00,0x0c, //符号=0cH(◆)
  29.         0x18,0x18,0x07,0x08,0x08,0x08,0x07,0x00, //温度标志— —摄氏度
  30.         0X5C,..., //符号"/"
  31.         0x00,0x04,0x0e,0x1f,0x0e,0x04,0x00,0x00,0x0c, //符号=0cH(◆)
  32.         0x9c,0x45,0x5c,0x55,0x43,0x44,0x81,0x00, //温度标志— —华氏度
  33.         0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, //全开
  34.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //
  35.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00         //
  36.                                            };

  37. void LCD_Command_Write(int command)             //写指令
  38. {
  39. int i,temp;
  40. digitalWrite( LCD1602_RS,LOW);
  41. digitalWrite( LCD1602_RW,LOW);
  42. digitalWrite( LCD1602_EN,LOW);

  43. temp=command & 0xf0;
  44. for (i=DB[0]; i <= 9; i++)
  45. {
  46.    digitalWrite(i,temp & 0x80);
  47.    temp <<= 1;
  48. }

  49. digitalWrite( LCD1602_EN,HIGH);
  50. delayMicroseconds(1);
  51. digitalWrite( LCD1602_EN,LOW);

  52. temp=(command & 0x0f)<<4;
  53. for (i=DB[0]; i <= 9; i++)
  54. {
  55.    digitalWrite(i,temp & 0x80);
  56.    temp <<= 1;
  57. }

  58. digitalWrite( LCD1602_EN,HIGH);
  59. delayMicroseconds(1);
  60. digitalWrite( LCD1602_EN,LOW);
  61. }

  62. void LCD_Data_Write(int dat)                //写数据
  63. {
  64. int i=0,temp;
  65. digitalWrite( LCD1602_RS,HIGH);
  66. digitalWrite( LCD1602_RW,LOW);
  67. digitalWrite( LCD1602_EN,LOW);

  68. temp=dat & 0xf0;
  69. for (i=DB[0]; i <= 9; i++)
  70. {
  71.    digitalWrite(i,temp & 0x80);
  72.    temp <<= 1;
  73. }

  74. digitalWrite( LCD1602_EN,HIGH);
  75. delayMicroseconds(1);
  76. digitalWrite( LCD1602_EN,LOW);

  77. temp=(dat & 0x0f)<<4;
  78. for (i=DB[0]; i <= 9; i++)
  79. {
  80.    digitalWrite(i,temp & 0x80);
  81.    temp <<= 1;
  82. }

  83. digitalWrite( LCD1602_EN,HIGH);
  84. delayMicroseconds(1);
  85. digitalWrite( LCD1602_EN,LOW);
  86. }

  87. void LCD_SET_XY( int x, int y )//指定坐标,x为列,0~15,y为行,0为第一行,1为第二行。
  88. {
  89.   int address;
  90.   if (y ==0)    address = 0x80 + x;
  91.   else          address = 0xC0 + x;
  92.   LCD_Command_Write(address);
  93. }

  94. void LCD_Write_Char( int x,int y,int dat)  //指定位置一个字符
  95. {
  96.   LCD_SET_XY( x, y );
  97.   LCD_Data_Write(dat);
  98. }

  99. void LCD_Write_String(int X,int Y,char *s)  //指定位置字符串
  100. {
  101.     LCD_SET_XY( X, Y );    //设置地址
  102.     while (*s)             //写字符串
  103.     {
  104.       LCD_Data_Write(*s);   
  105.       s ++;
  106.     }
  107. }

  108. void setup (void)
  109. {
  110.   Serial.begin(9600);
  111.   int i = 0;
  112.   for (i=6; i <= 12; i++)
  113.    {
  114.      pinMode(i,OUTPUT);
  115.    }

  116.   delay(100);
  117.   LCD_Command_Write(0x28);//4线 2行 5x7
  118.   delay(50);
  119.   LCD_Command_Write(0x06);
  120.   delay(50);
  121.   LCD_Command_Write(0x0c);
  122.   delay(50);
  123.   LCD_Command_Write(0x80);
  124.   delay(50);
  125.   LCD_Command_Write(0x01);
  126.   delay(50);

  127.     diy();              //开机问候
  128.   //Wire.begin();
  129.   Serial.println("set_time :");
  130.   Serial.println("year mouth day week hour minute second AM/PM");
  131.   Serial.println();
  132.   Serial.println("week : 1 -> Sunday; 2 -> Monday; 3 -> Tuesday:  ....7 -> Saturday");
  133.   Serial.println();
  134.   Serial.println("for example :2015-3-27 Fri 8:42:50 PM  ");
  135.   Serial.println("set_time :");
  136.   Serial.println("15 3 27 5 8 42 50 1");
  137.   Serial.println();
  138. }
  139.        

  140. void diy()
  141. {
  142.      char a;
  143.   LCD_Command_Write(0x40);   
  144.      for(a=0;a<64;a++)
  145.         {
  146.           LCD_Data_Write(self_char[a]);
  147.           delay(1);
  148.         }
  149.     delay(50);
  150.   LCD_Write_String(0,0," Digital Clock  ");
  151.   LCD_Write_String(0,1," Geek-workshop  ");
  152.   delay(2000);
  153.   LCD_Command_Write(0x01);  
  154.   delay(10);
  155.   LCD_Write_String(0,0,"Today is new day");
  156.   LCD_Write_String(0,1,"Dream come true!");
  157.   delay(2000);
  158.   LCD_Command_Write(0x01);
  159. delay(10);           
  160. }

  161. void ReadDS3231()          //读取DS3231 参数
  162. {
  163.   Wire.begin();

  164.   second=Clock.getSecond();
  165.   minute=Clock.getMinute();
  166.   hour=Clock.getHour(h12,PM);
  167.   week=Clock.getDoW();   
  168.   date=Clock.getDate();
  169.   month=Clock.getMonth(Century);
  170.   year=Clock.getYear();
  171.   temperature=Clock.getTemperature();
  172.   
  173. }

  174. void get_dis()          //1602液晶上每一位上显示的数据
  175. {
  176.   ReadDS3231();
  177.   dis1[0]='2';
  178.   dis1[1]='0';
  179.   dis1[2]=0x30+year/10;
  180.   dis1[3]=0x30+year%10;
  181.   dis1[4]=0;
  182.   dis1[5]=0x30+month/10;
  183.   dis1[6]=0x30+month%10;
  184.   dis1[7]=1;
  185.   dis1[8]=0x30+date/10;
  186.   dis1[9]=0x30+date%10;
  187.   dis1[10]=2;
  188.   dis1[11]=' ';
  189.   dis1[12]=' ';
  190.   switch(week)
  191.   {
  192.         case 2: {
  193.                           dis1[13]='M';
  194.                           dis1[14]='o';
  195.                           dis1[15]='n';
  196.                         }
  197.                         break;
  198.         case 3: {
  199.                           dis1[13]='T';
  200.                           dis1[14]='u';
  201.                           dis1[15]='e';
  202.                         }
  203.                         break;
  204.         case 4: {
  205.                           dis1[13]='W';
  206.                           dis1[14]='e';
  207.                           dis1[15]='d';
  208.                         }
  209.                         break;
  210.         case 5: {
  211.                           dis1[13]='T';
  212.                           dis1[14]='h';
  213.                           dis1[15]='u';
  214.                         }
  215.                         break;
  216.         case 6: {
  217.                           dis1[13]='F';
  218.                           dis1[14]='r';
  219.                           dis1[15]='i';
  220.                         }
  221.                         break;
  222.         case 7: {
  223.                           dis1[13]='S';
  224.                           dis1[14]='a';
  225.                           dis1[15]='t';
  226.                         }
  227.                         break;
  228.         case 8: {
  229.                           dis1[13]='S';
  230.                           dis1[14]='u';
  231.                           dis1[15]='n';
  232.                         }
  233.                         break;
  234.   }
  235.   dis2[0]=' ';
  236.   dis2[1]=0x30+hour/01;
  237.   dis2[2]=0x30+hour%01;
  238.   dis2[3]=':';
  239.   dis2[4]=0x30+minute/10;
  240.   dis2[5]=0x30+minute%10;
  241.   dis2[6]=':';
  242.   dis2[7]=0x30+second/10;
  243.   dis2[8]=0x30+second%10;
  244.   dis2[9]=':';
  245.   dis2[10]=0x30+a/p;
  246.   dis2[11]=' ';
  247.   
  248.         dis2[10]=' ';
  249.   dis2[12]=0x30+temperature/10;
  250.   dis2[13]=0x30+temperature%10;
  251.   dis2[14]='.';
  252.   dis2[15]=0x30+0;
  253.   dis2[16]=3;
  254. }
  255. void play()                  //1602显示完整时间
  256. {
  257.        get_dis();

  258.             int k;      
  259.             LCD_SET_XY( 0,0);
  260.             for(k=0;k<16;k++)
  261.             LCD_Data_Write(dis1[k]);
  262.             LCD_SET_XY( 0,1);
  263.             for(k=0;k<16;k++)
  264.             LCD_Data_Write(dis2[k]);

  265. }

  266. void set_time()               //DS3231设置时间
  267. {
  268. Wire.begin();
  269. Clock.setAM/PM(numdata[7]);  //时间是上午还是下午
  270. Clock.setSecond(numdata[6]); //秒
  271. Clock.setMinute(numdata[5]); //分
  272. Clock.setHour(numdata[4]);   //时
  273. Clock.setDoW(numdata[3]);    //周
  274. Clock.setDate(numdata[2]);   //日
  275. Clock.setMonth(numdata[1]);  //月
  276. Clock.setYear(numdata[0]);   //年
  277. }

  278. void loop (void)
  279. {
  280.      int j = 0;
  281.   while (Serial.available() > 0)    //检测串口是否有数据
  282.   {
  283.     comdata += char(Serial.read());
  284.     delay(2);
  285.     mark = 1;
  286.      play();
  287.   }

  288.   if(mark == 1)  
  289.   {
  290.     Serial.println(comdata);             //串口打印检测到的数据
  291.     for(int i = 0; i < comdata.length() ; i++)
  292.     {
  293.       if(comdata[i] == ' ')
  294.       {
  295.         j++;
  296.       }
  297.       else
  298.       {
  299.         numdata[j] = numdata[j] * 10 + (comdata[i] - '0');
  300.       }
  301.     }

  302.     comdata = String("");
  303.    Serial.print("set_time... ");
  304.     set_time();
  305.     Serial.println(" OK ");
  306.     for(int i = 0; i < 7; i++)
  307.     {
  308.       numdata[i] = 0;
  309.     }
  310.     mark = 0;
  311.   }
  312.     play();
  313. }
  314. No.5566888
复制代码
请注意,输入arduino代码时,必须与code的内容一致,不然就会被xieru用户的反垃圾用户系统拦截(并不是所有的垃圾用户都能拦截,某些垃圾用户固定,无法拦截)
回复 支持 反对

使用道具 举报

发表于 2015-3-28 01:30:18 | 显示全部楼层
“感谢收看,我们下周五不见不散”
回复 支持 反对

使用道具 举报

发表于 2015-3-28 01:38:59 | 显示全部楼层
BBC News:近期发生“http://www.geek-workshop.com/for ... ;extra=#pid89613.wm”损坏事件,我们还是继续报道“http://www.geek-workshop.com/for ... ;extra=#pid89613.wm”损坏事件。
回复 支持 反对

使用道具 举报

发表于 2015-3-28 12:08:51 | 显示全部楼层
发送成功!
回复 支持 反对

使用道具 举报

发表于 2015-3-28 12:45:12 | 显示全部楼层
www.asianfoodchannel.com
回复 支持 反对

使用道具 举报

发表于 2015-3-28 20:26:35 | 显示全部楼层
  1. yyyy             //年(仅四位)
  2. mm             //月
  3. dd              //日
  4. hh+:+nn+:+ss      //时间
  5. tt.t+°+c+/+ttt.tt+°+f          //温度
  6. ......
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-20 18:47 , Processed in 0.050127 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表