|
楼主 |
发表于 2013-4-12 10:56
|
显示全部楼层
奈何兄您好!谢谢您!还有个现象,我把第二行语句String comdata = "";改为String comdata="$GPRMC,091859.800,A,3204.8736,N,11853.4971,E,12.34,14.92,280313,,,A*56";奇怪的刚看上去是显示都正常了,但又发模拟GPS数据的串口输入无效,无论怎么变化串口数据,都显示上面这个字符串的内容里的经纬度和速度数据,就是看上去串口输入的数据不能改变comdata。为了验证这点,我改了程序部分语句,变成:
#include <LiquidCrystal.h>
String comdata1 = "";
String comdata;
String text4;
String text5;
String text6;
int i;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup()
{
lcd.clear();
Serial.begin(9600);
// delay(3000);
// Serial.print ("PMTK251,115200");
// Serial.print ("PMTK300,100,0,0,0,0");
Serial.print ("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29");
lcd.begin(16,2);
lcd.print("GPS DEMO");
delay(3000);
lcd.clear();
}
void loop()
{//y
while (Serial.available() > 0)
{ //y
for (byte i=1;i<=70;i++);
{
comdata1 += char(Serial.read());
delay(2);
}
comdata1.toUpperCase();
comdata1.trim();
comdata = comdata1; //A:
//comdata="$GPRMC,091859.800,A,3204.8736,N,11853.4971,E,12.34,14.92,280313,,,A*56"; //B:
Serial.print(comdata);
text4=(comdata.substring(comdata.indexOf('$')));
//Serial.println(text4);
text5=(text4.substring(text4.indexOf('A')+2));
text6=(text5.substring(0,text5.indexOf(',')));
Serial.print(text6);
lcd.setCursor(0, 0);
lcd.print((text6));
text5=(text4.substring(text4.indexOf('N')+2));
text6=(text5.substring(0,text5.indexOf(',')));
Serial.print(text6);
lcd.setCursor(0, 1);
lcd.print((text6));
text5=(text4.substring(text4.indexOf('E')+2));
text6=(text5.substring(0,text5.indexOf(',')));
Serial.print(text6);
lcd.setCursor(10, 0);
lcd.print((text6));
// lcd.clear();
comdata1 = "";
}//y
}
主要是增加了commdata1这个变量,让前半部分用comdata1变量,后半部分用comdata变量,中间通过
commdata=commdata1给commdata变量数据看看是否接受到串口数据,结果用commdata=commdata1就不正常,用comdata="$GPRMC,091859.800,A,3204.8736,N,11853.4971,E,12.34,14.92,280313,,,A*56";就能屏幕显示(当然这个数是死的),就是说分别屏蔽语句A和语句B结果不一样,您看着是什么原因?
|
|