极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 37341|回复: 21

GPS码表 & 轨迹记录仪 &蓝牙gps,谷歌地球查看,山寨Pro min搭建 【1楼完结】

[复制链接]
发表于 2014-10-18 22:09:31 | 显示全部楼层 |阅读模式
本帖最后由 hi55234 于 2014-11-2 17:55 编辑

太长不看系列之简易码表
功能:
1、显示速度,1602显示,已经转换为km/h
2、可以作为蓝牙GPS使用
3、可以通过SD卡记录GPX,当然也能在Google 地球上回放轨迹
4、时间改为UTC8,也就是Google 地球的回放时间就是实际的北京时间

效果:


连线图




GPX文件Google地球回放


生成的GPX文件,石子山体育公园一游


SD卡目录:



因为是太长不看系列(为了程序比较短,删掉了全部空行还有注释),所以,这个程序就以实用为主了

1、EEPROM写入,默认初始状态蓝牙会输出(这个程序必须先运行一次,否则SD卡记录的文件名,记录时间间隔(这个间隔设置的10s)全是乱的)
  1. #include<EEPROM.h>
  2. void setup() {
  3. Serial.begin(9600);
  4. EEPROM.write(0,1);
  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.   
  35. void loop()
  36. {
  37. }
复制代码


2、主程序:
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. LiquidCrystal_I2C lcd(0x26,16,2);
  4. boolean shanshuo=1;
  5. #include <SoftwareSerial.h>
  6. SoftwareSerial gps(8, 9);
  7. char tempx[12];
  8. int gpschangertest;
  9. boolean gpschanger;
  10. int weiduA;
  11. unsigned long weiduB,weiduC;
  12. int jingduA;
  13. unsigned long jingduB,jingduC;
  14. char GPRMC[80];
  15. unsigned long gpstimes;
  16. boolean konghangpanduan;
  17. int jsq1=0;
  18. boolean panduan1=0;
  19. boolean panduan2=0;
  20. String jianyan="";
  21. int yihuoyunsuan;
  22. boolean jiaoyanjieguo=0;
  23. boolean dingweiok=0;
  24. int gpsshuchuqiehuanA;
  25. boolean gpsshuchuqiehuanB;
  26. #include<EEPROM.h>
  27. int EEPROMvalue;
  28. #include <SD.h>
  29. const int chipSelect = 10;
  30. boolean gpxstart;
  31. boolean gpxmiddleA;
  32. boolean gpxmiddleB=1;
  33. boolean gpxendA;
  34. boolean gpxendB;
  35. int gpxjilujiangeA;
  36. int gpxjilujiangeB=256;
  37. int gpxjiludianshu;
  38. int gpxjiluguijishu;
  39. char TrackAL[4]="000";
  40. char TrackAN[6]="00000";
  41. char TrackB1[11]="12.1234560";
  42. char TrackB2[12]="123.1234560";
  43. char TrackB4[20]="2007-10-14T10:09:57";
  44. char TrackB5[8]="****.**";
  45. boolean weiduxuweitiao=0;
  46. boolean jingduxuweitiao=0;
  47. int weiduzhanwei,jingduzhanwei;
  48. int utc8s,utc8f,utc8m,utc8n,utc8y,utc8r;
  49. int xiaoyue[5]={4,6,9,11};
  50. boolean rijinwei,yuejinwei,nianjinwei,xiaoyueok;
  51. unsigned long fentodu;
  52. int Linenumber;
  53. int Tracknumber;

  54. void setup() {
  55. pinMode(5,INPUT);
  56.   lcd.init();
  57.   lcd.backlight();
  58. Serial.begin(9600);
  59. gps.begin(9600);
  60. EEPROMvalue= EEPROM.read(0);
  61. if(EEPROMvalue==0)gpsshuchuqiehuanB=0;
  62. else gpsshuchuqiehuanB=1;
  63. EEPROMvalue= EEPROM.read(1);
  64. if(EEPROMvalue==255) EEPROMvalue=0;
  65. Linename();
  66.   EEPROMvalue= EEPROM.read(2);
  67. if(EEPROMvalue==0)gpxjilujiangeA=1;
  68. else gpxjilujiangeA=EEPROMvalue;
  69.   EEPROMvalue= EEPROM.read(3);
  70.   gpxjiludianshu=EEPROMvalue*25;
  71.   EEPROMvalue++;
  72.   EEPROM.write(3, EEPROMvalue);
  73.   pinMode(10, OUTPUT);
  74.   if (!SD.begin(chipSelect)) {
  75.     lcd.print("SD Card failed! ");
  76.     return;
  77.   }
  78. }

  79. void loop()
  80. {
  81. while (gps.available() > 0) {
  82. gpstimes=millis();
  83. konghangpanduan=0;
  84. if(panduan2){
  85. tempx[0]=gps.read();
  86. if(gpsshuchuqiehuanB)Serial.print(tempx[0]);
  87. }else{
  88. GPRMC[jsq1] = gps.read();
  89. if(gpsshuchuqiehuanB)Serial.print(GPRMC[jsq1]);
  90. }
  91. if(jsq1<79 && !panduan2) jsq1++;
  92. else if(!panduan2) jsq1=79;
  93. if(jsq1>5 && !panduan1){
  94. if(GPRMC[jsq1-2]=='M' && GPRMC[jsq1-1]=='C')panduan1=1;
  95. else{
  96. GPRMC[jsq1-6]=GPRMC[jsq1-5];
  97. GPRMC[jsq1-5]=GPRMC[jsq1-4];
  98. GPRMC[jsq1-4]=GPRMC[jsq1-3];
  99. GPRMC[jsq1-3]=GPRMC[jsq1-2];
  100. GPRMC[jsq1-2]=GPRMC[jsq1-1];
  101. jsq1=5;
  102. }
  103. }
  104. if(panduan1 && GPRMC[jsq1-3]=='*'){
  105. panduan2=1;
  106. }
  107. }
  108. if(millis()-gpstimes>10 && !konghangpanduan){
  109. konghangpanduan=1;
  110. gpxjilujiangeB++;
  111. gpsdechuli();
  112. if(jiaoyanjieguo){
  113. jiaoyanjieguo=0;
  114. jiexiGPRMC();
  115. if(dingweiok && gpschanger) {
  116. gpschanger=0;
  117. if(gpxjilujiangeB>gpxjilujiangeA){
  118. gpxjilujiangeB=0;
  119. gpxjiludianshu++;
  120. if(gpxjiludianshu%25==0){
  121. EEPROMvalue= EEPROM.read(3);
  122. EEPROMvalue++;
  123. if(EEPROMvalue>108){
  124. EEPROMvalue=0;
  125. EEPROM.write(3, 0);
  126. gpxjiludianshu=0;
  127. EEPROM.write(8,0);
  128. EEPROM.write(9,0);
  129. sdcaozuo();
  130. }else {
  131. EEPROM.write(3, EEPROMvalue);
  132. }
  133. }
  134. sdcaozuo();
  135. }
  136. }
  137. }
  138.   lcd.setCursor(0, 1);
  139. if(gpsshuchuqiehuanB)lcd.print("BT");
  140. else lcd.print("  ");
  141. lcd.setCursor(3, 1);
  142. lcd.print(TrackB5);
  143. if(shanshuo)lcd.print("km/h");
  144. else lcd.print("        ");
  145.   shanshuo=!shanshuo;
  146. gpsshuchuqiehuanA =digitalRead(5);
  147. if (gpsshuchuqiehuanA==HIGH){
  148. gpsshuchuqiehuanB=!gpsshuchuqiehuanB;
  149. EEPROM.write(0,gpsshuchuqiehuanB);
  150. }
  151. for(int col=0;col<80;col++)GPRMC[col]=0;
  152. jsq1=0;
  153. panduan1=0;
  154. panduan2=0;
  155. }
  156. }

  157. void gpsdechuli()
  158. {
  159. for(int col=1;col<jsq1-3;col++){
  160. if(col==1)yihuoyunsuan=GPRMC[col];
  161. else yihuoyunsuan=yihuoyunsuan ^ GPRMC[col];
  162. }
  163. if(yihuoyunsuan==0){
  164. jianyan="00";
  165. }else if(yihuoyunsuan>15){
  166. jianyan = String(yihuoyunsuan,HEX);
  167. }else{
  168. jianyan = "0";
  169. jianyan += String(yihuoyunsuan,HEX);
  170. }
  171. jianyan.toUpperCase();
  172. if(jianyan[0]==GPRMC[jsq1-2] && jianyan[1]==GPRMC[jsq1-1] ){
  173. jiaoyanjieguo=1;
  174. }else{
  175. jiaoyanjieguo=0;
  176. }
  177. jianyan="";
  178. }

  179. void jiexiGPRMC()
  180. {
  181. if(GPRMC[18]=='A'){
  182. dingweiok=1;
  183.   lcd.setCursor(0, 0);
  184.   lcd.print("G:get! ");
  185. for(int col=0;col<12;col++)tempx[col]=0;
  186. memcpy(tempx,GPRMC+20, 2);
  187. jianyan =tempx;
  188. gpschangertest=jianyan.toInt();
  189. if(weiduA!=gpschangertest){
  190. weiduA=gpschangertest;
  191. gpschanger=1;
  192. }
  193. if(GPRMC[30]==83)weiduxuweitiao=1;
  194. if(GPRMC[43]==87)jingduxuweitiao=1;
  195. memcpy(TrackB1,GPRMC+20, 2);
  196. if(gpschangertest<10) {
  197. TrackB1[0]=32;
  198. weiduzhanwei=1;
  199. }else weiduzhanwei=2;
  200. for(int col=0;col<12;col++)tempx[col]=0;
  201. memcpy(tempx,GPRMC+22, 2);
  202. jianyan =tempx;
  203. gpschangertest=jianyan.toInt();
  204. if(weiduB!=gpschangertest){
  205. weiduB=gpschangertest;
  206. gpschanger=1;
  207. }
  208.   for(int col=0;col<12;col++)tempx[col]=0;
  209. memcpy(tempx,GPRMC+25, 4);
  210. jianyan =tempx;
  211. gpschangertest=jianyan.toInt();
  212. if(weiduC!=gpschangertest){
  213. weiduC=gpschangertest;
  214. gpschanger=1;
  215. }
  216. fentodu=weiduB*100000+weiduC*10;
  217. fentodu=fentodu/6;
  218.   for(int col=0;col<12;col++)tempx[col]=0;
  219. dtostrf(fentodu,6,0,tempx);
  220. if(fentodu>99999){
  221. memcpy(TrackB1+3,tempx, 6);
  222. }else if(fentodu>9999){
  223. TrackB1[3]=48;
  224.   memcpy(TrackB1+4,tempx, 5);
  225. }else if(fentodu>999){
  226. TrackB1[3]=48;
  227. TrackB1[4]=48;
  228.   memcpy(TrackB1+5,tempx, 4);
  229. }else if(fentodu>99){
  230. TrackB1[3]=48;
  231. TrackB1[4]=48;
  232. TrackB1[5]=48;
  233.   memcpy(TrackB1+6,tempx, 3);
  234. }else if(fentodu>9){
  235. TrackB1[3]=48;
  236. TrackB1[4]=48;
  237. TrackB1[5]=48;
  238. TrackB1[6]=48;
  239.   memcpy(TrackB1+7,tempx, 2);
  240. }else{
  241. TrackB1[3]=48;
  242. TrackB1[4]=48;
  243. TrackB1[5]=48;
  244. TrackB1[6]=48;
  245. TrackB1[7]=48;
  246.   memcpy(TrackB1+8,tempx, 1);
  247. }
  248. if(weiduxuweitiao){
  249. weiduxuweitiao=0;
  250. if(weiduzhanwei==2){
  251.    for(int col=0;col<12;col++)tempx[col]=0;
  252. tempx[0]=45;
  253. memcpy(tempx+1,TrackB1, 9);
  254. memcpy(TrackB1,tempx, 10);
  255. }else{
  256.   TrackB1[0]=45;
  257. }
  258. }
  259. for(int col=0;col<12;col++)tempx[col]=0;
  260. memcpy(tempx,GPRMC+32, 3);
  261. jianyan =tempx;
  262. gpschangertest=jianyan.toInt();
  263. if(jingduA!=gpschangertest){
  264. jingduA=gpschangertest;
  265. gpschanger=1;
  266. }
  267. memcpy(TrackB2,GPRMC+32, 3);
  268. jingduzhanwei=3;
  269. if(gpschangertest<100) {
  270. TrackB2[0]=32;
  271. jingduzhanwei=2;
  272. }
  273. if(gpschangertest<10) {
  274. TrackB2[1]=32;
  275. jingduzhanwei=1;
  276. }
  277. for(int col=0;col<12;col++)tempx[col]=0;
  278. memcpy(tempx,GPRMC+35, 2);
  279. jianyan =tempx;
  280. gpschangertest=jianyan.toInt();
  281. if(jingduB!=gpschangertest){
  282. jingduB=gpschangertest;
  283. gpschanger=1;
  284. }
  285.   for(int col=0;col<12;col++)tempx[col]=0;
  286. memcpy(tempx,GPRMC+38, 4);
  287. jianyan =tempx;
  288. gpschangertest=jianyan.toInt();
  289. if(jingduC!=gpschangertest){
  290. jingduC=gpschangertest;
  291. gpschanger=1;
  292. }
  293. jianyan="";
  294.   fentodu=jingduB*100000+jingduC*10;
  295. fentodu=fentodu/6;
  296.   for(int col=0;col<12;col++)tempx[col]=0;
  297. dtostrf(fentodu,6,0,tempx);
  298. if(fentodu>99999){
  299. memcpy(TrackB2+4,tempx, 6);
  300. }else if(fentodu>9999){
  301. TrackB2[4]=48;
  302.   memcpy(TrackB2+5,tempx, 5);
  303. }else if(fentodu>999){
  304. TrackB2[4]=48;
  305. TrackB2[5]=48;
  306.   memcpy(TrackB2+6,tempx, 4);
  307. }else if(fentodu>99){
  308. TrackB2[4]=48;
  309. TrackB2[5]=48;
  310. TrackB2[6]=48;
  311.   memcpy(TrackB2+7,tempx, 3);
  312. }else if(fentodu>9){
  313. TrackB2[4]=48;
  314. TrackB2[5]=48;
  315. TrackB2[6]=48;
  316. TrackB2[7]=48;
  317.   memcpy(TrackB2+8,tempx, 2);
  318. }else{
  319. TrackB2[4]=48;
  320. TrackB2[5]=48;
  321. TrackB2[6]=48;
  322. TrackB2[7]=48;
  323. TrackB2[8]=48;
  324.   memcpy(TrackB2+9,tempx, 1);
  325. }
  326. if(jingduxuweitiao){
  327. jingduxuweitiao=0;
  328. if(jingduzhanwei==3){
  329.    for(int col=0;col<12;col++)tempx[col]=0;
  330. tempx[0]=45;
  331. memcpy(tempx+1,TrackB2, 10);
  332. memcpy(TrackB2,tempx, 11);
  333. }else if(jingduzhanwei==2){
  334.   TrackB2[0]=45;
  335. }else{
  336. TrackB2[1]=45;
  337. }
  338. }
  339. chinatime();
  340. for(int col=0;col<12;col++)tempx[col]=0;
  341. if(utc8n>9){
  342. sprintf(tempx, "%d", utc8n);
  343. memcpy(TrackB4+2,tempx, 2);
  344. }else{
  345.   TrackB4[2]=48;
  346.   TrackB4[3]=utc8n+48;
  347. }
  348.   for(int col=0;col<12;col++)tempx[col]=0;
  349.   if(utc8y>9){
  350.   sprintf(tempx, "%d", utc8y);
  351. memcpy(TrackB4+5,tempx, 2);
  352. } else{
  353.   TrackB4[5]=48;
  354.    TrackB4[6]=utc8y+48;
  355. }
  356.    for(int col=0;col<12;col++)tempx[col]=0;
  357. if(utc8r>9){
  358. sprintf(tempx, "%d", utc8r);
  359. memcpy(TrackB4+8,tempx, 2);
  360. }else{
  361.   TrackB4[8]=48;
  362. TrackB4[9]=utc8r+48;
  363. }
  364.     for(int col=0;col<12;col++)tempx[col]=0;
  365. if(utc8s>9){
  366. sprintf(tempx, "%d", utc8s);
  367. memcpy(TrackB4+11,tempx, 2);
  368. }else{
  369. TrackB4[11]=48;
  370. TrackB4[12]=utc8s+48;
  371. }
  372.     for(int col=0;col<12;col++)tempx[col]=0;
  373. if(utc8f>9){
  374. sprintf(tempx, "%d", utc8f);
  375. memcpy(TrackB4+14,tempx, 2);
  376. }else{
  377. TrackB4[14]=48;
  378.   TrackB4[15]=utc8f+48;
  379. }
  380.     for(int col=0;col<12;col++)tempx[col]=0;
  381.   if(utc8m>9){
  382.   sprintf(tempx, "%d", utc8m);
  383. memcpy(TrackB4+17,tempx, 2);
  384. }else{
  385. TrackB4[17]=48;
  386.   TrackB4[18]=utc8m+48;
  387. }
  388. }else {
  389. lcd.setCursor(0, 0);
  390.   lcd.print("G:lost! ");
  391. dingweiok=0;
  392.   weiduA=0;
  393.    weiduB=0;
  394.     weiduC=0;
  395.   jingduA=0;
  396.    jingduB=0;
  397.     jingduC=0;
  398. }
  399. }
  400.   
  401. void sdcaozuo()
  402. {
  403.   for(int col=0;col<12;col++)tempx[col]=0;
  404.   tempx[0]='L';
  405.   tempx[1]='i';
  406.   tempx[2]='n';
  407.   tempx[3]='e';
  408.   memcpy(tempx+4,TrackAL,3);
  409.   tempx[7]='.';
  410.   tempx[8]='g';
  411.   tempx[9]='p';
  412.   tempx[10]='x';
  413. File dataFile = SD.open(tempx, FILE_WRITE);
  414. if (dataFile) {
  415.   lcd.setCursor(8, 0);
  416.   lcd.print("SD:Good ");
  417.       EEPROMvalue= EEPROM.read(4);
  418.       if(EEPROMvalue==0) gpxstart=1;
  419.       else gpxstart=0;
  420.     EEPROMvalue= EEPROM.read(7);
  421.     if(EEPROMvalue==0){
  422.     gpxmiddleA=1;
  423.     Trackname();
  424.     }else gpxmiddleA=0;
  425.       EEPROMvalue= EEPROM.read(8);
  426.       if(EEPROMvalue==0) gpxendA=1;
  427.       else gpxendA=0;
  428.       EEPROMvalue= EEPROM.read(9);
  429.       if(EEPROMvalue==0) gpxendB=1;
  430.       else gpxendB=0;
  431. if(gpxstart){
  432. EEPROM.write(4, 1);
  433. for(int col=0;col<80;col++)GPRMC[col]=0;
  434. for(int i=50;i<77;i++)GPRMC[i-50] = EEPROM.read(i);
  435. dataFile.print(GPRMC);
  436. }
  437. if(gpxmiddleA){         
  438. EEPROM.write(7, 1);
  439. for(int col=0;col<80;col++)GPRMC[col]=0;
  440. for(int i=77;i<89;i++)GPRMC[i-77] = EEPROM.read(i);
  441. dataFile.print(GPRMC);
  442. dataFile.print(TrackAN);
  443. for(int col=0;col<80;col++)GPRMC[col]=0;
  444. for(int i=89;i<110;i++)GPRMC[i-89] = EEPROM.read(i);
  445. dataFile.println(GPRMC);
  446. }
  447. if(gpxmiddleB){
  448.    for(int col=0;col<80;col++)GPRMC[col]=0;
  449.    for(int i=110;i<123;i++)GPRMC[i-110] = EEPROM.read(i);
  450.    dataFile.print(GPRMC);
  451.    dataFile.print(TrackB1);
  452.    for(int col=0;col<80;col++)GPRMC[col]=0;
  453.    for(int i=123;i<131;i++)GPRMC[i-123] = EEPROM.read(i);
  454.    dataFile.print(GPRMC);
  455.    dataFile.print(TrackB2);
  456. for(int col=0;col<80;col++)GPRMC[col]=0;
  457. for(int i=131;i<140;i++)GPRMC[i-131] = EEPROM.read(i);
  458.    dataFile.print(GPRMC);
  459.    dataFile.print(TrackB4);
  460.    for(int col=0;col<80;col++)GPRMC[col]=0;
  461.    for(int i=140;i<158;i++)GPRMC[i-140] = EEPROM.read(i);
  462.    dataFile.println(GPRMC);
  463. }
  464. if(gpxendA){
  465. EEPROM.write(8,1);
  466. EEPROM.write(7,0);
  467.   for(int col=0;col<80;col++)GPRMC[col]=0;
  468.   for(int i=158;i<174;i++)GPRMC[i-158] = EEPROM.read(i);
  469.    dataFile.print(GPRMC);
  470. EEPROMvalue= EEPROM.read(6);
  471. EEPROMvalue++;
  472. EEPROM.write(6,EEPROMvalue);
  473.   }
  474.   if(gpxendB){
  475. EEPROM.write(9,1);
  476. EEPROM.write(4,0);
  477.   for(int col=0;col<80;col++)GPRMC[col]=0;
  478.   for(int i=174;i<181;i++)GPRMC[i-174] = EEPROM.read(i);
  479.    dataFile.print(GPRMC);
  480. EEPROMvalue= EEPROM.read(1);
  481. EEPROMvalue++;
  482. if(EEPROMvalue==255) EEPROMvalue=0;
  483. EEPROM.write(1, EEPROMvalue);
  484. Linename();
  485.   }
  486.   }else{
  487.   lcd.setCursor(8, 0);
  488.   lcd.print("SD:Error");
  489.   }
  490. dataFile.close();
  491. }
  492.   
  493. void chinatime()
  494. {
  495. jianyan = String(GPRMC[7]);
  496. jianyan += GPRMC[8];
  497. utc8s=jianyan.toInt()+8;
  498. if(utc8s>23)rijinwei=1;
  499. utc8s=utc8s%24;
  500. jianyan = String(GPRMC[9]);
  501. jianyan += GPRMC[10];
  502. utc8f=jianyan.toInt();
  503. jianyan = String(GPRMC[11]);
  504. jianyan += GPRMC[12];
  505. utc8m=jianyan.toInt();
  506. int jsq2=0;
  507. int jsq3=0;
  508. int jsq4=0;
  509. int jsq5=0;
  510.   for(int col=0;col<99;col++){
  511.   if(GPRMC[col]==',')jsq2++;
  512. if(jsq2==9){
  513. jsq3=col;
  514. col=99;
  515. }
  516. if(jsq2<8){
  517. jsq4=col;
  518. }
  519. if(jsq2<6){
  520. jsq5=col;
  521. }
  522. }
  523. for(int col=0;col<12;col++)tempx[col]=0;
  524. memcpy(tempx,GPRMC+jsq5+4,jsq4-jsq5-3);
  525. for(int col=0;col<jsq4-jsq5-3;col++){
  526. if(tempx[col]==46){
  527. if(col==1)fentodu=(tempx[0]-48)*1000;
  528. else if(col==2)fentodu=(tempx[0]-48)*10000+(tempx[1]-48)*1000;
  529. else if(col==3)fentodu=(tempx[0]-48)*100000+(tempx[1]-48)*10000+(tempx[2]-48)*1000;
  530. if(jsq4-jsq5-col==5)fentodu=fentodu+(tempx[col+1]-48)*100;
  531. else if(jsq4-jsq5-col==6)fentodu=fentodu+(tempx[col+1]-48)*100+(tempx[col+2]-48)*10;
  532. else if(jsq4-jsq5-col==7)fentodu=fentodu+(tempx[col+1]-48)*100+(tempx[col+2]-48)*10+tempx[col+3]-48;
  533. fentodu=fentodu*1852*0.0001;
  534. col=jsq4-jsq5-3;
  535. }
  536. }
  537. float sudu=fentodu*0.01;
  538. for(int col=0;col<8;col++)TrackB5[col]=0;
  539. dtostrf(sudu,1,2,TrackB5);
  540. jianyan = String(GPRMC[jsq3+1]);
  541. jianyan += GPRMC[jsq3+2];
  542. utc8r=jianyan.toInt();
  543. jianyan = String(GPRMC[jsq3+3]);
  544. jianyan += GPRMC[jsq3+4];
  545. utc8y=jianyan.toInt();
  546. jianyan = String(GPRMC[jsq3+5]);
  547. jianyan += GPRMC[jsq3+6];
  548. utc8n=jianyan.toInt();
  549. if(rijinwei){
  550. if(utc8y==2 && utc8r==28){
  551. if(utc8n % 400 == 0 || utc8n % 100 != 0 && utc8n % 4 == 0)utc8r=29;
  552. else {
  553. utc8r=1;
  554. yuejinwei=1;
  555. }
  556. }else{
  557. for(int col=0;col<4;col++){
  558. if(xiaoyue[col]==utc8y)xiaoyueok=1;
  559. }
  560. if(xiaoyueok && utc8r==30){
  561. utc8r=1;
  562. yuejinwei=1;
  563. }else if(!xiaoyueok && utc8r==31){
  564. utc8r=1;
  565. yuejinwei=1;
  566. }else{
  567. utc8r++;
  568. }
  569. }
  570. }
  571. if(yuejinwei && utc8y==12){
  572. utc8y=1;
  573. nianjinwei=1;
  574. }else if(yuejinwei){
  575. utc8y++;
  576. }
  577. if(nianjinwei)utc8n++;
  578.   }
  579.   
  580. void Linename()
  581. {
  582.     for(int col=0;col<12;col++)tempx[col]=0;
  583.   if(EEPROMvalue<10){
  584. tempx[0]=48;
  585. tempx[1]=48;
  586.   tempx[2]=EEPROMvalue+48;
  587.   }else if(EEPROMvalue<100){
  588.   tempx[0]=48;
  589. Linenumber=EEPROMvalue*0.1;
  590.   tempx[1]=Linenumber+48;
  591.    Linenumber=EEPROMvalue%10;
  592.     tempx[2]=Linenumber+48;
  593.   }else{
  594.     Linenumber=EEPROMvalue*0.01;
  595.   tempx[0]=Linenumber+48;
  596.   Linenumber=EEPROMvalue*0.1;
  597.     Linenumber=Linenumber%10;
  598.   tempx[1]=Linenumber+48;
  599.    Linenumber=EEPROMvalue%10;
  600.     tempx[2]=Linenumber+48;
  601.   }
  602.   memcpy(TrackAL,tempx,3);
  603.   }

  604. void Trackname()
  605. {

  606.    EEPROMvalue= EEPROM.read(6);
  607.    if(EEPROMvalue <250){
  608.    gpxjiluguijishu=EEPROMvalue;
  609.    EEPROMvalue= EEPROM.read(5);
  610.    gpxjiluguijishu=EEPROMvalue*250+gpxjiluguijishu;
  611.    }else{
  612.    gpxjiluguijishu=0;
  613.    EEPROM.write(6,gpxjiluguijishu);
  614.    EEPROMvalue= EEPROM.read(5);
  615.    if(EEPROMvalue<240){
  616.    EEPROMvalue++;
  617.    EEPROM.write(5,EEPROMvalue);
  618.    gpxjiluguijishu=EEPROMvalue*250;
  619.    }else{
  620.    EEPROM.write(5,0);
  621.    gpxjiluguijishu=0;
  622.    }
  623.    }
  624.   for(int col=0;col<12;col++)tempx[col]=0;
  625. if(gpxjiluguijishu>9999)sprintf(tempx, "%d", gpxjiluguijishu);
  626. else if(gpxjiluguijishu>999){
  627. tempx[0]=48;
  628. sprintf(tempx+1, "%d", gpxjiluguijishu);
  629. }else if(gpxjiluguijishu>99){
  630. tempx[0]=48;
  631. tempx[1]=48;
  632. sprintf(tempx+2, "%d", gpxjiluguijishu);
  633. }else if(gpxjiluguijishu>9){
  634. tempx[0]=48;
  635. tempx[1]=48;
  636. tempx[2]=48;
  637. sprintf(tempx+3, "%d", gpxjiluguijishu);
  638. }else{
  639. tempx[0]=48;
  640. tempx[1]=48;
  641. tempx[2]=48;
  642. tempx[3]=48;
  643. sprintf(tempx+4, "%d", gpxjiluguijishu);
  644. }
  645.   memcpy(TrackAN,tempx,5);
  646. }

复制代码


其他成本,效果啥的,可以看19楼

本帖子中包含更多资源

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

x
回复

使用道具 举报

 楼主| 发表于 2014-10-19 00:09:01 | 显示全部楼层
本帖最后由 hi55234 于 2014-11-5 23:27 编辑

版本2
1602用了并口,省了i2c库的空间,所以,海拔加进去了,GPS也有一定的自适配性,并不局限于C3-470







  1. #include <MemoryFree.h>

  2. #include <LiquidCrystal.h>
  3. LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
  4. boolean shanshuo=1;


  5. #include <SoftwareSerial.h>
  6. SoftwareSerial gps(8, 9);
  7. char tempx[12];
  8. char GPRMC[80];
  9. char GPGGA[80];
  10. int gpschangertest;
  11. boolean gpschanger;
  12. int weiduA;
  13. unsigned long weiduB,weiduC;
  14. int jingduA;
  15. unsigned long jingduB,jingduC;


  16. boolean GPGGAget=0;
  17. boolean GPRMCget=0;
  18. unsigned long gpstimes;
  19. boolean konghangpanduan;
  20. boolean gpsshuchuqiehuanB=0;
  21. int jsq1=0;
  22. int jsq2=0;
  23. int jsq3=0;
  24. int jsq4=0;
  25. int jsq5=0;
  26. int jsq6=0;
  27. int jsq7=0;
  28. int GPGGAlong=0;
  29. int GPRMClong=0;
  30. boolean jiaoyanjieguoA,jiaoyanjieguoC;
  31. float sudu;

  32. String jianyan="";
  33. int yihuoyunsuan;



  34. boolean dingweiok=0;

  35. /*---------------------GPS end---------------------------------*/
  36. int gpsshuchuqiehuanA;



  37. #include<EEPROM.h>
  38. int EEPROMvalue;


  39. #include <SD.h>


  40. const int chipSelect = 10;


  41. boolean gpxstart;
  42. boolean gpxmiddleA;
  43. boolean gpxmiddleB=1;
  44. boolean gpxendA;
  45. boolean gpxendB;



  46. int gpxjilujiangeA;
  47. int gpxjilujiangeB=256;



  48. int gpxjiludianshu;
  49. int gpxjiluguijishu;




  50. char TrackAL[4]="000";


  51. char TrackB0[8]="-0000.0";

  52. char TrackB1[11]="00.0000000";
  53. char TrackB2[12]="000.0000000";

  54. char TrackB4[20]="2000-00-00T00:00:00";

  55. char TrackB5[8]="0000.00";
  56. char TrackB6[7]="000.00";


  57. boolean weiduxuweitiao=0;
  58. boolean jingduxuweitiao=0;
  59. int weiduzhanwei,jingduzhanwei;


  60. int utc8s,utc8f,utc8m,utc8n,utc8y,utc8r;

  61. int xiaoyue[5]={4,6,9,11};

  62. boolean rijinwei,yuejinwei,nianjinwei,xiaoyueok;

  63. unsigned long fentodu;
  64. int Linenumber;
  65. int Tracknumber;


  66. void setup() {

  67. pinMode(14,INPUT);

  68. lcd.begin(16, 2);


  69. Serial.begin(9600);
  70. gps.begin(9600);


  71. EEPROMvalue= EEPROM.read(0);
  72. if(EEPROMvalue==0)gpsshuchuqiehuanB=0;
  73. else gpsshuchuqiehuanB=1;



  74. EEPROMvalue= EEPROM.read(1);
  75. if(EEPROMvalue==255) EEPROMvalue=0;

  76. Linename();



  77.   EEPROMvalue= EEPROM.read(2);
  78. if(EEPROMvalue==0)gpxjilujiangeA=1;
  79. else gpxjilujiangeA=EEPROMvalue;



  80.   EEPROMvalue= EEPROM.read(3);
  81.   gpxjiludianshu=EEPROMvalue*25;
  82.    
  83.   EEPROMvalue++;
  84.   EEPROM.write(3, EEPROMvalue);




  85.   pinMode(10, OUTPUT);


  86.   if (!SD.begin(chipSelect)) {
  87.   lcd.print("SD Card failed! ");
  88.     return;
  89.   }
  90. }


  91. void loop() {


  92. ruanchuankou();

  93. if(millis()-gpstimes>10 && !konghangpanduan){
  94. konghangpanduan=1;
  95. gpxjilujiangeB++;

  96. gpsdechuli();



  97. if(!gpsshuchuqiehuanB){
  98. Serial.println(GPGGA);
  99. Serial.println(GPRMC);
  100. Serial.print(freeMemory());
  101. Serial.println("---------------------");
  102. }

  103. if(jiaoyanjieguoA)jiexiGPGGA();

  104. if(jiaoyanjieguoC){
  105. jiexiGPRMC();

  106. if(dingweiok && gpschanger) {
  107. gpschanger=0;


  108. if(gpxjilujiangeB>gpxjilujiangeA){
  109. gpxjilujiangeB=0;
  110. gpxjiludianshu++;


  111. if(gpxjiludianshu%25==0){
  112. EEPROMvalue= EEPROM.read(3);
  113. EEPROMvalue++;


  114. if(EEPROMvalue>108){
  115. EEPROMvalue=0;
  116. EEPROM.write(3, 0);
  117. gpxjiludianshu=0;



  118. EEPROM.write(8,0);
  119. EEPROM.write(9,0);


  120. sdcaozuo();


  121. }else {

  122. EEPROM.write(3, EEPROMvalue);
  123. }


  124. }


  125. sdcaozuo();
  126. }


  127. }

  128. }


  129. /*
  130. G:A B F:xxx SD:G
  131. 0123456789012345
  132. G:V _ F:xxx SD:E
  133. */



  134.   shanshuo=!shanshuo;
  135.   
  136.   lcd.setCursor(0, 0);
  137.   
  138. if(shanshuo)lcd.print("G:");
  139. else lcd.print(" :");
  140.   
  141.   if(dingweiok)lcd.print("A");
  142.   else lcd.print("V");

  143. if(gpsshuchuqiehuanB)lcd.print(" B F:");
  144. else lcd.print(" _ F:");

  145. lcd.print(freeMemory());
  146. lcd.print(" SD:");

  147. lcd.setCursor(0, 1);
  148. if(dingweiok){
  149. lcd.print(TrackB0);
  150. lcd.print("M ");
  151. lcd.print(TrackB5);
  152. lcd.print("km/h     ");
  153. }else{
  154. lcd.print(TrackB0);
  155. lcd.print(" M *.* km/h     ");

  156. }




  157.   gpsshuchuqiehuanA =digitalRead(14);
  158. if (gpsshuchuqiehuanA==HIGH){
  159. gpsshuchuqiehuanB=!gpsshuchuqiehuanB;
  160. EEPROM.write(0,gpsshuchuqiehuanB);
  161. }






  162. for(int col=0;col<80;col++)GPRMC[col]=0;
  163. for(int col=0;col<80;col++)GPGGA[col]=0;
  164. for(int col=0;col<12;col++)tempx[col]=0;
  165. jsq1=0;
  166. GPGGAget=0;
  167. GPRMCget=0;
  168. }

  169. }



  170. void ruanchuankou()
  171. {


  172. while (gps.available() > 0) {
  173. gpstimes=millis();
  174. konghangpanduan=0;


  175. if(GPRMCget){
  176. GPRMC[jsq1]=gps.read();
  177. if(gpsshuchuqiehuanB)Serial.print(GPRMC[jsq1]);
  178. if(GPRMC[jsq1-3]=='*'){
  179. GPRMClong=jsq1;
  180. GPRMCget=0;
  181. jsq1=0;
  182. }else if(jsq1<79)jsq1++;



  183. }else if(GPGGAget){

  184. GPGGA[jsq1]=gps.read();
  185. if(gpsshuchuqiehuanB)Serial.print(GPGGA[jsq1]);
  186. if(GPGGA[jsq1-3]=='*'){
  187. GPGGAlong=jsq1;
  188. GPGGAget=0;
  189. jsq1=0;
  190. }else if(jsq1<79)jsq1++;



  191. }else{
  192. tempx[jsq1]=gps.read();
  193. if(gpsshuchuqiehuanB)Serial.print(tempx[jsq1]);
  194. if(jsq1<6)jsq1++;

  195. }



  196. if(jsq1==6){


  197. if(tempx[4]=='M' && tempx[5]=='C'){

  198. GPRMCget=1;
  199. GPGGAget=0;
  200. for(int col=0;col<6;col++)GPRMC[col]=tempx[col];
  201. for(int col=0;col<6;col++)tempx[col]=0;

  202. }else if(tempx[jsq1-2]=='G' && tempx[jsq1-1]=='A'){

  203. GPGGAget=1;
  204. GPRMCget=0;
  205. for(int col=0;col<6;col++)GPGGA[col]=tempx[col];
  206. for(int col=0;col<6;col++)tempx[col]=0;

  207. }else{

  208. for(int col=0;col<5;col++)tempx[col]=tempx[col+1];
  209. jsq1=5;
  210. }

  211. }


  212. }



  213. }


  214. void gpsdechuli()
  215. {

  216. for(int col=1;col<GPRMClong-3;col++){
  217. if(col==1)yihuoyunsuan=GPRMC[col];
  218. else yihuoyunsuan=yihuoyunsuan ^ GPRMC[col];
  219. }

  220. if(yihuoyunsuan==0){
  221. jianyan="00";
  222. }else if(yihuoyunsuan>15){
  223. jianyan = String(yihuoyunsuan,HEX);
  224. }else{
  225. jianyan = "0";
  226. jianyan += String(yihuoyunsuan,HEX);
  227. }
  228. jianyan.toUpperCase();
  229. if(jianyan[0]==GPRMC[GPRMClong-2] && jianyan[1]==GPRMC[GPRMClong-1] ){
  230. jiaoyanjieguoC=1;
  231. }else{
  232. jiaoyanjieguoC=0;
  233. }

  234. jianyan="";




  235. for(int col=1;col<GPGGAlong-3;col++){
  236. if(col==1)yihuoyunsuan=GPGGA[col];
  237. else yihuoyunsuan=yihuoyunsuan ^ GPGGA[col];
  238. }

  239. if(yihuoyunsuan==0){
  240. jianyan="00";
  241. }else if(yihuoyunsuan>15){
  242. jianyan = String(yihuoyunsuan,HEX);
  243. }else{
  244. jianyan = "0";
  245. jianyan += String(yihuoyunsuan,HEX);
  246. }
  247. jianyan.toUpperCase();
  248. if(jianyan[0]==GPGGA[GPGGAlong-2] && jianyan[1]==GPGGA[GPGGAlong-1] ){
  249. jiaoyanjieguoA=1;
  250. }else{
  251. jiaoyanjieguoA=0;
  252. }


  253. jianyan="";


  254. }


  255. void jiexiGPGGA()
  256. {

  257.    jsq2=0;
  258.    jsq3=0;
  259.    jsq4=0;
  260.    jsq5=0;


  261.     for(int col=1;col<GPGGAlong-3;col++){
  262.      if(GPGGA[col]==',')jsq2++;
  263.    if(jsq2==10){
  264.    jsq3=col;
  265.    col=GPGGAlong-3;
  266.    }
  267.    
  268.   
  269.    if(jsq2<9)jsq4=col;
  270.   
  271.    if(jsq2<7)jsq5=col;
  272.    
  273.    }
  274.    
  275.   
  276.    if(GPGGA[jsq5]==49)dingweiok=1;
  277.    else dingweiok=0;
  278.    
  279.   
  280. for(int col=0;col<8;col++)TrackB0[col]=0;
  281. memcpy(TrackB0,GPGGA+jsq4+2, jsq3-jsq4-2);

  282. }


  283. void jiexiGPRMC()
  284. {

  285.    jsq2=0;
  286.    jsq3=0;
  287.    jsq4=0;
  288.    jsq5=0;
  289.    jsq6=0;
  290.    jsq7=0;
  291.    
  292.     for(int col=1;col<GPRMClong-3;col++){
  293.      if(GPRMC[col]==',')jsq2++;
  294.    if(jsq2==9){
  295.    jsq3=col;
  296.    col=GPRMClong-3;
  297.    }
  298.    
  299.    if(jsq2<8)jsq4=col;
  300.    if(jsq2<6)jsq5=col;
  301.    if(jsq2<4)jsq6=col;
  302.    if(jsq2<2)jsq7=col;
  303.    }


  304.   if(GPRMC[jsq7+2]=='A')chinatime();


  305. if(dingweiok){

  306. jingweiduchuli();
  307. hangxiangyusudu();

  308. }else {
  309.   weiduA=0;
  310.   weiduB=0;
  311.   weiduC=0;
  312.   jingduA=0;
  313.   jingduB=0;
  314.   jingduC=0;
  315. }


  316. }


  317.   void chinatime()
  318. {


  319. jianyan = String(GPRMC[7]);
  320. jianyan += GPRMC[8];
  321. utc8s=jianyan.toInt()+8;


  322. if(utc8s>23)rijinwei=1;
  323. utc8s=utc8s%24;

  324. jianyan = String(GPRMC[9]);
  325. jianyan += GPRMC[10];
  326. utc8f=jianyan.toInt();



  327. jianyan = String(GPRMC[11]);
  328. jianyan += GPRMC[12];
  329. utc8m=jianyan.toInt();







  330. jianyan = String(GPRMC[jsq3+1]);
  331. jianyan += GPRMC[jsq3+2];
  332. utc8r=jianyan.toInt();




  333. jianyan = String(GPRMC[jsq3+3]);
  334. jianyan += GPRMC[jsq3+4];
  335. utc8y=jianyan.toInt();



  336. jianyan = String(GPRMC[jsq3+5]);
  337. jianyan += GPRMC[jsq3+6];
  338. utc8n=jianyan.toInt();





  339. if(rijinwei){

  340. if(utc8y==2 && utc8r==28){
  341. if(utc8n % 400 == 0 || utc8n % 100 != 0 && utc8n % 4 == 0)utc8r=29;
  342. else {
  343. utc8r=1;
  344. yuejinwei=1;
  345. }
  346. }else{

  347. for(int col=0;col<4;col++){
  348. if(xiaoyue[col]==utc8y)xiaoyueok=1;
  349. }
  350. if(xiaoyueok && utc8r==30){
  351. utc8r=1;
  352. yuejinwei=1;
  353. }else if(!xiaoyueok && utc8r==31){
  354. utc8r=1;
  355. yuejinwei=1;
  356. }else{
  357. utc8r++;
  358. }
  359. }
  360. }
  361. if(yuejinwei && utc8y==12){
  362. utc8y=1;
  363. nianjinwei=1;
  364. }else if(yuejinwei){
  365. utc8y++;
  366. }
  367. if(nianjinwei)utc8n++;



  368. for(int col=0;col<12;col++)tempx[col]=0;
  369. if(utc8n>9){
  370. sprintf(tempx, "%d", utc8n);
  371. memcpy(TrackB4+2,tempx, 2);
  372. }else{
  373.   TrackB4[2]=48;
  374.   TrackB4[3]=utc8n+48;

  375. }

  376.   for(int col=0;col<12;col++)tempx[col]=0;
  377.   if(utc8y>9){
  378.   sprintf(tempx, "%d", utc8y);
  379. memcpy(TrackB4+5,tempx, 2);
  380. } else{
  381.   TrackB4[5]=48;
  382.    TrackB4[6]=utc8y+48;

  383. }
  384.    for(int col=0;col<12;col++)tempx[col]=0;
  385. if(utc8r>9){
  386. sprintf(tempx, "%d", utc8r);
  387. memcpy(TrackB4+8,tempx, 2);
  388. }else{
  389.   TrackB4[8]=48;
  390. TrackB4[9]=utc8r+48;

  391. }

  392.     for(int col=0;col<12;col++)tempx[col]=0;
  393. if(utc8s>9){
  394. sprintf(tempx, "%d", utc8s);
  395. memcpy(TrackB4+11,tempx, 2);
  396. }else{
  397. TrackB4[11]=48;
  398. TrackB4[12]=utc8s+48;

  399. }
  400.     for(int col=0;col<12;col++)tempx[col]=0;
  401. if(utc8f>9){
  402. sprintf(tempx, "%d", utc8f);
  403. memcpy(TrackB4+14,tempx, 2);
  404. }else{
  405. TrackB4[14]=48;
  406.   TrackB4[15]=utc8f+48;
  407. }

  408.     for(int col=0;col<12;col++)tempx[col]=0;
  409.   if(utc8m>9){
  410.   sprintf(tempx, "%d", utc8m);
  411. memcpy(TrackB4+17,tempx, 2);
  412. }else{
  413. TrackB4[17]=48;
  414.   TrackB4[18]=utc8m+48;
  415. }


  416. }


  417. void jingweiduchuli()
  418. {


  419. for(int col=0;col<12;col++)tempx[col]=0;
  420. memcpy(tempx,GPRMC+jsq7+4, 2);
  421. jianyan =tempx;
  422. gpschangertest=jianyan.toInt();
  423. if(weiduA!=gpschangertest){
  424. weiduA=gpschangertest;
  425. gpschanger=1;
  426. }



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


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

  430. if(gpschangertest<10) {
  431. TrackB1[0]=32;
  432. weiduzhanwei=1;
  433. }else weiduzhanwei=2;


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

  435. memcpy(tempx,GPRMC+jsq7+6, 2);
  436. jianyan =tempx;
  437. gpschangertest=jianyan.toInt();
  438. if(weiduB!=gpschangertest){
  439. weiduB=gpschangertest;
  440. gpschanger=1;
  441. }



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

  443. memcpy(tempx,GPRMC+jsq7+9, 4);
  444. if(jsq6-jsq7==12) memcpy(tempx,GPRMC+jsq7+9, 4);
  445. else if(jsq6-jsq7==13)memcpy(tempx,GPRMC+jsq7+9, 5);


  446. jianyan =tempx;
  447. gpschangertest=jianyan.toInt();
  448. if(weiduC!=gpschangertest){
  449. weiduC=gpschangertest;
  450. gpschanger=1;
  451. }


  452. fentodu=weiduB*100000+weiduC*10;
  453. fentodu=fentodu/6;

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





  456. if(fentodu>99999){
  457. memcpy(TrackB1+3,tempx, 6);
  458. }else if(fentodu>9999){
  459. TrackB1[3]=48;
  460.   memcpy(TrackB1+4,tempx, 5);
  461. }else if(fentodu>999){
  462. TrackB1[3]=48;
  463. TrackB1[4]=48;
  464.   memcpy(TrackB1+5,tempx, 4);

  465. }else if(fentodu>99){
  466. TrackB1[3]=48;
  467. TrackB1[4]=48;
  468. TrackB1[5]=48;
  469.   memcpy(TrackB1+6,tempx, 3);

  470. }else if(fentodu>9){
  471. TrackB1[3]=48;
  472. TrackB1[4]=48;
  473. TrackB1[5]=48;
  474. TrackB1[6]=48;
  475.   memcpy(TrackB1+7,tempx, 2);
  476. }else{
  477. TrackB1[3]=48;
  478. TrackB1[4]=48;
  479. TrackB1[5]=48;
  480. TrackB1[6]=48;
  481. TrackB1[7]=48;
  482.   memcpy(TrackB1+8,tempx, 1);

  483. }





  484. if(weiduxuweitiao){
  485. weiduxuweitiao=0;

  486. if(weiduzhanwei==2){


  487.    for(int col=0;col<12;col++)tempx[col]=0;
  488. tempx[0]=45;
  489. memcpy(tempx+1,TrackB1, 9);
  490. memcpy(TrackB1,tempx, 10);

  491. }else{

  492.   TrackB1[0]=45;

  493. }

  494. }





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

  496.    memcpy(tempx,GPRMC+jsq6+4, 3);
  497. jianyan =tempx;
  498. gpschangertest=jianyan.toInt();
  499. if(jingduA!=gpschangertest){
  500. jingduA=gpschangertest;
  501. gpschanger=1;
  502. }





  503.   memcpy(TrackB2,GPRMC+jsq6+4, 3);
  504. jingduzhanwei=3;

  505. if(gpschangertest<100) {
  506. TrackB2[0]=32;
  507. jingduzhanwei=2;
  508. }

  509. if(gpschangertest<10) {
  510. TrackB2[1]=32;
  511. jingduzhanwei=1;
  512. }

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

  514. memcpy(tempx,GPRMC+jsq6+7, 3);
  515. jianyan =tempx;
  516. gpschangertest=jianyan.toInt();
  517. if(jingduB!=gpschangertest){
  518. jingduB=gpschangertest;
  519. gpschanger=1;
  520. }

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

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

  524. jianyan =tempx;
  525. gpschangertest=jianyan.toInt();
  526. if(jingduC!=gpschangertest){
  527. jingduC=gpschangertest;
  528. gpschanger=1;
  529. }

  530. jianyan="";


  531.   fentodu=jingduB*100000+jingduC*10;
  532. fentodu=fentodu/6;

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





  535. if(fentodu>99999){
  536. memcpy(TrackB2+4,tempx, 6);
  537. }else if(fentodu>9999){
  538. TrackB2[4]=48;
  539.   memcpy(TrackB2+5,tempx, 5);
  540. }else if(fentodu>999){
  541. TrackB2[4]=48;
  542. TrackB2[5]=48;
  543.   memcpy(TrackB2+6,tempx, 4);

  544. }else if(fentodu>99){
  545. TrackB2[4]=48;
  546. TrackB2[5]=48;
  547. TrackB2[6]=48;
  548.   memcpy(TrackB2+7,tempx, 3);

  549. }else if(fentodu>9){
  550. TrackB2[4]=48;
  551. TrackB2[5]=48;
  552. TrackB2[6]=48;
  553. TrackB2[7]=48;
  554.   memcpy(TrackB2+8,tempx, 2);
  555. }else{
  556. TrackB2[4]=48;
  557. TrackB2[5]=48;
  558. TrackB2[6]=48;
  559. TrackB2[7]=48;
  560. TrackB2[8]=48;
  561.   memcpy(TrackB2+9,tempx, 1);

  562. }





  563. if(jingduxuweitiao){
  564. jingduxuweitiao=0;

  565. if(jingduzhanwei==3){


  566.    for(int col=0;col<12;col++)tempx[col]=0;
  567. tempx[0]=45;
  568. memcpy(tempx+1,TrackB2, 10);
  569. memcpy(TrackB2,tempx, 11);

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

  571.   TrackB2[0]=45;

  572. }else{

  573. TrackB2[1]=45;
  574. }

  575. }


  576. }


  577. void hangxiangyusudu()
  578. {

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


  581. for(int col=0;col<jsq4-jsq5-3;col++){

  582. if(tempx[col]==46){




  583. if(col==1)fentodu=(tempx[0]-48)*1000;
  584. else if(col==2)fentodu=(tempx[0]-48)*10000+(tempx[1]-48)*1000;
  585. else if(col==3)fentodu=(tempx[0]-48)*100000+(tempx[1]-48)*10000+(tempx[2]-48)*1000;





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





  589. fentodu=fentodu*1852*0.0001;
  590. col=jsq4-jsq5-3;

  591. }

  592. }


  593. sudu=fentodu*0.01;
  594. for(int col=0;col<8;col++)TrackB5[col]=0;
  595. dtostrf(sudu,1,2,TrackB5);


  596. for(int col=0;col<7;col++)TrackB6[col]=0;
  597. memcpy(TrackB6,GPRMC+jsq4+2, jsq3-jsq4-2);


  598. }


  599.   void sdcaozuo()
  600. {




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

  602.   tempx[0]='L';
  603.   tempx[1]='i';
  604.   tempx[2]='n';
  605.   tempx[3]='e';
  606.   memcpy(tempx+4,TrackAL,3);
  607.   tempx[7]='.';
  608.   tempx[8]='g';
  609.   tempx[9]='p';
  610.   tempx[10]='x';


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



  612.   if (dataFile) {

  613.   lcd.setCursor(15, 0);
  614. lcd.print("G");


  615.   
  616.       EEPROMvalue= EEPROM.read(4);
  617.       if(EEPROMvalue==0) gpxstart=1;
  618.       else gpxstart=0;
  619.      
  620.      
  621.    
  622.     EEPROMvalue= EEPROM.read(7);
  623.     if(EEPROMvalue==0){
  624.     gpxmiddleA=1;
  625.    
  626.    
  627.     }else gpxmiddleA=0;
  628.    
  629.       EEPROMvalue= EEPROM.read(8);
  630.       if(EEPROMvalue==0) gpxendA=1;
  631.       else gpxendA=0;

  632.       EEPROMvalue= EEPROM.read(9);
  633.       if(EEPROMvalue==0) gpxendB=1;
  634.       else gpxendB=0;
  635.      

  636. if(gpxstart){
  637. EEPROM.write(4, 1);


  638. for(int col=0;col<80;col++)GPRMC[col]=0;
  639. for(int i=50;i<77;i++)GPRMC[i-50] = EEPROM.read(i);

  640. dataFile.print(GPRMC);



  641.   }



  642. if(gpxmiddleA){       
  643. EEPROM.write(7, 1);



  644. for(int col=0;col<80;col++)GPRMC[col]=0;
  645. for(int i=77;i<89;i++)GPRMC[i-77] = EEPROM.read(i);

  646. dataFile.print(GPRMC);
  647. dataFile.print(TrackAL);






  648. for(int col=0;col<80;col++)GPRMC[col]=0;
  649. for(int i=89;i<110;i++)GPRMC[i-89] = EEPROM.read(i);

  650. dataFile.println(GPRMC);



  651. }


  652. if(gpxmiddleB){


  653.   
  654.    for(int col=0;col<80;col++)GPRMC[col]=0;
  655.    for(int i=110;i<123;i++)GPRMC[i-110] = EEPROM.read(i);
  656.    dataFile.print(GPRMC);
  657.    dataFile.print(TrackB1);
  658.    



  659.    for(int col=0;col<80;col++)GPRMC[col]=0;
  660.    for(int i=123;i<131;i++)GPRMC[i-123] = EEPROM.read(i);
  661.    dataFile.print(GPRMC);

  662.    dataFile.print(TrackB2);
  663.    




  664. for(int col=0;col<80;col++)GPRMC[col]=0;
  665. for(int i=131;i<140;i++)GPRMC[i-131] = EEPROM.read(i);
  666.    dataFile.print(GPRMC);

  667.    dataFile.print(TrackB4);
  668.    



  669.    for(int col=0;col<80;col++)GPRMC[col]=0;
  670.    for(int i=140;i<158;i++)GPRMC[i-140] = EEPROM.read(i);
  671.    dataFile.println(GPRMC);


  672. }


  673. if(gpxendA){
  674. EEPROM.write(8,1);

  675. EEPROM.write(7,0);

  676.   for(int col=0;col<80;col++)GPRMC[col]=0;
  677.   for(int i=158;i<174;i++)GPRMC[i-158] = EEPROM.read(i);
  678.    dataFile.print(GPRMC);


  679. EEPROMvalue= EEPROM.read(6);
  680. EEPROMvalue++;
  681. EEPROM.write(6,EEPROMvalue);

  682.   }


  683.   if(gpxendB){
  684. EEPROM.write(9,1);

  685. EEPROM.write(4,0);


  686.   for(int col=0;col<80;col++)GPRMC[col]=0;
  687.   for(int i=174;i<181;i++)GPRMC[i-174] = EEPROM.read(i);
  688.    dataFile.print(GPRMC);
  689.    




  690. EEPROMvalue= EEPROM.read(1);
  691. EEPROMvalue++;
  692. if(EEPROMvalue==255) EEPROMvalue=0;
  693. EEPROM.write(1, EEPROMvalue);
  694. Linename();


  695.   }


  696.   }else{
  697.   lcd.setCursor(15, 0);
  698.   lcd.print("E");

  699.   }



  700. dataFile.close();



  701. }

  702.   
  703. void Linename()
  704. {

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

  706. if(EEPROMvalue<10){
  707. tempx[0]=48;
  708. tempx[1]=48;
  709.   tempx[2]=EEPROMvalue+48;

  710. }else if(EEPROMvalue<100){
  711.   tempx[0]=48;
  712. Linenumber=EEPROMvalue*0.1;
  713.   tempx[1]=Linenumber+48;
  714.    Linenumber=EEPROMvalue%10;
  715.     tempx[2]=Linenumber+48;

  716. }else{

  717.    Linenumber=EEPROMvalue*0.01;
  718.   tempx[0]=Linenumber+48;
  719.   Linenumber=EEPROMvalue*0.1;
  720.     Linenumber=Linenumber%10;
  721.   tempx[1]=Linenumber+48;
  722.    Linenumber=EEPROMvalue%10;
  723.     tempx[2]=Linenumber+48;

  724. }


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

  727. }


复制代码

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-20 10:26:02 | 显示全部楼层
本帖最后由 hi55234 于 2014-10-30 22:05 编辑

太长不看········
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-20 21:38:00 | 显示全部楼层
一段测试程序,关于int 转 字符串
  1. char tempx[7];
  2. unsigned long fentodu;//分到度的转换
  3. unsigned long  weiduB=1;
  4. unsigned long weiduC=1;
  5. void setup() {

  6.   Serial.begin(9600);
  7. }


  8. void loop() {

  9. fentodu=weiduB*100000;
  10.    Serial.print("fentoduA=");
  11.    Serial.println(fentodu);

  12. fentodu=fentodu+weiduC;

  13.    Serial.print("fentoduB=");
  14.    Serial.println(fentodu);

  15. fentodu=fentodu/6;

  16.     Serial.print("fentoduC=");
  17.    Serial.println(fentodu);
  18.    
  19. for(int col=0;col<7;col++)tempx[col]=0;
  20. sprintf(tempx, "%d", fentodu);   
  21. Serial.print("tempx=");
  22.   Serial.println(tempx);
  23.    Serial.print("fentodu=");
  24.    Serial.println(fentodu);
  25.    
  26.    for(int col=0;col<7;col++)tempx[col]=0;
  27. dtostrf(fentodu,6,0,tempx);
  28. Serial.print("tempx=");
  29.   Serial.println(tempx);
  30.    Serial.print("fentodu=");
  31.    Serial.println(fentodu);
  32. Serial.println("---------------------------------");
  33.   delay(500);
  34.    weiduB++;
  35.     weiduC++;
  36. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-20 23:02:52 | 显示全部楼层
本帖最后由 hi55234 于 2014-10-30 22:56 编辑

太长不看········


最重要的是感谢网友
@卓泰科技/ka
的指点

回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-21 00:17:42 | 显示全部楼层
本帖最后由 hi55234 于 2014-10-30 22:04 编辑


简易的超声波,毫米单位


  1. const int TrigPin = 2;
  2. const int EchoPin = 3;
  3. unsigned long mm;
  4. void setup()
  5. {
  6. Serial.begin(9600);
  7. pinMode(TrigPin, OUTPUT);
  8. pinMode(EchoPin, INPUT);
  9. }
  10. void loop()
  11. {
  12. digitalWrite(TrigPin, LOW); //低高低电平发一个短时间脉冲去TrigPin
  13. delayMicroseconds(2);
  14. digitalWrite(TrigPin, HIGH);
  15. delayMicroseconds(10);
  16. digitalWrite(TrigPin, LOW);

  17. mm = pulseIn(EchoPin, HIGH)*1000; //将回波时间换算成mm
  18. mm = mm / 5882;

  19. Serial.print(mm);
  20. Serial.print("mm");
  21. Serial.println();
  22. delay(1000);
  23. }
复制代码

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-23 09:10:12 | 显示全部楼层
本帖最后由 hi55234 于 2014-10-30 22:04 编辑

神奇的地球,对于大量(大概100多字符的读取),在打印中,还是以数组方式出来比较稳妥
PS:EEPROM之前已写入对字符应数据

太长不看······
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-23 12:26:58 | 显示全部楼层
本帖最后由 hi55234 于 2014-10-30 22:03 编辑

楼太长,没法看
回复 支持 反对

使用道具 举报

发表于 2014-10-23 13:28:33 | 显示全部楼层
本帖最后由 yuqingshan 于 2014-10-23 13:36 编辑

楼主您好,一口气看完您的贴自,还真的不容易,值得收藏研究的好帖子。

我目前也是进行GPS校时,DS3231计时这样的电子钟折腾中,采用是蓝牙传送GPS数据,转换显示时间,参考是帖:
http://www.geek-workshop.com/thread-10584-1-1.html
http://www.geek-workshop.com/thread-8254-1-1.html
http://www.geek-workshop.com/thread-9151-1-1.html

目前显示时间没有问题,但有一问题想请教:
就是关闭蓝牙后,时钟也停止了,但是蓝牙打开时,不管是否有卫星信号,时钟都能运行,可像是利用GPS模块内部时钟。但是我想设计成蓝牙仅仅作校时用,不常开蓝牙,每隔一、两星期才开一次,DS3231才是正常时钟的运行的,研究一段时间,不得其法,能指导一下该部分的代码如何写吗?谢谢。

附代码:

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-23 14:21:39 | 显示全部楼层
yuqingshan 发表于 2014-10-23 13:28
楼主您好,一口气看完您的贴自,还真的不容易,值得收藏研究的好帖子。

我目前也是进行GPS校时,DS3231计 ...

如果你用的我的代码,你细看一下,就会知道
我把gps当做外部晶振(或者说定时器在用)
当gps没有信号,或者说对应串口没有数据输入时,程序的其他部分是不会执行的····

如果要做到和gps无关性,你改一下代码就可以了
回复 支持 反对

使用道具 举报

发表于 2014-10-23 16:15:34 | 显示全部楼层
哦,楼主您好,按原理应该可行,不过一时还没有试过您的代码,本人E文太烂,很长时间才读懂,需慢慢研究,如果现成代码是想偷懒,谢谢楼主。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-24 09:31:07 | 显示全部楼层
本帖最后由 hi55234 于 2014-10-30 22:07 编辑

内存溢出版本~~~程序执行不正常

回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-24 12:15:53 | 显示全部楼层
本帖最后由 hi55234 于 2014-10-30 22:09 编辑

File dataFile = SD.open(tempx, FILE_WRITE);
在  dataFile 不为真的情况下,是无法进行写入的

尼玛,霸王硬上弓,依旧不成功
回复 支持 反对

使用道具 举报

发表于 2014-10-24 13:45:48 | 显示全部楼层
LZ,您的代码看到有点懵,下面2点我的理解不知对否?
1)GPS电子钟,应去了BMP180(气压传感器)吧。
2)海平面气压(sea level pressure)换算成高程,可像没有这样必要,因为GPS数据流本身有高程数据的($GPGGA中 <9>,天线离海平面的高度,应该是吧)。
谢谢。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-25 10:49:53 | 显示全部楼层
yuqingshan 发表于 2014-10-24 13:45
LZ,您的代码看到有点懵,下面2点我的理解不知对否?
1)GPS电子钟,应去了BMP180(气压传感器)吧。
2)海 ...

GPS电子钟是不需要气压计的,其实吧,这个程序最开始是属于10DOF的

http://geek-workshop.com/forum.p ... 11140&pid=74900
因为10DOF要求尽可能快的刷新速度,所以gps就以19200波特率只输出GPRMC数据,而GPRMC不带海拔数据(对高程变化,GPS远不及气压精确和灵敏),所以最开始就想偷懒(GPX轨迹记录,带经纬度、海拔、时间)而保留了BMP180的功能

然后悲剧就出现了,BMP180+SD库,程序体积过大+内存告罄(程序跑飞、乱执行)

所以,下一步还需要修改的,最懒的方式直接不要海拔了,勤快点就再用点内存,去分析记录GPGGA

PS:这个程序和以前程序在读取思路上不一样,以前是全部读取之后再慢慢分析,这个是要分析什么就读取什么,内存使用相对较少
回复 支持 反对

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-4-19 20:12 , Processed in 0.052876 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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