极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12958|回复: 9

双328p 初版 完结

[复制链接]
发表于 2014-11-13 21:06:12 | 显示全部楼层 |阅读模式
本帖最后由 hi55234 于 2014-11-16 20:54 编辑

起因:
328p的程序空间30,720字节,作为菜鸟,只会用现成的库,可这库加不了几个,空间就告罄了·········悲剧啊·····

所以,果断双芯走起

思路如下:



----------------------------------------------
程序见 8、9、10楼

纯蓝牙控制:

控制命令暂时4条
$AT,A*78
$AT,B*7B
$AT,C*7A
$AT,D*7D

分别设定:
普通GPX记录模式、
蓝牙GPS 输出模式 、
1602向前翻页(仅普通模式有效)、
1602向后翻译(仅普通模式有效)

要说有啥特别的话,估计就是命令都用了异或校验~~~装作很稳定的样子{:soso_e113:}

要说有啥问题的话:
1、SD卡状态获取了,但没显示,出来~~~这个坑爹~~~(暂时没想到怎么显示比较好)
2、在蓝牙模式下,真心不知道这个GPS定位没有,因为没做这块的定义

本帖子中包含更多资源

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

x
回复

使用道具 举报

发表于 2014-11-13 21:09:07 | 显示全部楼层
2560 欢迎你
回复 支持 反对

使用道具 举报

发表于 2014-11-13 22:45:57 | 显示全部楼层
你的1602不会用i2c接口么
回复 支持 反对

使用道具 举报

发表于 2014-11-14 08:39:37 | 显示全部楼层
@microduino 有个双核呢
回复 支持 反对

使用道具 举报

发表于 2014-11-14 08:48:06 | 显示全部楼层
单独用个328驱动1602呗
回复 支持 反对

使用道具 举报

发表于 2014-11-14 17:45:59 | 显示全部楼层
IIC的oled,只需一根pin,物美价廉。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-11-15 19:45:22 | 显示全部楼层
本帖最后由 hi55234 于 2014-11-16 21:32 编辑

基本思路:
A   提取GPS信息,并通过串口把所提取的信息发送给B,B通过串口显示出来
A   通过提取的GPS信息,在SD卡中生成GPX文件
B   通过传感器采集到的温度、湿度啥的信息,通过串口发送给A,A把相关信息加在GPX文件当中,完成地点、环境的对应
B  负责蓝牙互动啥的,毕竟A已经没程序空间了,而且内存也快没了


实践方式:仿GPS的字符串:
$起始符
*结束符
带2位异或检验,以保证信息的正确与有效










本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-11-15 20:11:20 | 显示全部楼层
本帖最后由 hi55234 于 2014-11-16 20:31 编辑

A的EEPROM写入程序


  1. #include<EEPROM.h>

  2. void setup() {

  3. Serial.begin(9600);

  4. EEPROM.write(0,0);
  5. EEPROM.write(1,0);
  6. EEPROM.write(2,10);
  7. EEPROM.write(3,0);
  8. EEPROM.write(4,0);
  9. EEPROM.write(5,0);
  10. EEPROM.write(6,0);
  11. EEPROM.write(7,0);
  12. EEPROM.write(8,1);
  13. EEPROM.write(9,1);



  14. char TrackA0[27] = "<?xml version="1.0"?><gpx>";
  15. for(int i=0;i<27;i++) EEPROM.write(i+50,TrackA0[i]);


  16. char TrackA1[12] = "<name>Track";
  17. for(int i=0;i<12;i++) EEPROM.write(i+77,TrackA1[i]);

  18. char TrackA2[21] = "</name><trk><trkseg>";
  19. for(int i=0;i<21;i++) EEPROM.write(i+89,TrackA2[i]);


  20. char TrackA3[13]= "<trkpt lat="";
  21. for(int i=0;i<13;i++) EEPROM.write(i+110,TrackA3[i]);

  22. char TrackA4[8]= "" lon="";
  23.    for(int i=0;i<8;i++) EEPROM.write(i+123,TrackA4[i]);


  24. char TrackA5[9]= ""><time>";
  25.   for(int i=0;i<9;i++) EEPROM.write(i+131,TrackA5[i]);


  26. char TrackA6[17]= "Z</time></trkpt>";
  27. for(int i=0;i<17;i++) EEPROM.write(i+140,TrackA6[i]);


  28. char TrackA7[16] = "</trkseg></trk>";
  29.     for(int i=0;i<16;i++) EEPROM.write(i+158,TrackA7[i]);


  30. char TrackA8[7] = "</gpx>";
  31.     for(int i=0;i<7;i++) EEPROM.write(i+174,TrackA8[i]);


  32. Serial.println("EEPROM Write is completed , Please re-download new program");


  33. }



  34. void loop()
  35. {

  36. }
复制代码





回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-11-15 23:50:22 | 显示全部楼层
本帖最后由 hi55234 于 2014-11-16 20:40 编辑

