hi55234 发表于 2014-10-18 22:09:31

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

本帖最后由 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)全是乱的)
#include<EEPROM.h>
void setup() {
Serial.begin(9600);
EEPROM.write(0,1);
EEPROM.write(1,0);
EEPROM.write(2,10);
EEPROM.write(3,0);
EEPROM.write(4,0);
EEPROM.write(5,0);
EEPROM.write(6,0);
EEPROM.write(7,0);
EEPROM.write(8,1);
EEPROM.write(9,1);
char TrackA0 = "<?xml version=\"1.0\"?><gpx>";
for(int i=0;i<27;i++) EEPROM.write(i+50,TrackA0);
char TrackA1 = "<name>Track";
for(int i=0;i<12;i++) EEPROM.write(i+77,TrackA1);
char TrackA2 = "</name><trk><trkseg>";
for(int i=0;i<21;i++) EEPROM.write(i+89,TrackA2);
char TrackA3= "<trkpt lat=\"";
for(int i=0;i<13;i++) EEPROM.write(i+110,TrackA3);
char TrackA4= "\" lon=\"";
   for(int i=0;i<8;i++) EEPROM.write(i+123,TrackA4);
char TrackA5= "\"><time>";
for(int i=0;i<9;i++) EEPROM.write(i+131,TrackA5);
char TrackA6= "Z</time></trkpt>";
for(int i=0;i<17;i++) EEPROM.write(i+140,TrackA6);
char TrackA7 = "</trkseg></trk>";
    for(int i=0;i<16;i++) EEPROM.write(i+158,TrackA7);
char TrackA8 = "</gpx>";
    for(int i=0;i<7;i++) EEPROM.write(i+174,TrackA8);
Serial.println("EEPROM Write is completed , Please re-download new program");
}

void loop()
{
}


2、主程序:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x26,16,2);
boolean shanshuo=1;
#include <SoftwareSerial.h>
SoftwareSerial gps(8, 9);
char tempx;
int gpschangertest;
boolean gpschanger;
int weiduA;
unsigned long weiduB,weiduC;
int jingduA;
unsigned long jingduB,jingduC;
char GPRMC;
unsigned long gpstimes;
boolean konghangpanduan;
int jsq1=0;
boolean panduan1=0;
boolean panduan2=0;
String jianyan="";
int yihuoyunsuan;
boolean jiaoyanjieguo=0;
boolean dingweiok=0;
int gpsshuchuqiehuanA;
boolean gpsshuchuqiehuanB;
#include<EEPROM.h>
int EEPROMvalue;
#include <SD.h>
const int chipSelect = 10;
boolean gpxstart;
boolean gpxmiddleA;
boolean gpxmiddleB=1;
boolean gpxendA;
boolean gpxendB;
int gpxjilujiangeA;
int gpxjilujiangeB=256;
int gpxjiludianshu;
int gpxjiluguijishu;
char TrackAL="000";
char TrackAN="00000";
char TrackB1="12.1234560";
char TrackB2="123.1234560";
char TrackB4="2007-10-14T10:09:57";
char TrackB5="****.**";
boolean weiduxuweitiao=0;
boolean jingduxuweitiao=0;
int weiduzhanwei,jingduzhanwei;
int utc8s,utc8f,utc8m,utc8n,utc8y,utc8r;
int xiaoyue={4,6,9,11};
boolean rijinwei,yuejinwei,nianjinwei,xiaoyueok;
unsigned long fentodu;
int Linenumber;
int Tracknumber;

void setup() {
pinMode(5,INPUT);
lcd.init();
lcd.backlight();
Serial.begin(9600);
gps.begin(9600);
EEPROMvalue= EEPROM.read(0);
if(EEPROMvalue==0)gpsshuchuqiehuanB=0;
else gpsshuchuqiehuanB=1;
EEPROMvalue= EEPROM.read(1);
if(EEPROMvalue==255) EEPROMvalue=0;
Linename();
EEPROMvalue= EEPROM.read(2);
if(EEPROMvalue==0)gpxjilujiangeA=1;
else gpxjilujiangeA=EEPROMvalue;
EEPROMvalue= EEPROM.read(3);
gpxjiludianshu=EEPROMvalue*25;
EEPROMvalue++;
EEPROM.write(3, EEPROMvalue);
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
    lcd.print("SD Card failed! ");
    return;
}
}

void loop()
{
while (gps.available() > 0) {
gpstimes=millis();
konghangpanduan=0;
if(panduan2){
tempx=gps.read();
if(gpsshuchuqiehuanB)Serial.print(tempx);
}else{
GPRMC = gps.read();
if(gpsshuchuqiehuanB)Serial.print(GPRMC);
}
if(jsq1<79 && !panduan2) jsq1++;
else if(!panduan2) jsq1=79;
if(jsq1>5 && !panduan1){
if(GPRMC=='M' && GPRMC=='C')panduan1=1;
else{
GPRMC=GPRMC;
GPRMC=GPRMC;
GPRMC=GPRMC;
GPRMC=GPRMC;
GPRMC=GPRMC;
jsq1=5;
}
}
if(panduan1 && GPRMC=='*'){
panduan2=1;
}
}
if(millis()-gpstimes>10 && !konghangpanduan){
konghangpanduan=1;
gpxjilujiangeB++;
gpsdechuli();
if(jiaoyanjieguo){
jiaoyanjieguo=0;
jiexiGPRMC();
if(dingweiok && gpschanger) {
gpschanger=0;
if(gpxjilujiangeB>gpxjilujiangeA){
gpxjilujiangeB=0;
gpxjiludianshu++;
if(gpxjiludianshu%25==0){
EEPROMvalue= EEPROM.read(3);
EEPROMvalue++;
if(EEPROMvalue>108){
EEPROMvalue=0;
EEPROM.write(3, 0);
gpxjiludianshu=0;
EEPROM.write(8,0);
EEPROM.write(9,0);
sdcaozuo();
}else {
EEPROM.write(3, EEPROMvalue);
}
}
sdcaozuo();
}
}
}
lcd.setCursor(0, 1);
if(gpsshuchuqiehuanB)lcd.print("BT");
else lcd.print("");
lcd.setCursor(3, 1);
lcd.print(TrackB5);
if(shanshuo)lcd.print("km/h");
else lcd.print("      ");
shanshuo=!shanshuo;
gpsshuchuqiehuanA =digitalRead(5);
if (gpsshuchuqiehuanA==HIGH){
gpsshuchuqiehuanB=!gpsshuchuqiehuanB;
EEPROM.write(0,gpsshuchuqiehuanB);
}
for(int col=0;col<80;col++)GPRMC=0;
jsq1=0;
panduan1=0;
panduan2=0;
}
}