A的程序


  1. #include <SoftwareSerial.h>
  2. SoftwareSerial gps(8, 9);
  3. char tempx[12];
  4. char tempxB[12];
  5. char GPRMC[95];
  6. char GPGGA[95];
  7. char MS[90];
  8. char AT[20];
  9. int gpschangertest;
  10. boolean gpschanger;
  11. int weiduA;
  12. unsigned long weiduB,weiduC;
  13. int jingduA;
  14. unsigned long jingduB,jingduC;

  15. boolean GPGGAget=0;
  16. boolean GPRMCget=0;
  17. boolean ATget=0;
  18. boolean MSget=0;

  19. unsigned long gpstimes;
  20. boolean konghangpanduan;
  21. boolean konghangpanduanB;
  22. boolean gpsshuchuqiehuanB;
  23. int jsq1=0;
  24. int jsq2=0;
  25. int jsq3=0;
  26. int jsq4=0;
  27. int jsq5=0;
  28. int jsq6=0;
  29. int jsq7=0;
  30. int GPGGAlong=0;
  31. int GPRMClong=0;
  32. int ATlong=0;
  33. int MSlong=0;
  34. int asllong=0;
  35. int yawlong=0;
  36. int sudulong=0;
  37. int chuankouzhuanyong;
  38. boolean jiaoyanjieguoA,jiaoyanjieguoC;
  39. float sudu;
  40. String jianyan="";
  41. int yihuoyunsuan;

  42. boolean dingweiok=0;
  43. /*---------------------GPS end---------------------------------*/
  44. int gpsshuchuqiehuanA;

  45.   
  46. #include<EEPROM.h>
  47. int EEPROMvalue;


  48. #include <SD.h>

  49. const int chipSelect = 10;

  50. boolean gpxstart;
  51. boolean gpxmiddleA;
  52. boolean gpxmiddleB=1;
  53. boolean gpxendA;
  54. boolean gpxendB;

  55. int gpxjilujiangeA;
  56. int gpxjilujiangeB=256;

  57. int gpxjiludianshu;
  58. int gpxjiluguijishu;


  59. char TrackAL[4]="000";
  60. char TrackAN[6]="00000";

  61. char TrackB0[8]="-0000.0";
  62. char TrackB1[11]="00.0000000";
  63. char TrackB2[12]="000.0000000";
  64. char TrackB4[20]="2000-00-00T00:00:00";
  65. char TrackB5[8]="0000.00";
  66. char TrackB6[7]="000.00";

  67. char SDzhuangtai[7]="SDwait";

  68. boolean weiduxuweitiao=0;
  69. boolean jingduxuweitiao=0;
  70. int weiduzhanwei,jingduzhanwei;





  71. unsigned long fentodu;
  72. int Linenumber;
  73. int Tracknumber;

  74. void setup() {





  75. Serial.begin(9600);
  76. gps.begin(9600);
  77.   
  78. EEPROMvalue= EEPROM.read(0);
  79. if(EEPROMvalue==0)gpsshuchuqiehuanB=0;
  80. else gpsshuchuqiehuanB=1;


  81.   
  82. EEPROMvalue= EEPROM.read(1);
  83. if(EEPROMvalue==255) EEPROMvalue=0;

  84. Linename();
  85. Trackname();


  86.   EEPROMvalue= EEPROM.read(2);
  87. if(EEPROMvalue==0)gpxjilujiangeA=1;
  88. else gpxjilujiangeA=EEPROMvalue;



  89.   EEPROMvalue= EEPROM.read(3);
  90.   gpxjiludianshu=EEPROMvalue*25;
  91.    
  92.   EEPROMvalue++;
  93.   EEPROM.write(3, EEPROMvalue);



  94.   pinMode(10, OUTPUT);


  95.   if (!SD.begin(chipSelect)) {
  96.   Serial.println("$MS,SD Card failed! ,*xx");
  97.     return;
  98.   }
  99. }

  100. void loop() {
  101. while (Serial.available() > 0) {

  102. gpstimes=millis();
  103. konghangpanduanB=0;
  104. if(ATget){
  105. AT[chuankouzhuanyong]=Serial.read();
  106. if(AT[chuankouzhuanyong-2]=='*'){
  107. ATlong=chuankouzhuanyong;
  108. ATget=0;
  109. chuankouzhuanyong=0;
  110. }else if(chuankouzhuanyong<18)chuankouzhuanyong++;
  111. }else if(MSget){
  112. MS[chuankouzhuanyong]=Serial.read();
  113. if(MS[chuankouzhuanyong-2]=='*'){
  114. MSlong=chuankouzhuanyong;
  115. MSget=0;
  116. chuankouzhuanyong=0;
  117. }else if(chuankouzhuanyong<88)chuankouzhuanyong++;
  118. }else{
  119. tempxB[chuankouzhuanyong]=Serial.read();
  120. if(chuankouzhuanyong<3)chuankouzhuanyong++;
  121. }

  122. if(chuankouzhuanyong==3){

  123. if(tempxB[1]=='A' && tempxB[2]=='T'){
  124. ATget=1;
  125. MSget=0;
  126. for(int col=0;col<20;col++)AT[col]=0;
  127. for(int col=0;col<3;col++)AT[col]=tempxB[col];
  128. for(int col=0;col<3;col++)tempxB[col]=0;
  129. }else if(tempxB[1]=='M' && tempxB[2]=='S'){
  130. MSget=1;
  131. ATget=0;
  132. for(int col=0;col<90;col++)MS[col]=0;
  133. for(int col=0;col<3;col++)MS[col]=tempxB[col];
  134. for(int col=0;col<3;col++)tempxB[col]=0;
  135. }else{
  136. for(int col=0;col<2;col++)tempxB[col]=tempxB[col+1];
  137. chuankouzhuanyong=2;
  138. }

  139. }

  140. }

  141. ruanchuankou();
  142. if(millis()-gpstimes>10 && !konghangpanduan){
  143. konghangpanduan=1;
  144. gpxjilujiangeB++;
  145. gpsdechuli();

  146. if(jiaoyanjieguoA)jiexiGPGGA();
  147. if(jiaoyanjieguoC)jiexiGPRMC();


  148. if(dingweiok) {
  149. gpschanger=0;

  150. if(gpxjilujiangeB>gpxjilujiangeA){
  151. gpxjilujiangeB=0;
  152. gpxjiludianshu++;

  153. if(gpxjiludianshu%25==0){
  154. EEPROMvalue= EEPROM.read(3);
  155. EEPROMvalue++;

  156. if(EEPROMvalue>108){
  157. EEPROMvalue=0;
  158. EEPROM.write(3, 0);
  159. gpxjiludianshu=0;

  160. EEPROM.write(8,0);
  161. EEPROM.write(9,0);



  162. }else {
  163. EEPROM.write(3, EEPROMvalue);
  164. }

  165. }

  166. sdcaozuo();
  167. }

  168. }


  169. if(dingweiok && !gpsshuchuqiehuanB){

  170. /*
  171. $MS,TrackAL,TrackAN,TrackB1,TrackB2,TrackB4,TrackB0,TrackB5,TrackB6,SDzhuangtai*XX
  172. $MS,000,00000,00.0000000,000.0000000,2000-00-00T00:00:00,-0000.0,0000.00,000.00,SDGood,*XX
  173. ----4---8----14----------25----------37------------------57-----后面就是动态的了
  174. 极限长度90,最小数组长度81
  175. */
  176. for(int col=0;col<95;col++)GPRMC[col]=0;
  177. GPRMC[0]='$';
  178. GPRMC[1]='M';
  179. GPRMC[2]='S';
  180. GPRMC[3]=44;
  181. memcpy(GPRMC+4,TrackAL,3);
  182. GPRMC[7]=44;
  183. memcpy(GPRMC+8,TrackAN,5);
  184. GPRMC[13]=44;
  185. memcpy(GPRMC+14,TrackB1,10);
  186. GPRMC[24]=44;
  187. memcpy(GPRMC+25,TrackB2,11);
  188. GPRMC[36]=44;
  189. memcpy(GPRMC+37,TrackB4,19);
  190. GPRMC[56]=44;
  191. memcpy(GPRMC+57,TrackB0,asllong);
  192. GPRMC[57+asllong]=44;
  193. memcpy(GPRMC+58+asllong,TrackB5,sudulong);
  194. GPRMC[58+asllong+sudulong]=44;
  195. memcpy(GPRMC+59+asllong+sudulong,TrackB6,yawlong);
  196. GPRMC[59+asllong+sudulong+yawlong]=44;
  197. memcpy(GPRMC+60+asllong+sudulong+yawlong,SDzhuangtai,6);
  198. GPRMC[66+asllong+sudulong+yawlong]=44;
  199. GPRMC[67+asllong+sudulong+yawlong]=42;
  200. for(int col=1;col<67+asllong+sudulong+yawlong;col++){
  201. if(col==1)yihuoyunsuan=GPRMC[col];
  202. else yihuoyunsuan=yihuoyunsuan ^ GPRMC[col];
  203. }
  204. if(yihuoyunsuan==0){
  205. jianyan="00";
  206. }else if(yihuoyunsuan>15){
  207. jianyan = String(yihuoyunsuan,HEX);
  208. }else{
  209. jianyan = "0";
  210. jianyan += String(yihuoyunsuan,HEX);
  211. }
  212. jianyan.toUpperCase();
  213. GPRMC[68+asllong+sudulong+yawlong]=jianyan[0];
  214. GPRMC[69+asllong+sudulong+yawlong]=jianyan[1];
  215. jianyan="";
  216. Serial.println(GPRMC);
  217. }



  218. for(int col=0;col<95;col++)GPRMC[col]=0;
  219. for(int col=0;col<95;col++)GPGGA[col]=0;
  220. for(int col=0;col<12;col++)tempx[col]=0;
  221. jsq1=0;
  222. GPGGAget=0;
  223. GPRMCget=0;
  224. }

  225. if(millis()-gpstimes>10 && !konghangpanduanB){
  226. konghangpanduanB=1;

  227.        
  228. for(int col=1;col<ATlong-2;col++){
  229. if(col==1)yihuoyunsuan=AT[col];
  230. else yihuoyunsuan=yihuoyunsuan ^ AT[col];
  231. }
  232. if(yihuoyunsuan==0){
  233. jianyan="00";
  234. }else if(yihuoyunsuan>15){
  235. jianyan = String(yihuoyunsuan,HEX);
  236. }else{
  237. jianyan = "0";
  238. jianyan += String(yihuoyunsuan,HEX);
  239. }
  240. jianyan.toUpperCase();
  241.         if(jianyan[0]==AT[ATlong-1] && jianyan[1]==AT[ATlong] ){

  242.        



  243. if(AT[4]=='A'){
  244.        
  245.        
  246.                 if(gpsshuchuqiehuanB){
  247.                 gpsshuchuqiehuanB=0;
  248.                  EEPROM.write(0,0);
  249.                 }
  250.                
  251. }else if(AT[4]=='B'){
  252.        
  253.                 if(!gpsshuchuqiehuanB){
  254.                 gpsshuchuqiehuanB=1;
  255.                  EEPROM.write(0,1);
  256.                 }
  257. }

  258. for(int col=0;col<20;col++)AT[col]=0;
  259. ATlong=0;
  260. }else {
  261. for(int col=0;col<20;col++)AT[col]=0;
  262. ATlong=0;
  263. chuankouzhuanyong=0;
  264. ATget=0;
  265. }
  266. jianyan="";
  267. for(int col=1;col<MSlong-2;col++){
  268. if(col==1)yihuoyunsuan=MS[col];
  269. else yihuoyunsuan=yihuoyunsuan ^ MS[col];
  270. }
  271. if(yihuoyunsuan==0){
  272. jianyan="00";
  273. }else if(yihuoyunsuan>15){
  274. jianyan = String(yihuoyunsuan,HEX);
  275. }else{
  276. jianyan = "0";
  277. jianyan += String(yihuoyunsuan,HEX);
  278. }
  279. jianyan.toUpperCase();
  280. if(jianyan[0]==MS[MSlong-1] && jianyan[1]==MS[MSlong] ){



  281. }else {
  282. for(int col=0;col<90;col++)MS[col]=0;
  283. MSlong=0;
  284. chuankouzhuanyong=0;
  285. MSget=0;
  286. }
  287. jianyan="";

  288. }
  289. }


  290. void ruanchuankou()
  291. {

  292. while (gps.available() > 0) {
  293. gpstimes=millis();
  294. konghangpanduan=0;

  295. if(GPRMCget){
  296. GPRMC[jsq1]=gps.read();
  297. if(gpsshuchuqiehuanB)Serial.print(GPRMC[jsq1]);
  298. if(GPRMC[jsq1-3]=='*'){
  299. GPRMClong=jsq1;
  300. GPRMCget=0;
  301. jsq1=0;
  302. }else if(jsq1<93)jsq1++;

  303. }else if(GPGGAget){
  304. GPGGA[jsq1]=gps.read();
  305. if(gpsshuchuqiehuanB)Serial.print(GPGGA[jsq1]);
  306. if(GPGGA[jsq1-3]=='*'){
  307. GPGGAlong=jsq1;
  308. GPGGAget=0;
  309. jsq1=0;
  310. }else if(jsq1<93)jsq1++;

  311. }else{
  312. tempx[jsq1]=gps.read();
  313. if(gpsshuchuqiehuanB)Serial.print(tempx[jsq1]);
  314. if(jsq1<6)jsq1++;
  315. }

  316. if(jsq1==6){


  317. if(tempx[4]=='M' && tempx[5]=='C'){
  318. GPRMCget=1;
  319. GPGGAget=0;
  320. for(int col=0;col<6;col++)GPRMC[col]=tempx[col];
  321. for(int col=0;col<6;col++)tempx[col]=0;
  322. }else if(tempx[jsq1-2]=='G' && tempx[jsq1-1]=='A'){
  323. GPGGAget=1;
  324. GPRMCget=0;
  325. for(int col=0;col<6;col++)GPGGA[col]=tempx[col];
  326. for(int col=0;col<6;col++)tempx[col]=0;
  327. }else{
  328. for(int col=0;col<5;col++)tempx[col]=tempx[col+1];
  329. jsq1=5;
  330. }

  331. }

  332. }

  333. }

  334. void gpsdechuli()
  335. {
  336. for(int col=1;col<GPRMClong-3;col++){
  337. if(col==1)yihuoyunsuan=GPRMC[col];
  338. else yihuoyunsuan=yihuoyunsuan ^ GPRMC[col];
  339. }
  340. if(yihuoyunsuan==0){
  341. jianyan="00";
  342. }else if(yihuoyunsuan>15){
  343. jianyan = String(yihuoyunsuan,HEX);
  344. }else{
  345. jianyan = "0";
  346. jianyan += String(yihuoyunsuan,HEX);
  347. }
  348. jianyan.toUpperCase();
  349. if(jianyan[0]==GPRMC[GPRMClong-2] && jianyan[1]==GPRMC[GPRMClong-1] ){
  350. jiaoyanjieguoC=1;
  351. }else{
  352. jiaoyanjieguoC=0;
  353. for(int col=0;col<95;col++)GPRMC[col]=0;
  354. GPRMClong=0;
  355. jsq1=0;
  356. GPRMCget=0;
  357. }
  358. jianyan="";


  359. for(int col=1;col<GPGGAlong-3;col++){
  360. if(col==1)yihuoyunsuan=GPGGA[col];
  361. else yihuoyunsuan=yihuoyunsuan ^ GPGGA[col];
  362. }
  363. if(yihuoyunsuan==0){
  364. jianyan="00";
  365. }else if(yihuoyunsuan>15){
  366. jianyan = String(yihuoyunsuan,HEX);
  367. }else{
  368. jianyan = "0";
  369. jianyan += String(yihuoyunsuan,HEX);
  370. }
  371. jianyan.toUpperCase();
  372. if(jianyan[0]==GPGGA[GPGGAlong-2] && jianyan[1]==GPGGA[GPGGAlong-1] ){
  373. jiaoyanjieguoA=1;
  374. }else{
  375. jiaoyanjieguoA=0;
  376. for(int col=0;col<90;col++)GPGGA[col]=0;
  377. GPGGAlong=0;
  378. jsq1=0;
  379. GPGGAget=0;
  380. }

  381. jianyan="";

  382. }


  383. void jiexiGPGGA()
  384. {

  385.    jsq2=0;
  386.    jsq3=0;
  387.    jsq4=0;
  388.    jsq5=0;


  389.     for(int col=1;col<GPGGAlong-3;col++){
  390.      if(GPGGA[col]==',')jsq2++;
  391.    if(jsq2==10){
  392.    jsq3=col;
  393.    col=GPGGAlong-3;
  394.    }
  395.    
  396.    
  397.    if(jsq2<9)jsq4=col;
  398.    
  399.    if(jsq2<7)jsq5=col;
  400.    
  401.    }
  402.    
  403.    
  404.    if(GPGGA[jsq5]==49)dingweiok=1;
  405.    else dingweiok=0;
  406.    
  407.    
  408. for(int col=0;col<8;col++)TrackB0[col]=0;
  409. memcpy(TrackB0,GPGGA+jsq4+2, jsq3-jsq4-2);
  410. asllong=jsq3-jsq4-2;

  411. }


  412. void jiexiGPRMC()
  413. {

  414.    jsq2=0;
  415.    jsq3=0;
  416.    jsq4=0;
  417.    jsq5=0;
  418.    jsq6=0;
  419.    jsq7=0;
  420.    
  421.     for(int col=1;col<GPRMClong-3;col++){
  422.      if(GPRMC[col]==',')jsq2++;
  423.    if(jsq2==9){
  424.    jsq3=col;
  425.    col=GPRMClong-3;
  426.    }
  427.    
  428.    if(jsq2<8)jsq4=col;
  429.    if(jsq2<6)jsq5=col;
  430.    if(jsq2<4)jsq6=col;
  431.    if(jsq2<2)jsq7=col;
  432.    }


  433.   if(GPRMC[jsq7+2]=='A')UTCtime();


  434. if(dingweiok){
  435. jingweiduchuli();
  436. hangxiangyusudu();

  437. }else {
  438.   weiduA=0;
  439.   weiduB=0;
  440.   weiduC=0;
  441.   jingduA=0;
  442.   jingduB=0;
  443.   jingduC=0;
  444. }


  445. }


  446.   void UTCtime()
  447. {



  448. TrackB4[11]=GPRMC[7];
  449. TrackB4[12]=GPRMC[8];


  450.   TrackB4[14]=GPRMC[9];
  451. TrackB4[15]=GPRMC[10];

  452.   TrackB4[17]=GPRMC[11];
  453. TrackB4[18]=GPRMC[12];

  454.   TrackB4[8]=GPRMC[jsq3+1];
  455. TrackB4[9]=GPRMC[jsq3+2];

  456.   TrackB4[5]=GPRMC[jsq3+3];
  457. TrackB4[6]=GPRMC[jsq3+4];

  458.   TrackB4[2]=GPRMC[jsq3+5];
  459. TrackB4[3]=GPRMC[jsq3+6];

  460. }

  461. void jingweiduchuli()
  462. {

  463.   
  464. for(int col=0;col<12;col++)tempx[col]=0;
  465. memcpy(tempx,GPRMC+jsq7+4, 2);
  466. jianyan =tempx;
  467. gpschangertest=jianyan.toInt();
  468. if(weiduA!=gpschangertest){
  469. weiduA=gpschangertest;
  470. gpschanger=1;
  471. }


  472. if(GPRMC[jsq6+2]==83)weiduxuweitiao=1;
  473. if(GPRMC[jsq5+2]==87)jingduxuweitiao=1;


  474. memcpy(TrackB1,GPRMC+jsq7+4, 2);

  475. if(gpschangertest<10) {
  476. TrackB1[0]=32;
  477. weiduzhanwei=1;
  478. }else weiduzhanwei=2;


  479. for(int col=0;col<12;col++)tempx[col]=0;

  480. memcpy(tempx,GPRMC+jsq7+6, 2);
  481. jianyan =tempx;
  482. gpschangertest=jianyan.toInt();
  483. if(weiduB!=gpschangertest){
  484. weiduB=gpschangertest;
  485. gpschanger=1;
  486. }



  487.   for(int col=0;col<12;col++)tempx[col]=0;

  488. memcpy(tempx,GPRMC+jsq7+9, 4);
  489. if(jsq6-jsq7==12) memcpy(tempx,GPRMC+jsq7+9, 4);
  490. else if(jsq6-jsq7==13)memcpy(tempx,GPRMC+jsq7+9, 5);


  491. jianyan =tempx;
  492. gpschangertest=jianyan.toInt();
  493. if(weiduC!=gpschangertest){
  494. weiduC=gpschangertest;
  495. gpschanger=1;
  496. }

  497. fentodu=weiduB*100000+weiduC*10;
  498. fentodu=fentodu/6;

  499.   for(int col=0;col<12;col++)tempx[col]=0;
  500. dtostrf(fentodu,6,0,tempx);


  501. if(fentodu>99999){
  502. memcpy(TrackB1+3,tempx, 6);
  503. }else if(fentodu>9999){
  504. TrackB1[3]=48;
  505.   memcpy(TrackB1+4,tempx, 5);
  506. }else if(fentodu>999){
  507. TrackB1[3]=48;
  508. TrackB1[4]=48;
  509.   memcpy(TrackB1+5,tempx, 4);

  510. }else if(fentodu>99){
  511. TrackB1[3]=48;
  512. TrackB1[4]=48;
  513. TrackB1[5]=48;
  514.   memcpy(TrackB1+6,tempx, 3);

  515. }else if(fentodu>9){
  516. TrackB1[3]=48;
  517. TrackB1[4]=48;
  518. TrackB1[5]=48;
  519. TrackB1[6]=48;
  520.   memcpy(TrackB1+7,tempx, 2);
  521. }else{
  522. TrackB1[3]=48;
  523. TrackB1[4]=48;
  524. TrackB1[5]=48;
  525. TrackB1[6]=48;
  526. TrackB1[7]=48;
  527.   memcpy(TrackB1+8,tempx, 1);

  528. }




  529. if(weiduxuweitiao){
  530. weiduxuweitiao=0;

  531. if(weiduzhanwei==2){


  532.    for(int col=0;col<12;col++)tempx[col]=0;
  533. tempx[0]=45;
  534. memcpy(tempx+1,TrackB1, 9);
  535. memcpy(TrackB1,tempx, 10);

  536. }else{

  537.   TrackB1[0]=45;

  538. }

  539. }




  540. for(int col=0;col<12;col++)tempx[col]=0;

  541.    memcpy(tempx,GPRMC+jsq6+4, 3);
  542. jianyan =tempx;
  543. gpschangertest=jianyan.toInt();
  544. if(jingduA!=gpschangertest){
  545. jingduA=gpschangertest;
  546. gpschanger=1;
  547. }


  548.   

  549.   memcpy(TrackB2,GPRMC+jsq6+4, 3);
  550. jingduzhanwei=3;

  551. if(gpschangertest<100) {
  552. TrackB2[0]=32;
  553. jingduzhanwei=2;
  554. }

  555. if(gpschangertest<10) {
  556. TrackB2[1]=32;
  557. jingduzhanwei=1;
  558. }

  559. for(int col=0;col<12;col++)tempx[col]=0;

  560. memcpy(tempx,GPRMC+jsq6+7, 3);
  561. jianyan =tempx;
  562. gpschangertest=jianyan.toInt();
  563. if(jingduB!=gpschangertest){
  564. jingduB=gpschangertest;
  565. gpschanger=1;
  566. }

  567.   for(int col=0;col<12;col++)tempx[col]=0;

  568. if(jsq5-jsq6==13)memcpy(tempx,GPRMC+jsq6+10, 4);
  569. else if(jsq5-jsq6==14)memcpy(tempx,GPRMC+jsq6+10, 5);

  570. jianyan =tempx;
  571. gpschangertest=jianyan.toInt();
  572. if(jingduC!=gpschangertest){
  573. jingduC=gpschangertest;
  574. gpschanger=1;
  575. }

  576. jianyan="";

  577.   fentodu=jingduB*100000+jingduC*10;
  578. fentodu=fentodu/6;

  579.   for(int col=0;col<12;col++)tempx[col]=0;
  580. dtostrf(fentodu,6,0,tempx);



  581. if(fentodu>99999){
  582. memcpy(TrackB2+4,tempx, 6);
  583. }else if(fentodu>9999){
  584. TrackB2[4]=48;
  585.   memcpy(TrackB2+5,tempx, 5);
  586. }else if(fentodu>999){
  587. TrackB2[4]=48;
  588. TrackB2[5]=48;
  589.   memcpy(TrackB2+6,tempx, 4);

  590. }else if(fentodu>99){
  591. TrackB2[4]=48;
  592. TrackB2[5]=48;
  593. TrackB2[6]=48;
  594.   memcpy(TrackB2+7,tempx, 3);

  595. }else if(fentodu>9){
  596. TrackB2[4]=48;
  597. TrackB2[5]=48;
  598. TrackB2[6]=48;
  599. TrackB2[7]=48;
  600.   memcpy(TrackB2+8,tempx, 2);
  601. }else{
  602. TrackB2[4]=48;
  603. TrackB2[5]=48;
  604. TrackB2[6]=48;
  605. TrackB2[7]=48;
  606. TrackB2[8]=48;
  607.   memcpy(TrackB2+9,tempx, 1);

  608. }




  609. if(jingduxuweitiao){
  610. jingduxuweitiao=0;

  611. if(jingduzhanwei==3){


  612.    for(int col=0;col<12;col++)tempx[col]=0;
  613. tempx[0]=45;
  614. memcpy(tempx+1,TrackB2, 10);
  615. memcpy(TrackB2,tempx, 11);

  616. }else if(jingduzhanwei==2){

  617.   TrackB2[0]=45;

  618. }else{
  619. TrackB2[1]=45;
  620. }

  621. }


  622. }


  623. void hangxiangyusudu()
  624. {

  625. for(int col=0;col<12;col++)tempx[col]=0;
  626. memcpy(tempx,GPRMC+jsq5+4,jsq4-jsq5-3);

  627. for(int col=0;col<jsq4-jsq5-3;col++){
  628. if(tempx[col]==46){


  629. if(col==1)fentodu=(tempx[0]-48)*1000;
  630. else if(col==2)fentodu=(tempx[0]-48)*10000+(tempx[1]-48)*1000;
  631. else if(col==3)fentodu=(tempx[0]-48)*100000+(tempx[1]-48)*10000+(tempx[2]-48)*1000;


  632. if(jsq4-jsq5-col==5)fentodu=fentodu+(tempx[col+1]-48)*100;
  633. else if(jsq4-jsq5-col==6)fentodu=fentodu+(tempx[col+1]-48)*100+(tempx[col+2]-48)*10;
  634. else if(jsq4-jsq5-col==7)fentodu=fentodu+(tempx[col+1]-48)*100+(tempx[col+2]-48)*10+tempx[col+3]-48;



  635. fentodu=fentodu*1852*0.0001;
  636. col=jsq4-jsq5-3;
  637. }
  638. }

  639. sudu=fentodu*0.01;
  640. for(int col=0;col<8;col++)TrackB5[col]=0;
  641. dtostrf(sudu,1,2,TrackB5);
  642. if(sudu*0.001>1)sudulong=7;
  643. else if(sudu*0.01>1)sudulong=6;
  644. else if(sudu*0.1>1)sudulong=5;
  645. else sudulong=4;

  646. for(int col=0;col<7;col++)TrackB6[col]=0;
  647. memcpy(TrackB6,GPRMC+jsq4+2, jsq3-jsq4-2);
  648. yawlong=jsq3-jsq4-2;


  649. }


  650.   void sdcaozuo()
  651. {




  652.   for(int col=0;col<12;col++)tempx[col]=0;

  653.   tempx[0]='L';
  654.   tempx[1]='i';
  655.   tempx[2]='n';
  656.   tempx[3]='e';
  657.   memcpy(tempx+4,TrackAL,3);
  658.   tempx[7]='.';
  659.   tempx[8]='g';
  660.   tempx[9]='p';
  661.   tempx[10]='x';

  662. File dataFile = SD.open(tempx, FILE_WRITE);


  663.   if (dataFile) {

  664.   for(int col=0;col<12;col++)tempx[col]=0;
  665.   SDzhuangtai[0]='S';
  666.   SDzhuangtai[1]='D';
  667.   SDzhuangtai[2]='G';
  668.   SDzhuangtai[3]='o';
  669.   SDzhuangtai[4]='o';
  670.   SDzhuangtai[5]='d';


  671.    
  672.       EEPROMvalue= EEPROM.read(4);
  673.       if(EEPROMvalue==0) gpxstart=1;
  674.       else gpxstart=0;
  675.      
  676.      
  677.    
  678.     EEPROMvalue= EEPROM.read(7);
  679.     if(EEPROMvalue==0){
  680.     gpxmiddleA=1;
  681.    
  682.       
  683.     Trackname();

  684.     }else gpxmiddleA=0;
  685.    
  686.       EEPROMvalue= EEPROM.read(8);
  687.       if(EEPROMvalue==0) gpxendA=1;
  688.       else gpxendA=0;

  689.       EEPROMvalue= EEPROM.read(9);
  690.       if(EEPROMvalue==0) gpxendB=1;
  691.       else gpxendB=0;
  692.      

  693. if(gpxstart){
  694. EEPROM.write(4, 1);


  695. for(int col=0;col<95;col++)GPRMC[col]=0;
  696. for(int i=50;i<77;i++)GPRMC[i-50] = EEPROM.read(i);

  697. dataFile.print(GPRMC);

  698.   }


  699. if(gpxmiddleA){         
  700. EEPROM.write(7, 1);

  701. for(int col=0;col<95;col++)GPRMC[col]=0;
  702. for(int i=77;i<89;i++)GPRMC[i-77] = EEPROM.read(i);

  703. dataFile.print(GPRMC);
  704. dataFile.print(TrackAN);




  705. for(int col=0;col<95;col++)GPRMC[col]=0;
  706. for(int i=89;i<110;i++)GPRMC[i-89] = EEPROM.read(i);

  707. dataFile.println(GPRMC);


  708. }


  709. if(gpxmiddleB){

  710.    
  711.    for(int col=0;col<95;col++)GPRMC[col]=0;
  712.    for(int i=110;i<123;i++)GPRMC[i-110] = EEPROM.read(i);
  713.    dataFile.print(GPRMC);
  714.    dataFile.print(TrackB1);
  715.    


  716.    for(int col=0;col<95;col++)GPRMC[col]=0;
  717.    for(int i=123;i<131;i++)GPRMC[i-123] = EEPROM.read(i);
  718.    dataFile.print(GPRMC);

  719.    dataFile.print(TrackB2);
  720.    



  721. for(int col=0;col<95;col++)GPRMC[col]=0;
  722. for(int i=131;i<140;i++)GPRMC[i-131] = EEPROM.read(i);
  723.    dataFile.print(GPRMC);
  724.    dataFile.print(TrackB4);
  725.    


  726.    for(int col=0;col<95;col++)GPRMC[col]=0;
  727.    for(int i=140;i<158;i++)GPRMC[i-140] = EEPROM.read(i);
  728.    
  729.    if(MSlong>0){

  730.                  dataFile.print(GPRMC);
  731.                
  732.                
  733.                  for(int col=0;col<95;col++)GPRMC[col]=0;
  734.                  memcpy(GPRMC,MS+4,MSlong-6);
  735.                  dataFile.println(GPRMC);
  736.                
  737.                
  738.                 MSlong=0;
  739.                

  740.   }else dataFile.println(GPRMC);



  741. }


  742. if(gpxendA){
  743. EEPROM.write(8,1);
  744. EEPROM.write(7,0);

  745.   for(int col=0;col<95;col++)GPRMC[col]=0;
  746.   for(int i=158;i<174;i++)GPRMC[i-158] = EEPROM.read(i);
  747.    dataFile.print(GPRMC);


  748. EEPROMvalue= EEPROM.read(6);
  749. EEPROMvalue++;
  750. EEPROM.write(6,EEPROMvalue);

  751.   }


  752.   if(gpxendB){
  753. EEPROM.write(9,1);

  754. EEPROM.write(4,0);


  755.   for(int col=0;col<95;col++)GPRMC[col]=0;
  756.   for(int i=174;i<181;i++)GPRMC[i-174] = EEPROM.read(i);
  757.    dataFile.print(GPRMC);
  758.    


  759. EEPROMvalue= EEPROM.read(1);
  760. EEPROMvalue++;
  761. if(EEPROMvalue==255) EEPROMvalue=0;
  762. EEPROM.write(1, EEPROMvalue);
  763. Linename();

  764.   }


  765.   }else{
  766.    for(int col=0;col<12;col++)tempx[col]=0;
  767.   SDzhuangtai[0]='F';
  768.   SDzhuangtai[1]='a';
  769.   SDzhuangtai[2]='i';
  770.   SDzhuangtai[3]='l';
  771.   SDzhuangtai[4]='e';
  772.   SDzhuangtai[5]='d';


  773.   }



  774. dataFile.close();



  775. }


  776. void Linename()
  777. {

  778.    for(int col=0;col<12;col++)tempx[col]=0;

  779. if(EEPROMvalue<10){
  780. tempx[0]=48;
  781. tempx[1]=48;
  782.   tempx[2]=EEPROMvalue+48;

  783. }else if(EEPROMvalue<100){
  784.   tempx[0]=48;
  785. Linenumber=EEPROMvalue*0.1;
  786.   tempx[1]=Linenumber+48;
  787.    Linenumber=EEPROMvalue%10;
  788.     tempx[2]=Linenumber+48;

  789. }else{

  790.    Linenumber=EEPROMvalue*0.01;
  791.   tempx[0]=Linenumber+48;
  792.   Linenumber=EEPROMvalue*0.1;
  793.     Linenumber=Linenumber%10;
  794.   tempx[1]=Linenumber+48;
  795.    Linenumber=EEPROMvalue%10;
  796.     tempx[2]=Linenumber+48;

  797. }


  798. for(int col=0;col<4;col++)TrackAL[col]=0;
  799.   memcpy(TrackAL,tempx,3);

  800. }



  801.   void Trackname()
  802. {

  803.    
  804.    EEPROMvalue= EEPROM.read(6);
  805.    if(EEPROMvalue <250){
  806.    gpxjiluguijishu=EEPROMvalue;
  807.    
  808.    EEPROMvalue= EEPROM.read(5);
  809.    gpxjiluguijishu=EEPROMvalue*250+gpxjiluguijishu;
  810.    
  811.    }else{
  812.    gpxjiluguijishu=0;
  813.    EEPROM.write(6,gpxjiluguijishu);
  814.    
  815.    EEPROMvalue= EEPROM.read(5);
  816.    if(EEPROMvalue<240){
  817.    EEPROMvalue++;
  818.    EEPROM.write(5,EEPROMvalue);
  819.    gpxjiluguijishu=EEPROMvalue*250;
  820.    }else{
  821.    EEPROM.write(5,0);
  822.    gpxjiluguijishu=0;
  823.    }
  824.    
  825.    }
  826.    
  827.   
  828.   for(int col=0;col<12;col++)tempx[col]=0;

  829. if(gpxjiluguijishu>9999)sprintf(tempx, "%d", gpxjiluguijishu);
  830. else if(gpxjiluguijishu>999){
  831. tempx[0]=48;
  832. sprintf(tempx+1, "%d", gpxjiluguijishu);
  833. }else if(gpxjiluguijishu>99){
  834. tempx[0]=48;
  835. tempx[1]=48;
  836. sprintf(tempx+2, "%d", gpxjiluguijishu);
  837. }else if(gpxjiluguijishu>9){
  838. tempx[0]=48;
  839. tempx[1]=48;
  840. tempx[2]=48;
  841. sprintf(tempx+3, "%d", gpxjiluguijishu);
  842. }else{
  843. tempx[0]=48;
  844. tempx[1]=48;
  845. tempx[2]=48;
  846. tempx[3]=48;
  847. sprintf(tempx+4, "%d", gpxjiluguijishu);
  848. }

  849.   memcpy(TrackAN,tempx,5);

  850. }