void gpsdechuli()
{
for(int col=1;col<jsq1-3;col++){
if(col==1)yihuoyunsuan=GPRMC;
else yihuoyunsuan=yihuoyunsuan ^ GPRMC;
}
if(yihuoyunsuan==0){
jianyan="00";
}else if(yihuoyunsuan>15){
jianyan = String(yihuoyunsuan,HEX);
}else{
jianyan = "0";
jianyan += String(yihuoyunsuan,HEX);
}
jianyan.toUpperCase();
if(jianyan==GPRMC && jianyan==GPRMC ){
jiaoyanjieguo=1;
}else{
jiaoyanjieguo=0;
}
jianyan="";
}

void jiexiGPRMC()
{
if(GPRMC=='A'){
dingweiok=1;
lcd.setCursor(0, 0);
lcd.print("G:get! ");
for(int col=0;col<12;col++)tempx=0;
memcpy(tempx,GPRMC+20, 2);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(weiduA!=gpschangertest){
weiduA=gpschangertest;
gpschanger=1;
}
if(GPRMC==83)weiduxuweitiao=1;
if(GPRMC==87)jingduxuweitiao=1;
memcpy(TrackB1,GPRMC+20, 2);
if(gpschangertest<10) {
TrackB1=32;
weiduzhanwei=1;
}else weiduzhanwei=2;
for(int col=0;col<12;col++)tempx=0;
memcpy(tempx,GPRMC+22, 2);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(weiduB!=gpschangertest){
weiduB=gpschangertest;
gpschanger=1;
}
for(int col=0;col<12;col++)tempx=0;
memcpy(tempx,GPRMC+25, 4);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(weiduC!=gpschangertest){
weiduC=gpschangertest;
gpschanger=1;
}
fentodu=weiduB*100000+weiduC*10;
fentodu=fentodu/6;
for(int col=0;col<12;col++)tempx=0;
dtostrf(fentodu,6,0,tempx);
if(fentodu>99999){
memcpy(TrackB1+3,tempx, 6);
}else if(fentodu>9999){
TrackB1=48;
memcpy(TrackB1+4,tempx, 5);
}else if(fentodu>999){
TrackB1=48;
TrackB1=48;
memcpy(TrackB1+5,tempx, 4);
}else if(fentodu>99){
TrackB1=48;
TrackB1=48;
TrackB1=48;
memcpy(TrackB1+6,tempx, 3);
}else if(fentodu>9){
TrackB1=48;
TrackB1=48;
TrackB1=48;
TrackB1=48;
memcpy(TrackB1+7,tempx, 2);
}else{
TrackB1=48;
TrackB1=48;
TrackB1=48;
TrackB1=48;
TrackB1=48;
memcpy(TrackB1+8,tempx, 1);
}
if(weiduxuweitiao){
weiduxuweitiao=0;
if(weiduzhanwei==2){
   for(int col=0;col<12;col++)tempx=0;
tempx=45;
memcpy(tempx+1,TrackB1, 9);
memcpy(TrackB1,tempx, 10);
}else{
TrackB1=45;
}
}
for(int col=0;col<12;col++)tempx=0;
memcpy(tempx,GPRMC+32, 3);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(jingduA!=gpschangertest){
jingduA=gpschangertest;
gpschanger=1;
}
memcpy(TrackB2,GPRMC+32, 3);
jingduzhanwei=3;
if(gpschangertest<100) {
TrackB2=32;
jingduzhanwei=2;
}
if(gpschangertest<10) {
TrackB2=32;
jingduzhanwei=1;
}
for(int col=0;col<12;col++)tempx=0;
memcpy(tempx,GPRMC+35, 2);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(jingduB!=gpschangertest){
jingduB=gpschangertest;
gpschanger=1;
}
for(int col=0;col<12;col++)tempx=0;
memcpy(tempx,GPRMC+38, 4);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(jingduC!=gpschangertest){
jingduC=gpschangertest;
gpschanger=1;
}
jianyan="";
fentodu=jingduB*100000+jingduC*10;
fentodu=fentodu/6;
for(int col=0;col<12;col++)tempx=0;
dtostrf(fentodu,6,0,tempx);
if(fentodu>99999){
memcpy(TrackB2+4,tempx, 6);
}else if(fentodu>9999){
TrackB2=48;
memcpy(TrackB2+5,tempx, 5);
}else if(fentodu>999){
TrackB2=48;
TrackB2=48;
memcpy(TrackB2+6,tempx, 4);
}else if(fentodu>99){
TrackB2=48;
TrackB2=48;
TrackB2=48;
memcpy(TrackB2+7,tempx, 3);
}else if(fentodu>9){
TrackB2=48;
TrackB2=48;
TrackB2=48;
TrackB2=48;
memcpy(TrackB2+8,tempx, 2);
}else{
TrackB2=48;
TrackB2=48;
TrackB2=48;
TrackB2=48;
TrackB2=48;
memcpy(TrackB2+9,tempx, 1);
}
if(jingduxuweitiao){
jingduxuweitiao=0;
if(jingduzhanwei==3){
   for(int col=0;col<12;col++)tempx=0;
tempx=45;
memcpy(tempx+1,TrackB2, 10);
memcpy(TrackB2,tempx, 11);
}else if(jingduzhanwei==2){
TrackB2=45;
}else{
TrackB2=45;
}
}
chinatime();
for(int col=0;col<12;col++)tempx=0;
if(utc8n>9){
sprintf(tempx, "%d", utc8n);
memcpy(TrackB4+2,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8n+48;
}
for(int col=0;col<12;col++)tempx=0;
if(utc8y>9){
sprintf(tempx, "%d", utc8y);
memcpy(TrackB4+5,tempx, 2);
} else{
TrackB4=48;
   TrackB4=utc8y+48;
}
   for(int col=0;col<12;col++)tempx=0;
if(utc8r>9){
sprintf(tempx, "%d", utc8r);
memcpy(TrackB4+8,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8r+48;
}
    for(int col=0;col<12;col++)tempx=0;
if(utc8s>9){
sprintf(tempx, "%d", utc8s);
memcpy(TrackB4+11,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8s+48;
}
    for(int col=0;col<12;col++)tempx=0;
if(utc8f>9){
sprintf(tempx, "%d", utc8f);
memcpy(TrackB4+14,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8f+48;
}
    for(int col=0;col<12;col++)tempx=0;
if(utc8m>9){
sprintf(tempx, "%d", utc8m);
memcpy(TrackB4+17,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8m+48;
}
}else {
lcd.setCursor(0, 0);
lcd.print("G:lost! ");
dingweiok=0;
weiduA=0;
   weiduB=0;
    weiduC=0;
jingduA=0;
   jingduB=0;
    jingduC=0;
}
}

void sdcaozuo()
{
for(int col=0;col<12;col++)tempx=0;
tempx='L';
tempx='i';
tempx='n';
tempx='e';
memcpy(tempx+4,TrackAL,3);
tempx='.';
tempx='g';
tempx='p';
tempx='x';
File dataFile = SD.open(tempx, FILE_WRITE);
if (dataFile) {
lcd.setCursor(8, 0);
lcd.print("SD:Good ");
      EEPROMvalue= EEPROM.read(4);
      if(EEPROMvalue==0) gpxstart=1;
      else gpxstart=0;
    EEPROMvalue= EEPROM.read(7);
    if(EEPROMvalue==0){
    gpxmiddleA=1;
    Trackname();
    }else gpxmiddleA=0;
      EEPROMvalue= EEPROM.read(8);
      if(EEPROMvalue==0) gpxendA=1;
      else gpxendA=0;
      EEPROMvalue= EEPROM.read(9);
      if(EEPROMvalue==0) gpxendB=1;
      else gpxendB=0;
if(gpxstart){
EEPROM.write(4, 1);
for(int col=0;col<80;col++)GPRMC=0;
for(int i=50;i<77;i++)GPRMC = EEPROM.read(i);
dataFile.print(GPRMC);
}
if(gpxmiddleA){       
EEPROM.write(7, 1);
for(int col=0;col<80;col++)GPRMC=0;
for(int i=77;i<89;i++)GPRMC = EEPROM.read(i);
dataFile.print(GPRMC);
dataFile.print(TrackAN);
for(int col=0;col<80;col++)GPRMC=0;
for(int i=89;i<110;i++)GPRMC = EEPROM.read(i);
dataFile.println(GPRMC);
}
if(gpxmiddleB){
   for(int col=0;col<80;col++)GPRMC=0;
   for(int i=110;i<123;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);
   dataFile.print(TrackB1);
   for(int col=0;col<80;col++)GPRMC=0;
   for(int i=123;i<131;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);
   dataFile.print(TrackB2);
for(int col=0;col<80;col++)GPRMC=0;
for(int i=131;i<140;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);
   dataFile.print(TrackB4);
   for(int col=0;col<80;col++)GPRMC=0;
   for(int i=140;i<158;i++)GPRMC = EEPROM.read(i);
   dataFile.println(GPRMC);
}
if(gpxendA){
EEPROM.write(8,1);
EEPROM.write(7,0);
for(int col=0;col<80;col++)GPRMC=0;
for(int i=158;i<174;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);
EEPROMvalue= EEPROM.read(6);
EEPROMvalue++;
EEPROM.write(6,EEPROMvalue);
}
if(gpxendB){
EEPROM.write(9,1);
EEPROM.write(4,0);
for(int col=0;col<80;col++)GPRMC=0;
for(int i=174;i<181;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);
EEPROMvalue= EEPROM.read(1);
EEPROMvalue++;
if(EEPROMvalue==255) EEPROMvalue=0;
EEPROM.write(1, EEPROMvalue);
Linename();
}
}else{
lcd.setCursor(8, 0);
lcd.print("SD:Error");
}
dataFile.close();
}

void chinatime()
{
jianyan = String(GPRMC);
jianyan += GPRMC;
utc8s=jianyan.toInt()+8;
if(utc8s>23)rijinwei=1;
utc8s=utc8s%24;
jianyan = String(GPRMC);
jianyan += GPRMC;
utc8f=jianyan.toInt();
jianyan = String(GPRMC);
jianyan += GPRMC;
utc8m=jianyan.toInt();
int jsq2=0;
int jsq3=0;
int jsq4=0;
int jsq5=0;
for(int col=0;col<99;col++){
if(GPRMC==',')jsq2++;
if(jsq2==9){
jsq3=col;
col=99;
}
if(jsq2<8){
jsq4=col;
}
if(jsq2<6){
jsq5=col;
}
}
for(int col=0;col<12;col++)tempx=0;
memcpy(tempx,GPRMC+jsq5+4,jsq4-jsq5-3);
for(int col=0;col<jsq4-jsq5-3;col++){
if(tempx==46){
if(col==1)fentodu=(tempx-48)*1000;
else if(col==2)fentodu=(tempx-48)*10000+(tempx-48)*1000;
else if(col==3)fentodu=(tempx-48)*100000+(tempx-48)*10000+(tempx-48)*1000;
if(jsq4-jsq5-col==5)fentodu=fentodu+(tempx-48)*100;
else if(jsq4-jsq5-col==6)fentodu=fentodu+(tempx-48)*100+(tempx-48)*10;
else if(jsq4-jsq5-col==7)fentodu=fentodu+(tempx-48)*100+(tempx-48)*10+tempx-48;
fentodu=fentodu*1852*0.0001;
col=jsq4-jsq5-3;
}
}
float sudu=fentodu*0.01;
for(int col=0;col<8;col++)TrackB5=0;
dtostrf(sudu,1,2,TrackB5);
jianyan = String(GPRMC);
jianyan += GPRMC;
utc8r=jianyan.toInt();
jianyan = String(GPRMC);
jianyan += GPRMC;
utc8y=jianyan.toInt();
jianyan = String(GPRMC);
jianyan += GPRMC;
utc8n=jianyan.toInt();
if(rijinwei){
if(utc8y==2 && utc8r==28){
if(utc8n % 400 == 0 || utc8n % 100 != 0 && utc8n % 4 == 0)utc8r=29;
else {
utc8r=1;
yuejinwei=1;
}
}else{
for(int col=0;col<4;col++){
if(xiaoyue==utc8y)xiaoyueok=1;
}
if(xiaoyueok && utc8r==30){
utc8r=1;
yuejinwei=1;
}else if(!xiaoyueok && utc8r==31){
utc8r=1;
yuejinwei=1;
}else{
utc8r++;
}
}
}
if(yuejinwei && utc8y==12){
utc8y=1;
nianjinwei=1;
}else if(yuejinwei){
utc8y++;
}
if(nianjinwei)utc8n++;
}

void Linename()
{
    for(int col=0;col<12;col++)tempx=0;
if(EEPROMvalue<10){
tempx=48;
tempx=48;
tempx=EEPROMvalue+48;
}else if(EEPROMvalue<100){
tempx=48;
Linenumber=EEPROMvalue*0.1;
tempx=Linenumber+48;
   Linenumber=EEPROMvalue%10;
    tempx=Linenumber+48;
}else{
    Linenumber=EEPROMvalue*0.01;
tempx=Linenumber+48;
Linenumber=EEPROMvalue*0.1;
    Linenumber=Linenumber%10;
tempx=Linenumber+48;
   Linenumber=EEPROMvalue%10;
    tempx=Linenumber+48;
}
memcpy(TrackAL,tempx,3);
}

void Trackname()
{

   EEPROMvalue= EEPROM.read(6);
   if(EEPROMvalue <250){
   gpxjiluguijishu=EEPROMvalue;
   EEPROMvalue= EEPROM.read(5);
   gpxjiluguijishu=EEPROMvalue*250+gpxjiluguijishu;
   }else{
   gpxjiluguijishu=0;
   EEPROM.write(6,gpxjiluguijishu);
   EEPROMvalue= EEPROM.read(5);
   if(EEPROMvalue<240){
   EEPROMvalue++;
   EEPROM.write(5,EEPROMvalue);
   gpxjiluguijishu=EEPROMvalue*250;
   }else{
   EEPROM.write(5,0);
   gpxjiluguijishu=0;
   }
   }
for(int col=0;col<12;col++)tempx=0;
if(gpxjiluguijishu>9999)sprintf(tempx, "%d", gpxjiluguijishu);
else if(gpxjiluguijishu>999){
tempx=48;
sprintf(tempx+1, "%d", gpxjiluguijishu);
}else if(gpxjiluguijishu>99){
tempx=48;
tempx=48;
sprintf(tempx+2, "%d", gpxjiluguijishu);
}else if(gpxjiluguijishu>9){
tempx=48;
tempx=48;
tempx=48;
sprintf(tempx+3, "%d", gpxjiluguijishu);
}else{
tempx=48;
tempx=48;
tempx=48;
tempx=48;
sprintf(tempx+4, "%d", gpxjiluguijishu);
}
memcpy(TrackAN,tempx,5);
}



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

hi55234 发表于 2014-10-19 00:09:01

本帖最后由 hi55234 于 2014-11-5 23:27 编辑

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







#include <MemoryFree.h>

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


#include <SoftwareSerial.h>
SoftwareSerial gps(8, 9);
char tempx;
char GPRMC;
char GPGGA;
int gpschangertest;
boolean gpschanger;
int weiduA;
unsigned long weiduB,weiduC;
int jingduA;
unsigned long jingduB,jingduC;


boolean GPGGAget=0;
boolean GPRMCget=0;
unsigned long gpstimes;
boolean konghangpanduan;
boolean gpsshuchuqiehuanB=0;
int jsq1=0;
int jsq2=0;
int jsq3=0;
int jsq4=0;
int jsq5=0;
int jsq6=0;
int jsq7=0;
int GPGGAlong=0;
int GPRMClong=0;
boolean jiaoyanjieguoA,jiaoyanjieguoC;
float sudu;

String jianyan="";
int yihuoyunsuan;



boolean dingweiok=0;

/*---------------------GPS end---------------------------------*/
int gpsshuchuqiehuanA;



#include<EEPROM.h>
int EEPROMvalue;


#include <SD.h>


const int chipSelect = 10;


boolean gpxstart;
boolean gpxmiddleA;
boolean gpxmiddleB=1;
boolean gpxendA;
boolean gpxendB;



int gpxjilujiangeA;
int gpxjilujiangeB=256;



int gpxjiludianshu;
int gpxjiluguijishu;




char TrackAL="000";


char TrackB0="-0000.0";

char TrackB1="00.0000000";
char TrackB2="000.0000000";

char TrackB4="2000-00-00T00:00:00";

char TrackB5="0000.00";
char TrackB6="000.00";


boolean weiduxuweitiao=0;
boolean jingduxuweitiao=0;
int weiduzhanwei,jingduzhanwei;


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

int xiaoyue={4,6,9,11};

boolean rijinwei,yuejinwei,nianjinwei,xiaoyueok;

unsigned long fentodu;
int Linenumber;
int Tracknumber;


void setup() {

pinMode(14,INPUT);

lcd.begin(16, 2);


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


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



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

Linename();



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



EEPROMvalue= EEPROM.read(3);
gpxjiludianshu=EEPROMvalue*25;
   
EEPROMvalue++;
EEPROM.write(3, EEPROMvalue);




pinMode(10, OUTPUT);


if (!SD.begin(chipSelect)) {
lcd.print("SD Card failed! ");
    return;
}
}


void loop() {


ruanchuankou();

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

gpsdechuli();



if(!gpsshuchuqiehuanB){
Serial.println(GPGGA);
Serial.println(GPRMC);
Serial.print(freeMemory());
Serial.println("---------------------");
}

if(jiaoyanjieguoA)jiexiGPGGA();

if(jiaoyanjieguoC){
jiexiGPRMC();

if(dingweiok && gpschanger) {
gpschanger=0;


if(gpxjilujiangeB>gpxjilujiangeA){
gpxjilujiangeB=0;
gpxjiludianshu++;


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


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



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


sdcaozuo();


}else {

EEPROM.write(3, EEPROMvalue);
}


}


sdcaozuo();
}


}

}


/*
G:A B F:xxx SD:G
0123456789012345
G:V _ F:xxx SD:E
*/



shanshuo=!shanshuo;

lcd.setCursor(0, 0);

if(shanshuo)lcd.print("G:");
else lcd.print(" :");

if(dingweiok)lcd.print("A");
else lcd.print("V");

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

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

lcd.setCursor(0, 1);
if(dingweiok){
lcd.print(TrackB0);
lcd.print("M ");
lcd.print(TrackB5);
lcd.print("km/h   ");
}else{
lcd.print(TrackB0);
lcd.print(" M *.* km/h   ");

}




gpsshuchuqiehuanA =digitalRead(14);
if (gpsshuchuqiehuanA==HIGH){
gpsshuchuqiehuanB=!gpsshuchuqiehuanB;
EEPROM.write(0,gpsshuchuqiehuanB);
}






for(int col=0;col<80;col++)GPRMC=0;
for(int col=0;col<80;col++)GPGGA=0;
for(int col=0;col<12;col++)tempx=0;
jsq1=0;
GPGGAget=0;
GPRMCget=0;
}

}



void ruanchuankou()
{


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


if(GPRMCget){
GPRMC=gps.read();
if(gpsshuchuqiehuanB)Serial.print(GPRMC);
if(GPRMC=='*'){
GPRMClong=jsq1;
GPRMCget=0;
jsq1=0;
}else if(jsq1<79)jsq1++;



}else if(GPGGAget){

GPGGA=gps.read();
if(gpsshuchuqiehuanB)Serial.print(GPGGA);
if(GPGGA=='*'){
GPGGAlong=jsq1;
GPGGAget=0;
jsq1=0;
}else if(jsq1<79)jsq1++;



}else{
tempx=gps.read();
if(gpsshuchuqiehuanB)Serial.print(tempx);
if(jsq1<6)jsq1++;

}



if(jsq1==6){


if(tempx=='M' && tempx=='C'){

GPRMCget=1;
GPGGAget=0;
for(int col=0;col<6;col++)GPRMC=tempx;
for(int col=0;col<6;col++)tempx=0;

}else if(tempx=='G' && tempx=='A'){

GPGGAget=1;
GPRMCget=0;
for(int col=0;col<6;col++)GPGGA=tempx;
for(int col=0;col<6;col++)tempx=0;

}else{

for(int col=0;col<5;col++)tempx=tempx;
jsq1=5;
}

}


}



}


void gpsdechuli()
{

for(int col=1;col<GPRMClong-3;col++){
if(col==1)yihuoyunsuan=GPRMC;
else yihuoyunsuan=yihuoyunsuan ^ GPRMC;
}

if(yihuoyunsuan==0){
jianyan="00";
}else if(yihuoyunsuan>15){
jianyan = String(yihuoyunsuan,HEX);
}else{
jianyan = "0";
jianyan += String(yihuoyunsuan,HEX);
}
jianyan.toUpperCase();
if(jianyan==GPRMC && jianyan==GPRMC ){
jiaoyanjieguoC=1;
}else{
jiaoyanjieguoC=0;
}

jianyan="";




for(int col=1;col<GPGGAlong-3;col++){
if(col==1)yihuoyunsuan=GPGGA;
else yihuoyunsuan=yihuoyunsuan ^ GPGGA;
}

if(yihuoyunsuan==0){
jianyan="00";
}else if(yihuoyunsuan>15){
jianyan = String(yihuoyunsuan,HEX);
}else{
jianyan = "0";
jianyan += String(yihuoyunsuan,HEX);
}
jianyan.toUpperCase();
if(jianyan==GPGGA && jianyan==GPGGA ){
jiaoyanjieguoA=1;
}else{
jiaoyanjieguoA=0;
}


jianyan="";


}


void jiexiGPGGA()
{

   jsq2=0;
   jsq3=0;
   jsq4=0;
   jsq5=0;


    for(int col=1;col<GPGGAlong-3;col++){
   if(GPGGA==',')jsq2++;
   if(jsq2==10){
   jsq3=col;
   col=GPGGAlong-3;
   }
   

   if(jsq2<9)jsq4=col;

   if(jsq2<7)jsq5=col;
   
   }
   

   if(GPGGA==49)dingweiok=1;
   else dingweiok=0;
   

for(int col=0;col<8;col++)TrackB0=0;
memcpy(TrackB0,GPGGA+jsq4+2, jsq3-jsq4-2);

}


void jiexiGPRMC()
{

   jsq2=0;
   jsq3=0;
   jsq4=0;
   jsq5=0;
   jsq6=0;
   jsq7=0;
   
    for(int col=1;col<GPRMClong-3;col++){
   if(GPRMC==',')jsq2++;
   if(jsq2==9){
   jsq3=col;
   col=GPRMClong-3;
   }
   
   if(jsq2<8)jsq4=col;
   if(jsq2<6)jsq5=col;
   if(jsq2<4)jsq6=col;
   if(jsq2<2)jsq7=col;
   }


if(GPRMC=='A')chinatime();


if(dingweiok){

jingweiduchuli();
hangxiangyusudu();

}else {
weiduA=0;
weiduB=0;
weiduC=0;
jingduA=0;
jingduB=0;
jingduC=0;
}


}


void chinatime()
{


jianyan = String(GPRMC);
jianyan += GPRMC;
utc8s=jianyan.toInt()+8;


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

jianyan = String(GPRMC);
jianyan += GPRMC;
utc8f=jianyan.toInt();



jianyan = String(GPRMC);
jianyan += GPRMC;
utc8m=jianyan.toInt();







jianyan = String(GPRMC);
jianyan += GPRMC;
utc8r=jianyan.toInt();




jianyan = String(GPRMC);
jianyan += GPRMC;
utc8y=jianyan.toInt();



jianyan = String(GPRMC);
jianyan += GPRMC;
utc8n=jianyan.toInt();





if(rijinwei){

if(utc8y==2 && utc8r==28){
if(utc8n % 400 == 0 || utc8n % 100 != 0 && utc8n % 4 == 0)utc8r=29;
else {
utc8r=1;
yuejinwei=1;
}
}else{

for(int col=0;col<4;col++){
if(xiaoyue==utc8y)xiaoyueok=1;
}
if(xiaoyueok && utc8r==30){
utc8r=1;
yuejinwei=1;
}else if(!xiaoyueok && utc8r==31){
utc8r=1;
yuejinwei=1;
}else{
utc8r++;
}
}
}
if(yuejinwei && utc8y==12){
utc8y=1;
nianjinwei=1;
}else if(yuejinwei){
utc8y++;
}
if(nianjinwei)utc8n++;



for(int col=0;col<12;col++)tempx=0;
if(utc8n>9){
sprintf(tempx, "%d", utc8n);
memcpy(TrackB4+2,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8n+48;

}

for(int col=0;col<12;col++)tempx=0;
if(utc8y>9){
sprintf(tempx, "%d", utc8y);
memcpy(TrackB4+5,tempx, 2);
} else{
TrackB4=48;
   TrackB4=utc8y+48;

}
   for(int col=0;col<12;col++)tempx=0;
if(utc8r>9){
sprintf(tempx, "%d", utc8r);
memcpy(TrackB4+8,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8r+48;

}

    for(int col=0;col<12;col++)tempx=0;
if(utc8s>9){
sprintf(tempx, "%d", utc8s);
memcpy(TrackB4+11,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8s+48;

}
    for(int col=0;col<12;col++)tempx=0;
if(utc8f>9){
sprintf(tempx, "%d", utc8f);
memcpy(TrackB4+14,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8f+48;
}

    for(int col=0;col<12;col++)tempx=0;
if(utc8m>9){
sprintf(tempx, "%d", utc8m);
memcpy(TrackB4+17,tempx, 2);
}else{
TrackB4=48;
TrackB4=utc8m+48;
}


}


void jingweiduchuli()
{


for(int col=0;col<12;col++)tempx=0;
memcpy(tempx,GPRMC+jsq7+4, 2);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(weiduA!=gpschangertest){
weiduA=gpschangertest;
gpschanger=1;
}



if(GPRMC==83)weiduxuweitiao=1;
if(GPRMC==87)jingduxuweitiao=1;


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

if(gpschangertest<10) {
TrackB1=32;
weiduzhanwei=1;
}else weiduzhanwei=2;


for(int col=0;col<12;col++)tempx=0;

memcpy(tempx,GPRMC+jsq7+6, 2);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(weiduB!=gpschangertest){
weiduB=gpschangertest;
gpschanger=1;
}



for(int col=0;col<12;col++)tempx=0;

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


jianyan =tempx;
gpschangertest=jianyan.toInt();
if(weiduC!=gpschangertest){
weiduC=gpschangertest;
gpschanger=1;
}


fentodu=weiduB*100000+weiduC*10;
fentodu=fentodu/6;

for(int col=0;col<12;col++)tempx=0;
dtostrf(fentodu,6,0,tempx);





if(fentodu>99999){
memcpy(TrackB1+3,tempx, 6);
}else if(fentodu>9999){
TrackB1=48;
memcpy(TrackB1+4,tempx, 5);
}else if(fentodu>999){
TrackB1=48;
TrackB1=48;
memcpy(TrackB1+5,tempx, 4);

}else if(fentodu>99){
TrackB1=48;
TrackB1=48;
TrackB1=48;
memcpy(TrackB1+6,tempx, 3);

}else if(fentodu>9){
TrackB1=48;
TrackB1=48;
TrackB1=48;
TrackB1=48;
memcpy(TrackB1+7,tempx, 2);
}else{
TrackB1=48;
TrackB1=48;
TrackB1=48;
TrackB1=48;
TrackB1=48;
memcpy(TrackB1+8,tempx, 1);

}





if(weiduxuweitiao){
weiduxuweitiao=0;

if(weiduzhanwei==2){


   for(int col=0;col<12;col++)tempx=0;
tempx=45;
memcpy(tempx+1,TrackB1, 9);
memcpy(TrackB1,tempx, 10);

}else{

TrackB1=45;

}

}





for(int col=0;col<12;col++)tempx=0;

   memcpy(tempx,GPRMC+jsq6+4, 3);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(jingduA!=gpschangertest){
jingduA=gpschangertest;
gpschanger=1;
}





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

if(gpschangertest<100) {
TrackB2=32;
jingduzhanwei=2;
}

if(gpschangertest<10) {
TrackB2=32;
jingduzhanwei=1;
}

for(int col=0;col<12;col++)tempx=0;

memcpy(tempx,GPRMC+jsq6+7, 3);
jianyan =tempx;
gpschangertest=jianyan.toInt();
if(jingduB!=gpschangertest){
jingduB=gpschangertest;
gpschanger=1;
}

for(int col=0;col<12;col++)tempx=0;

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

jianyan =tempx;
gpschangertest=jianyan.toInt();
if(jingduC!=gpschangertest){
jingduC=gpschangertest;
gpschanger=1;
}

jianyan="";


fentodu=jingduB*100000+jingduC*10;
fentodu=fentodu/6;

for(int col=0;col<12;col++)tempx=0;
dtostrf(fentodu,6,0,tempx);





if(fentodu>99999){
memcpy(TrackB2+4,tempx, 6);
}else if(fentodu>9999){
TrackB2=48;
memcpy(TrackB2+5,tempx, 5);
}else if(fentodu>999){
TrackB2=48;
TrackB2=48;
memcpy(TrackB2+6,tempx, 4);

}else if(fentodu>99){
TrackB2=48;
TrackB2=48;
TrackB2=48;
memcpy(TrackB2+7,tempx, 3);

}else if(fentodu>9){
TrackB2=48;
TrackB2=48;
TrackB2=48;
TrackB2=48;
memcpy(TrackB2+8,tempx, 2);
}else{
TrackB2=48;
TrackB2=48;
TrackB2=48;
TrackB2=48;
TrackB2=48;
memcpy(TrackB2+9,tempx, 1);

}





if(jingduxuweitiao){
jingduxuweitiao=0;

if(jingduzhanwei==3){


   for(int col=0;col<12;col++)tempx=0;
tempx=45;
memcpy(tempx+1,TrackB2, 10);
memcpy(TrackB2,tempx, 11);

}else if(jingduzhanwei==2){

TrackB2=45;

}else{

TrackB2=45;
}

}


}


void hangxiangyusudu()
{

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


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

if(tempx==46){




if(col==1)fentodu=(tempx-48)*1000;
else if(col==2)fentodu=(tempx-48)*10000+(tempx-48)*1000;
else if(col==3)fentodu=(tempx-48)*100000+(tempx-48)*10000+(tempx-48)*1000;





if(jsq4-jsq5-col==5)fentodu=fentodu+(tempx-48)*100;
else if(jsq4-jsq5-col==6)fentodu=fentodu+(tempx-48)*100+(tempx-48)*10;
else if(jsq4-jsq5-col==7)fentodu=fentodu+(tempx-48)*100+(tempx-48)*10+tempx-48;





fentodu=fentodu*1852*0.0001;
col=jsq4-jsq5-3;

}

}


sudu=fentodu*0.01;
for(int col=0;col<8;col++)TrackB5=0;
dtostrf(sudu,1,2,TrackB5);


for(int col=0;col<7;col++)TrackB6=0;
memcpy(TrackB6,GPRMC+jsq4+2, jsq3-jsq4-2);


}


void sdcaozuo()
{




for(int col=0;col<12;col++)tempx=0;

tempx='L';
tempx='i';
tempx='n';
tempx='e';
memcpy(tempx+4,TrackAL,3);
tempx='.';
tempx='g';
tempx='p';
tempx='x';


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



if (dataFile) {

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



      EEPROMvalue= EEPROM.read(4);
      if(EEPROMvalue==0) gpxstart=1;
      else gpxstart=0;
   
   
   
    EEPROMvalue= EEPROM.read(7);
    if(EEPROMvalue==0){
    gpxmiddleA=1;
   
   
    }else gpxmiddleA=0;
   
      EEPROMvalue= EEPROM.read(8);
      if(EEPROMvalue==0) gpxendA=1;
      else gpxendA=0;

      EEPROMvalue= EEPROM.read(9);
      if(EEPROMvalue==0) gpxendB=1;
      else gpxendB=0;
   

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


for(int col=0;col<80;col++)GPRMC=0;
for(int i=50;i<77;i++)GPRMC = EEPROM.read(i);

dataFile.print(GPRMC);



}



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



for(int col=0;col<80;col++)GPRMC=0;
for(int i=77;i<89;i++)GPRMC = EEPROM.read(i);

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






for(int col=0;col<80;col++)GPRMC=0;
for(int i=89;i<110;i++)GPRMC = EEPROM.read(i);

dataFile.println(GPRMC);



}


if(gpxmiddleB){



   for(int col=0;col<80;col++)GPRMC=0;
   for(int i=110;i<123;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);
   dataFile.print(TrackB1);
   



   for(int col=0;col<80;col++)GPRMC=0;
   for(int i=123;i<131;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);

   dataFile.print(TrackB2);
   




for(int col=0;col<80;col++)GPRMC=0;
for(int i=131;i<140;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);

   dataFile.print(TrackB4);
   



   for(int col=0;col<80;col++)GPRMC=0;
   for(int i=140;i<158;i++)GPRMC = EEPROM.read(i);
   dataFile.println(GPRMC);


}


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

EEPROM.write(7,0);

for(int col=0;col<80;col++)GPRMC=0;
for(int i=158;i<174;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);


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

}


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

EEPROM.write(4,0);


for(int col=0;col<80;col++)GPRMC=0;
for(int i=174;i<181;i++)GPRMC = EEPROM.read(i);
   dataFile.print(GPRMC);
   




EEPROMvalue= EEPROM.read(1);
EEPROMvalue++;
if(EEPROMvalue==255) EEPROMvalue=0;
EEPROM.write(1, EEPROMvalue);
Linename();


}


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

}



dataFile.close();



}


void Linename()
{

   for(int col=0;col<12;col++)tempx=0;

if(EEPROMvalue<10){
tempx=48;
tempx=48;
tempx=EEPROMvalue+48;

}else if(EEPROMvalue<100){
tempx=48;
Linenumber=EEPROMvalue*0.1;
tempx=Linenumber+48;
   Linenumber=EEPROMvalue%10;
    tempx=Linenumber+48;

}else{

   Linenumber=EEPROMvalue*0.01;
tempx=Linenumber+48;
Linenumber=EEPROMvalue*0.1;
    Linenumber=Linenumber%10;
tempx=Linenumber+48;
   Linenumber=EEPROMvalue%10;
    tempx=Linenumber+48;

}


for(int col=0;col<4;col++)TrackAL=0;
memcpy(TrackAL,tempx,3);

}


hi55234 发表于 2014-10-20 10:26:02

本帖最后由 hi55234 于 2014-10-30 22:05 编辑

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

hi55234 发表于 2014-10-20 21:38:00

一段测试程序,关于int 转 字符串
char tempx;
unsigned long fentodu;//分到度的转换
unsigned longweiduB=1;
unsigned long weiduC=1;
void setup() {

Serial.begin(9600);
}


void loop() {

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

fentodu=fentodu+weiduC;

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

fentodu=fentodu/6;

    Serial.print("fentoduC=");
   Serial.println(fentodu);
   
for(int col=0;col<7;col++)tempx=0;
sprintf(tempx, "%d", fentodu);   
Serial.print("tempx=");
Serial.println(tempx);
   Serial.print("fentodu=");
   Serial.println(fentodu);
   
   for(int col=0;col<7;col++)tempx=0;
dtostrf(fentodu,6,0,tempx);
Serial.print("tempx=");
Serial.println(tempx);
   Serial.print("fentodu=");
   Serial.println(fentodu);
Serial.println("---------------------------------");
delay(500);
   weiduB++;
    weiduC++;
}