复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-11-16 20:39:17 | 显示全部楼层
B的程序

  1. #include <MemoryFree.h>

  2. #include <LiquidCrystal_I2C.h>
  3. LiquidCrystal_I2C lcd(0x3F,16,2);

  4. #include <SoftwareSerial.h>
  5. SoftwareSerial LC05(8, 9);
  6. char tempx[17];
  7. char tempxB[17];
  8. char MS[100];
  9. char AT[20];
  10. char TOSD[100]="$MS,<PM2.5>199.12ug</PM2.5><AQI>182</AQI><TEMP>-14</TEMP><humidity>15</humidity>*2B";
  11. boolean MSget=0;
  12. boolean ATget=0;
  13. unsigned long gpstimes;
  14. boolean konghangpanduan;
  15. boolean konghangpanduanB;
  16. boolean gpsshuchuqiehuanB;
  17. int chuankouzhuanyong;
  18. int chuankouzhuanyongB;
  19. int jsq1=0;
  20. int jsq2=0;
  21. int jsq3=0;
  22. int jsq4=0;
  23. int jsq5=0;
  24. int jsq6=0;
  25. int jsq7=0;
  26. int MSlong=0;
  27. int ATlong=0;
  28. boolean jiaoyanjieguoA,jiaoyanjieguoC;

  29. String jianyan="";
  30. int yihuoyunsuan;

  31. boolean dingweiok=0;
  32. boolean fangzhilianji=1;
  33. int lcdxianshi=0;
  34. /*---------------------LC05 end---------------------------------*/

  35.   
  36. #include<EEPROM.h>
  37. int EEPROMvalue;


  38. char TrackAL[4]="000";
  39. char TrackAN[6]="00000";
  40. char TrackB0[8]="-0000.0";
  41. char TrackB1[11]="00.0000000";
  42. char TrackB2[12]="000.0000000";
  43. char TrackB4[20]="2000-00-00T00:00:00";
  44. char TrackB5[8]="0000.00";
  45. char TrackB6[7]="000.00";

  46. char SDzhuangtai[7];

  47. int utc8s,utc8f,utc8m,utc8n,utc8y,utc8r;
  48. int xiaoyue[5]={4,6,9,11};
  49. boolean rijinwei,yuejinwei,nianjinwei,xiaoyueok;


  50. #include <OneWire.h>
  51. #include <DallasTemperature.h>
  52. OneWire oneWire(6);
  53. DallasTemperature sensors(&oneWire);

  54. #include <dht11.h>
  55. dht11 DHT11;
  56. #define DHT11PIN 7


  57. #include <Wire.h>
  58. #include <RTClib.h>
  59. void printDateTime(DateTime dateTime);
  60. RTC_DS1307 RTC;
  61. int nian,yue,ri,shi,fen,miao;
  62. boolean shoushiqidong;


  63. int gp2y1010dust=2;
  64. int gp2y1010led=15;
  65. int dustVal=0;
  66. int delayTime=280;
  67. int delayTime2=40;
  68. float offTime=9680;
  69. int dusti=0;
  70. float dustValPM25,averagedustVal;
  71. int AQI;
  72. int mySensVals [10];
  73. unsigned long time1=millis();

  74. void setup() {

  75. pinMode(gp2y1010led,OUTPUT);

  76.   lcd.init();
  77.   lcd.backlight();

  78.   
  79.   Wire.begin();
  80.   RTC.begin();


  81. Serial.begin(9600);
  82. LC05.begin(9600);
  83.   
  84. EEPROMvalue= EEPROM.read(0);
  85. if(EEPROMvalue==0){
  86. gpsshuchuqiehuanB=0;
  87. Serial.println("$AT,A*78");
  88. }else{
  89. gpsshuchuqiehuanB=1;
  90. Serial.println("$AT,B*7B");
  91. }

  92. EEPROMvalue= EEPROM.read(10);
  93. if(EEPROMvalue<4)lcdxianshi=EEPROMvalue;
  94. else {
  95.   EEPROM.write(10,3);
  96.   lcdxianshi=3;
  97. }

  98.   
  99. }

  100. void loop() {
  101. MShuoqu();
  102. AThuoqu();
  103. if(millis()-gpstimes>10){
  104. if(!konghangpanduan){
  105. konghangpanduan=1;

  106. for(int col=1;col<MSlong-2;col++){
  107.         if(col==1)yihuoyunsuan=MS[col];
  108.         else yihuoyunsuan=yihuoyunsuan ^ MS[col];
  109. }
  110. if(yihuoyunsuan==0){
  111.         jianyan="00";
  112. }else if(yihuoyunsuan>15){
  113.         jianyan = String(yihuoyunsuan,HEX);
  114. }else{
  115.         jianyan = "0";
  116.         jianyan += String(yihuoyunsuan,HEX);
  117. }
  118. jianyan.toUpperCase();
  119. if(jianyan[0]==MS[MSlong-1] && jianyan[1]==MS[MSlong] ){
  120.        
  121.        
  122.         memcpy(TrackAL,MS+4, 3);
  123.         memcpy(TrackAN,MS+8, 5);
  124.         memcpy(TrackB1,MS+14, 10);
  125.         memcpy(TrackB2,MS+25, 11);
  126.         memcpy(TrackB4,MS+37, 19);
  127.    jsq2=0;
  128.    jsq3=0;
  129.    jsq4=0;
  130.    jsq5=0;
  131.    jsq6=0;
  132.     for(int col=1;col<MSlong;col++){
  133.                 if(MS[col]==',')jsq2++;
  134.                 if(jsq2==10){
  135.                         jsq3=col;
  136.                         col=MSlong;
  137.                 }
  138.                
  139.                 if(jsq2<9)jsq4=col;
  140.                
  141.                 if(jsq2<8)jsq5=col;
  142.                
  143.                 if(jsq2<7)jsq6=col;
  144.    }
  145.    
  146.    
  147.    
  148. for(int col=0;col<8;col++)TrackB0[col]=0;
  149. memcpy(TrackB0,MS+57, jsq6-56);

  150.    
  151. for(int col=0;col<8;col++)TrackB5[col]=0;
  152. memcpy(TrackB5,MS+jsq6+2, jsq5-jsq6-1);
  153.    
  154. for(int col=0;col<8;col++)TrackB6[col]=0;
  155. memcpy(TrackB6,MS+jsq5+2, jsq4-jsq5-1);
  156.    
  157. for(int col=0;col<7;col++)SDzhuangtai[col]=0;
  158. memcpy(SDzhuangtai,MS+jsq4+2, jsq3-jsq4-2);





  159. chinatime();





  160. }else {
  161. for(int col=0;col<100;col++)MS[col]=0;
  162. MSlong=0;
  163. chuankouzhuanyong=0;
  164. MSget=0;
  165. }
  166. jianyan="";

  167. }

  168. if(!konghangpanduanB){
  169.         konghangpanduanB=1;
  170. for(int col=1;col<ATlong-2;col++){
  171.         if(col==1)yihuoyunsuan=AT[col];
  172.         else yihuoyunsuan=yihuoyunsuan ^ AT[col];
  173. }
  174. if(yihuoyunsuan==0){
  175.         jianyan="00";
  176. }else if(yihuoyunsuan>15){
  177.         jianyan = String(yihuoyunsuan,HEX);
  178. }else{
  179.         jianyan = "0";
  180.         jianyan += String(yihuoyunsuan,HEX);
  181. }
  182. jianyan.toUpperCase();
  183.        
  184.        
  185.    
  186.        
  187.    
  188.        
  189.        
  190. if(jianyan[0]==AT[ATlong-1] && jianyan[1]==AT[ATlong] ){

  191. if(AT[4]=='A'){
  192.        
  193.        
  194.                 if(gpsshuchuqiehuanB){
  195.                 gpsshuchuqiehuanB=0;
  196.                  EEPROM.write(0,0);
  197.                 }
  198.                 Serial.println("$AT,A*78");
  199.                 LC05.println("OK");
  200.                 lcdxianshi= EEPROM.read(10);
  201. }else if(AT[4]=='B'){
  202.        
  203.                 if(!gpsshuchuqiehuanB){
  204.                 gpsshuchuqiehuanB=1;
  205.                  EEPROM.write(0,1);
  206.                 }
  207.                 Serial.println("$AT,B*7B");
  208.                 LC05.println("OK");
  209.                 lcdxianshi=3;
  210.                
  211. }else if(AT[4]=='C'){
  212.        
  213.         if(!gpsshuchuqiehuanB){
  214.                 if(lcdxianshi>0)lcdxianshi--;
  215.                 else lcdxianshi=3;
  216.                 EEPROM.write(10,lcdxianshi);
  217.                 LC05.println("OK");
  218.         }else LC05.println("Bluetooth GPS out");
  219.        
  220. }else if(AT[4]=='D'){
  221.        
  222.         if(!gpsshuchuqiehuanB){
  223.                 if(lcdxianshi<3)lcdxianshi++;
  224.                 else lcdxianshi=0;
  225.                 EEPROM.write(10,lcdxianshi);
  226.                 LC05.println("OK");
  227.         }else LC05.println("Bluetooth GPS out");
  228.         }else LC05.println("AT undefinition");

  229.         for(int col=0;col<20;col++)AT[col]=0;
  230.         ATlong=0;
  231. }else {
  232.         for(int col=0;col<20;col++)AT[col]=0;
  233.         ATlong=0;
  234.         chuankouzhuanyongB=0;
  235.         ATget=0;
  236. }
  237. jianyan="";

  238. }

  239. if (millis() - time1 > 1000){
  240. time1=millis();
  241. fenchentou();

  242.    
  243.    sensors.requestTemperatures();
  244.    
  245.    jsq1=sensors.getTempCByIndex(0);
  246.    
  247.       DHT11.read(DHT11PIN);
  248.    
  249.    jsq2=DHT11.humidity;
  250.    
  251.     for(int col=0;col<17;col++)tempx[col]=0;
  252.    
  253. DS1307tiquxiaodui();   
  254.    
  255.     jsq3=jsq2*0.1;
  256.   tempx[0] = jsq3+48;
  257.    TOSD[67]=tempx[0];
  258.   jsq3=jsq2%10;
  259.   tempx[1] = jsq3+48;
  260.    TOSD[68]=tempx[1];

  261. tempx[2]='%';
  262. tempx[3]=32;

  263. if(jsq1<0){
  264. jsq1=0-jsq1;
  265. tempx[3]='-';
  266. TOSD[47]='-';
  267. }else TOSD[47]=32;

  268.   jsq3=jsq1*0.1;
  269.   tempx[4] = jsq3+48;
  270.   TOSD[48]=tempx[4];
  271.   jsq3=jsq1%10;
  272.   tempx[5] = jsq3+48;
  273.   TOSD[49]=tempx[5];
  274.   tempx[6]='C';
  275.   tempx[7]=32;
  276.   
  277.   now1602out();
  278.   
  279.   MSlong=0;
  280.   
  281. for(int col=1;col<80;col++){
  282. if(col==1)yihuoyunsuan=TOSD[col];
  283. else yihuoyunsuan=yihuoyunsuan ^ TOSD[col];
  284. }
  285. if(yihuoyunsuan==0){
  286. jianyan="00";
  287. }else if(yihuoyunsuan>15){
  288. jianyan = String(yihuoyunsuan,HEX);
  289. }else{
  290. jianyan = "0";
  291. jianyan += String(yihuoyunsuan,HEX);
  292. }
  293. jianyan.toUpperCase();
  294. TOSD[81]=jianyan[0];
  295. TOSD[82]=jianyan[1];
  296. jianyan="";
  297. Serial.println(TOSD);

  298. }



  299. }
  300.   
  301. if (millis() < time1)time1=millis();
  302. if (millis() < gpstimes)gpstimes=millis();

  303. }

  304. void fenchentou()
  305. {


  306. /*粉尘头控制代码*/
  307. digitalWrite(gp2y1010led,LOW);
  308. delayMicroseconds(delayTime);
  309. dustVal=analogRead(gp2y1010dust);
  310. delayMicroseconds(delayTime2);
  311. digitalWrite(gp2y1010led,HIGH);

  312. /*邻采样10次平均averagedustVal的计算*/
  313. mySensVals [dusti]=dustVal;
  314. dusti++;
  315. dusti=dusti%10;
  316. averagedustVal=0;
  317. for(int col=0;col<10;col++)averagedustVal=averagedustVal+mySensVals[col];
  318. averagedustVal=averagedustVal*0.1;



  319. /*计算pm2.5的数值 电压阀值以上用:(v*0.172-0.0999)*1000,阀值以下用线性,参考国外帖子,认为输出最低17,对应粉尘5000*/




  320. if(averagedustVal>184.5)dustValPM25=0.83984375*averagedustVal-99.9;
  321. else dustValPM25=averagedustVal*0.298373984;

  322. jsq3=dustValPM25*0.01;
  323. if(jsq3>0)TOSD[11]=jsq3+48;
  324. else TOSD[11]=32;
  325. jsq3=dustValPM25*0.1;
  326. if(jsq3>0)TOSD[12]=jsq3%10+48;
  327. else TOSD[12]=32;
  328. jsq3=dustValPM25;
  329. jsq3=jsq3%10;
  330. TOSD[13]=jsq3+48;
  331. jsq3=dustValPM25*10;
  332. TOSD[15]=jsq3%10+48;
  333. jsq3=dustValPM25*100;
  334. TOSD[16]=jsq3%10+48;
  335.   

  336. /*AQI的计算,美国标准*/

  337. if(dustValPM25<15.4) AQI=(50-0)/(15.4-0)*(dustValPM25-0)+0;
  338. else if(dustValPM25<40.4) AQI=(100-51)/(40.4-15.5)*(dustValPM25-15.5)+51;
  339. else if(dustValPM25<65.4) AQI=(150-101)/(65.4-40.5)*(dustValPM25-40.5)+101;
  340. else if(dustValPM25<150.4) AQI=(200-151)/(150.4-65.5)*(dustValPM25-65.5)+151;
  341. else if(dustValPM25<250.4) AQI=(300-201)/(250.4-150.5)*(dustValPM25-150.5)+201;
  342. else if(dustValPM25<350.4) AQI=(400-301)/(350.4-250.5)*(dustValPM25-250.5)+301;
  343. else AQI=(500-401)/(500.4-350.5)*(dustValPM25-350.5)+401;


  344. if(AQI>100){
  345. jsq3=AQI*0.01;
  346. TOSD[32]=jsq3+48;
  347. }else  TOSD[32]=32;

  348.   if(AQI>10){
  349. jsq3=AQI*0.1;
  350. TOSD[33]=jsq3%10+48;
  351. }else  TOSD[33]=32;

  352. TOSD[34]=AQI%10+48;

  353. if(lcdxianshi==3){
  354. lcd.setCursor(0, 0);
  355. lcd.print(dustValPM25);
  356. lcd.print("ug AQI:");
  357. lcd.print(AQI);
  358. lcd.print("     ");
  359. }

  360. }

  361. void MShuoqu()
  362. {
  363. while (Serial.available() > 0) {

  364. gpstimes=millis();
  365. konghangpanduan=0;
  366. if(MSget){
  367. MS[chuankouzhuanyong]=Serial.read();
  368. if(gpsshuchuqiehuanB)LC05.print(MS[chuankouzhuanyong]);
  369. if(MS[chuankouzhuanyong-2]=='*'){
  370. MSlong=chuankouzhuanyong;
  371. MSget=0;
  372. chuankouzhuanyong=0;
  373. }else if(chuankouzhuanyong<98)chuankouzhuanyong++;
  374. }else{
  375. tempx[chuankouzhuanyong]=Serial.read();
  376. if(gpsshuchuqiehuanB)LC05.print(tempx[chuankouzhuanyong]);
  377. if(chuankouzhuanyong<3)chuankouzhuanyong++;
  378. }

  379. if(chuankouzhuanyong==3){
  380. if(tempx[1]=='M' && tempx[2]=='S'){
  381. MSget=1;
  382. for(int col=0;col<100;col++)MS[col]=0;
  383. for(int col=0;col<3;col++)MS[col]=tempx[col];
  384. for(int col=0;col<3;col++)tempx[col]=0;
  385. }else{
  386. for(int col=0;col<2;col++)tempx[col]=tempx[col+1];
  387. chuankouzhuanyong=2;
  388. }

  389. }
  390. }


  391. }

  392. void AThuoqu()
  393. {
  394. while (LC05.available() > 0) {
  395. gpstimes=millis();
  396. konghangpanduanB=0;
  397. if(ATget){
  398.         AT[chuankouzhuanyongB]=LC05.read();
  399.        
  400.        
  401.         if(AT[chuankouzhuanyongB-2]=='*'){
  402.                 ATlong=chuankouzhuanyongB;
  403.                 ATget=0;
  404.                 chuankouzhuanyongB=0;
  405.         }else if(chuankouzhuanyongB<18)chuankouzhuanyongB++;
  406. }else{
  407.         tempxB[chuankouzhuanyongB]=LC05.read();
  408.         if(chuankouzhuanyongB<3)chuankouzhuanyongB++;
  409. }

  410. if(chuankouzhuanyongB==3){
  411. if(tempxB[1]=='A' && tempxB[2]=='T'){
  412. ATget=1;
  413. for(int col=0;col<20;col++)AT[col]=0;
  414. for(int col=0;col<3;col++)AT[col]=tempxB[col];
  415. for(int col=0;col<17;col++)tempxB[col]=0;

  416. }else{
  417. for(int col=0;col<2;col++)tempxB[col]=tempxB[col+1];
  418. chuankouzhuanyongB=2;
  419. }

  420. }
  421. }


  422. }

  423. void printDateTime(DateTime dateTime) {
  424.    
  425. nian=dateTime.year(), DEC;

  426.    
  427.     yue=dateTime.month(), DEC;
  428.    
  429. ri=dateTime.day(), DEC;
  430.    
  431. shi=dateTime.hour(), DEC;
  432.    
  433. fen=dateTime.minute(), DEC;
  434.    
  435. miao=dateTime.second(), DEC;


  436. }


  437. void DS1307tiquxiaodui()
  438. {
  439.   

  440.   
  441.     DateTime now = RTC.now();
  442.       
  443.       printDateTime(now);

  444. if(MSlong>0){
  445. if(yue != utc8y) shoushiqidong=1;
  446. if(ri != utc8r) shoushiqidong=1;
  447. if(shi != utc8s) shoushiqidong=1;
  448. if(fen != utc8f) shoushiqidong=1;
  449. if(miao-utc8m>2 || utc8m-miao>2) shoushiqidong=1;
  450. if(shoushiqidong){
  451. shoushiqidong=0;

  452.    RTC.set(RTC_YEAR, utc8n);
  453.    
  454.    RTC.set(RTC_MONTH, utc8y);
  455.    
  456.    RTC.set(RTC_DAY, utc8r);
  457.    
  458.    RTC.set(RTC_HOUR, utc8s);
  459.    
  460. RTC.set(RTC_MINUTE, utc8f);
  461.    
  462.    RTC.set(RTC_SECOND, utc8m);
  463. }
  464. }
  465. /*
  466. jsq3=nian*0.1;
  467.   jsq3=jsq3%10;
  468.   temp2[7] = jsq3+48, DEC;
  469.   jsq3=nian%10;
  470.   temp2[8] = jsq3+48, DEC;

  471.    
  472.   jsq3=yue*0.1;
  473.   temp2[10] = jsq3+48, DEC;
  474.   jsq3=yue%10;
  475.   temp2[11] = jsq3+48, DEC;


  476.     jsq3=ri*0.1;
  477.   temp2[13] = jsq3+48, DEC;
  478.   jsq3=ri%10;
  479.   temp2[14] = jsq3+48, DEC;
  480.    
  481.    */
  482.    
  483.   jsq3=shi*0.1;
  484.   tempx[8] = jsq3+48, DEC;
  485.   jsq3=shi%10;
  486.   tempx[9] = jsq3+48, DEC;
  487.   tempx[10]=':';

  488.   jsq3=fen*0.1;
  489.   tempx[11] = jsq3+48, DEC;
  490.   jsq3=fen%10;
  491.   tempx[12] = jsq3+48, DEC;
  492.   tempx[13]=':';


  493.   jsq3=miao*0.1;
  494.   tempx[14]= jsq3+48, DEC;
  495.   jsq3=miao%10;
  496.   tempx[15] = jsq3+48, DEC;
  497. }


  498. void now1602out()
  499. {

  500. /*GPS模式下的显示情况说明
  501. char TrackB0[8]="-0000.0";
  502. char TrackB1[11]="00.0000000";
  503. char TrackB2[12]="000.0000000";
  504. char TrackB4[20]="2000-00-00T00:00:00";
  505. char TrackB5[8]="0000.00";
  506. char TrackB6[7]="000.00";

  507. lcdxianshi=0显示内容如下
  508. LAT.  00.0000000
  509. 0123456789012345
  510. LON. 000.0000000

  511. lcdxianshi=1显示内容如下
  512. ASL(G): -0000.0M
  513. 0123456789012345
  514. YAW(GPS): 000.00

  515. lcdxianshi=2显示内容如下
  516.   00-00T00:00:00
  517. 0123456789012345
  518. speed:000.00km/h

  519. I'm so sorry but
  520. 0123456789012345
  521. now the GPS lost
  522. */
  523. if(MSlong==0 && lcdxianshi<3){
  524. lcd.setCursor(0, 0);
  525. lcd.print("I'm so sorry but");
  526. lcd.setCursor(0, 1);
  527. lcd.print("now the GPS lost");
  528. }else{
  529. if(lcdxianshi==0){
  530. lcd.setCursor(0, 0);
  531. lcd.print("LAT.  ");
  532. lcd.print(TrackB1);
  533. lcd.setCursor(0, 1);
  534. lcd.print("LON. ");
  535. lcd.print(TrackB2);

  536. }else if(lcdxianshi==1){
  537. lcd.setCursor(0, 0);
  538. lcd.print("ASL(G): ");
  539. lcd.print(TrackB0);
  540. lcd.print("M    ");
  541. lcd.setCursor(0, 1);
  542. lcd.print("YAW(GPS): ");
  543. lcd.print(TrackB6);
  544. lcd.print("        ");

  545. }else if(lcdxianshi==2){
  546. for(int col=0;col<17;col++)tempx[col]=0;
  547. for(int col=0;col<14;col++)tempx[col]=TrackB4[col+5];
  548. lcd.setCursor(0, 0);
  549. lcd.print("  ");
  550. lcd.print(tempx);
  551. lcd.setCursor(0, 1);
  552. lcd.print("speed:");
  553. lcd.print(TrackB5);
  554. lcd.print("km/h    ");
  555. }else if(lcdxianshi==3){

  556.   lcd.setCursor(0, 1);
  557.   

  558. lcd.print(tempx);

  559. }
  560. }

  561. }

  562. void chinatime()
  563. {




  564. jianyan = String(TrackB4[11]);
  565. jianyan += TrackB4[12];
  566. utc8s=jianyan.toInt()+8;


  567. if(utc8s>23)rijinwei=1;
  568. utc8s=utc8s%24;
  569. jianyan = String(TrackB4[14]);
  570. jianyan += TrackB4[15];
  571. utc8f=jianyan.toInt();


  572. jianyan = String(TrackB4[17]);
  573. jianyan += TrackB4[18];
  574. utc8m=jianyan.toInt();





  575. jianyan = String(TrackB4[8]);
  576. jianyan += TrackB4[9];
  577. utc8r=jianyan.toInt();



  578. jianyan = String(TrackB4[5]);
  579. jianyan += TrackB4[6];
  580. utc8y=jianyan.toInt();


  581. jianyan = String(TrackB4[2]);
  582. jianyan += TrackB4[3];
  583. utc8n=jianyan.toInt();




  584. if(rijinwei){
  585. if(utc8y==2 && utc8r==28){
  586. if(utc8n % 400 == 0 || utc8n % 100 != 0 && utc8n % 4 == 0)utc8r=29;
  587. else {
  588. utc8r=1;
  589. yuejinwei=1;
  590. }
  591. }else{
  592. for(int col=0;col<4;col++){
  593. if(xiaoyue[col]==utc8y)xiaoyueok=1;
  594. }
  595. if(xiaoyueok && utc8r==30){
  596. utc8r=1;
  597. yuejinwei=1;
  598. }else if(!xiaoyueok && utc8r==31){
  599. utc8r=1;
  600. yuejinwei=1;
  601. }else{
  602. utc8r++;
  603. }
  604. }
  605. }
  606. if(yuejinwei && utc8y==12){
  607. utc8y=1;
  608. nianjinwei=1;
  609. }else if(yuejinwei){
  610. utc8y++;
  611. }
  612. if(nianjinwei)utc8n++;



  613. for(int col=0;col<17;col++)tempx[col]=0;
  614. if(utc8n>9){
  615. sprintf(tempx, "%d", utc8n);
  616. memcpy(TrackB4+2,tempx, 2);
  617. }else{
  618.   TrackB4[2]=48;
  619.   TrackB4[3]=utc8n+48;

  620. }

  621.   for(int col=0;col<17;col++)tempx[col]=0;
  622.   if(utc8y>9){
  623.   sprintf(tempx, "%d", utc8y);
  624. memcpy(TrackB4+5,tempx, 2);
  625. } else{
  626.   TrackB4[5]=48;
  627.    TrackB4[6]=utc8y+48;

  628. }
  629.    for(int col=0;col<17;col++)tempx[col]=0;
  630. if(utc8r>9){
  631. sprintf(tempx, "%d", utc8r);
  632. memcpy(TrackB4+8,tempx, 2);
  633. }else{
  634.   TrackB4[8]=48;
  635. TrackB4[9]=utc8r+48;

  636. }

  637.     for(int col=0;col<17;col++)tempx[col]=0;
  638. if(utc8s>9){
  639. sprintf(tempx, "%d", utc8s);
  640. memcpy(TrackB4+11,tempx, 2);
  641. }else{
  642. TrackB4[11]=48;
  643. TrackB4[12]=utc8s+48;

  644. }
  645.     for(int col=0;col<17;col++)tempx[col]=0;
  646. if(utc8f>9){
  647. sprintf(tempx, "%d", utc8f);
  648. memcpy(TrackB4+14,tempx, 2);
  649. }else{
  650. TrackB4[14]=48;
  651.   TrackB4[15]=utc8f+48;
  652. }

  653.     for(int col=0;col<17;col++)tempx[col]=0;
  654.   if(utc8m>9){
  655.   sprintf(tempx, "%d", utc8m);
  656. memcpy(TrackB4+17,tempx, 2);
  657. }else{
  658. TrackB4[17]=48;
  659.   TrackB4[18]=utc8m+48;
  660. }


  661. }





复制代码
回复 支持 反对

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-4-23 17:39 , Processed in 0.046146 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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