hi55234 发表于 2014-10-20 23:02:52

本帖最后由 hi55234 于 2014-10-30 22:56 编辑

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


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

hi55234 发表于 2014-10-21 00:17:42

本帖最后由 hi55234 于 2014-10-30 22:04 编辑


简易的超声波,毫米单位


const int TrigPin = 2;
const int EchoPin = 3;
unsigned long mm;
void setup()
{
Serial.begin(9600);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
}
void loop()
{
digitalWrite(TrigPin, LOW); //低高低电平发一个短时间脉冲去TrigPin
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);

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

Serial.print(mm);
Serial.print("mm");
Serial.println();
delay(1000);
}

hi55234 发表于 2014-10-23 09:10:12

本帖最后由 hi55234 于 2014-10-30 22:04 编辑

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

太长不看······

hi55234 发表于 2014-10-23 12:26:58

本帖最后由 hi55234 于 2014-10-30 22:03 编辑

楼太长,没法看

yuqingshan 发表于 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才是正常时钟的运行的,研究一段时间,不得其法,能指导一下该部分的代码如何写吗?谢谢。

附代码:

hi55234 发表于 2014-10-23 14:21:39

yuqingshan 发表于 2014-10-23 13:28 static/image/common/back.gif
楼主您好,一口气看完您的贴自,还真的不容易,值得收藏研究的好帖子。

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

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

如果要做到和gps无关性,你改一下代码就可以了

yuqingshan 发表于 2014-10-23 16:15:34

哦,楼主您好,按原理应该可行,不过一时还没有试过您的代码,本人E文太烂,很长时间才读懂,需慢慢研究,如果现成代码是想偷懒,谢谢楼主。

hi55234 发表于 2014-10-24 09:31:07

本帖最后由 hi55234 于 2014-10-30 22:07 编辑

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

hi55234 发表于 2014-10-24 12:15:53

本帖最后由 hi55234 于 2014-10-30 22:09 编辑

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

尼玛,霸王硬上弓,依旧不成功

yuqingshan 发表于 2014-10-24 13:45:48

LZ,您的代码看到有点懵,下面2点我的理解不知对否?
1)GPS电子钟,应去了BMP180(气压传感器)吧。
2)海平面气压(sea level pressure)换算成高程,可像没有这样必要,因为GPS数据流本身有高程数据的($GPGGA中 <9>,天线离海平面的高度,应该是吧)。
谢谢。

hi55234 发表于 2014-10-25 10:49:53

yuqingshan 发表于 2014-10-24 13:45 static/image/common/back.gif
LZ,您的代码看到有点懵,下面2点我的理解不知对否?
1)GPS电子钟,应去了BMP180(气压传感器)吧。
2)海 ...

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

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

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

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

PS:这个程序和以前程序在读取思路上不一样,以前是全部读取之后再慢慢分析,这个是要分析什么就读取什么,内存使用相对较少
页: [1] 2
查看完整版本: GPS码表 & 轨迹记录仪 &蓝牙gps,谷歌地球查看,山寨Pro min搭建 【1楼完结】