基于C3-370C的GPS定位及轨迹记录仪!
在51hei买了C3-370C的GPS,准备做GPS轨迹记录,因为我一直想在旅游的照片上加上坐标信息……
开始用M48作控制MCU,结果写着写着,发现Flash空间不足,想换个M8或M88的,在常州还不好买,手上正好还有两块STC90C52,8K的,于是就换上C52了。
C52不带AD,那电池检测又成问题,于是从坏的万用表上拆下一个2904运放,做了个简单的电池电压检测。
现在整个设备的供电都由锂电池直接提供,配一块880mah的手机电池,可以用6小时左右;
我用24C64记录轨迹信息,包括日期时间、经纬度在内的一组信息,可存储512条,按1min/条,可存8小时。
数据通过串口传给上位机,上位机软件转换数据,也可直接输出KML文件,在Goole earth中打开。
按键0: 短按(可见卫星信息|坐标数据); 长按(运行|暂停);
按键1: 短按(记录当前坐标数据); 长按(暂停时长按删除所有数据);
按键2: 短按(背光灯); 长按(记录模式切换H/A90s/A60s/A30s/A10s);
视图1
背光灯开启
界面说明
液晶背后的主控板
30S自动记录模式
可见卫星信息
连接电脑上传数据
PC端接收数据
删除数据
背面
左侧
右侧
在GooleEarth打开
运放低电压指示电路
最近想着给它加个壳,费了一些时间,找到了一个东东,感觉做外壳不错,就是ADSL的分频器,不过体积小了不少, 尺寸只有60X44X21!
于是想做就做吧,为了减小体积,能用贴片的元件都换成贴片的,幸好最近出了Atmega8a这个价格还算合理的AVR片子, 上位机软件也做了调整,将照片匹配软件与上位机软件合成。 主程序文件:
#include "_STC90.h"
#include "_GPS.h"
sbit C_LED = P0^4; //数据通讯指示
sbit Key0 = P3^3;
sbit Key1 = P1^2;
sbit Key2 = P1^0;
bit flg_gsv=0;
bit flg_mode=0;
bit flg_upload=0;
bit flg_rx=0;
bit flg_rxf=0;
uchar flg_rmcgga=0; //1rmc 2gga
void get_gpsmode(void)
{
if(!flg_mode){
if(buf_gps[3]=='M' && buf_gps[4]=='C') flg_rmcgga = 1; //RMC
else{
if(buf_gps[3]=='G' && buf_gps[4]=='A') flg_rmcgga = 2; //GGA
else flg_rx = 0;
}
}
else{
if(buf_gps[3]=='S' && buf_gps[4]=='V') flg_rmcgga = 3; //GGA
else flg_rx = 0;
}
}
void UART_RX(void) interrupt 4
{
uchar tp_rx;
while(!RI);
tp_rx = SBUF;
if(!flg_rxf){
if(flg_rx){
buf_gps[count_gps] = tp_rx;
if(count_gps==4) get_gpsmode();
if(tp_rx=='*'){ flg_rx = 0; flg_rxf = 1;}
else count_gps++;
}
else{
if(tp_rx=='$'){ flg_rx = 1; count_gps = 0; flg_rmcgga = 0;}
}
}
if(tp_rx=='#') flg_upload = 1;
RI = 0;
}
void UART_TX(uchar tp_tx)
{
SBUF = tp_tx;
while(!TI);
TI = 0; _nus(100);
}
uchar var_js7=36;
uchar var_js5=0;
uchar var_js4=0;
uint var_jsrec=0;
//60ms
void TIMER2_SEV(void) interrupt 5
{
TF2 = 0;
if(var_js7>0) var_js7--;
if(var_js5>0) var_js5--;
if(var_js4>0) var_js4--;
if(var_jsrec>0) var_jsrec--;
}
void initial(void)
{
C_LED = 0;
GPS_EN = 0;
EA = 0;
AUXR = 0x01;
IPH = 0x0c; IP = 0x14;
SCON = 0x50;
PCON = 0x00;
RI = 0; TI = 0; ES = 1;
TCON = 0x00;
TMOD = 0x21;
TH1 = 256-6; TL1 = 256-6; ET1 = 0; TR1 = 1;
T2CON = 0x00; T2MOD = 0x00;
RCAP2H = (65536-55296)/256; RCAP2L = (65536-55296)%256;
ET2 = 1; TR2 = 1;
I2C_Init();
L5_init();
L5_wrstr_cn(24,2,0,4,4); //卫星定位
L5_wrstr_cn(24,4,4,4,4); //轨迹记录
EA = 1;
while(var_js7>0);
Lgps_disp_init();
C_LED = 1;
}
void Key_deal(void)
{
uchar jk=255;
C_LED = 0; EA = 0; flg_rx = 0; flg_rxf = 0;
if(!Key0){
do{ _nms(8); jk--;}while(!Key0 && jk>0);
if(jk>0){
flg_mode = !flg_mode;
L5_setxy(0,1); ofs = 0; line = 0x00; Lwr_icob(336);
if(!flg_mode) Lgps_disp_dt();
}
else{
flg_sata = !flg_sata; L5_SATA();
GPS_EN = flg_sata;
}
do{ while(!Key0); _nms(5);}while(!Key0);
}
if(!Key1){
do{ _nms(20); jk--;}while(!Key1 && jk>0);
if(jk>0){ at_onewr('H'); var_js4 = 10;}
else at_format();
do{ while(!Key1); _nms(5);}while(!Key1);
}
if(!Key2){
do{ _nms(8); jk--;}while(!Key2 && jk>0);
if(jk>0) L5_LED = !L5_LED;
else{
while(!Key2){
rec_add();
_nms(255); _nms(255); _nms(255); _nms(255);
}
var_jsrec = var_rec*50; var_jsrec/=3;
}
}
C_LED = 1; EA = 1;
}
void main(void)
{
initial();
while(1){
if(flg_rxf){
if(flg_sign) C_LED = 0;
L5_ComData(1); var_js5 = 6;
get_cama();
if(!flg_mode){
if(flg_rmcgga==1) L5_RMC();
else if(flg_rmcgga==2) L5_GGA();
}
else{
if(flg_rmcgga==3){
if(!flg_gsv){
L5_GSV();
if(buf_gps[8]=='3') flg_gsv = 1;
}
else{
if(buf_gps[8]=='2'){ L5_GSV(); flg_gsv = 0;}
}
}
}
for(count_gps=0;count_gps<96;count_gps++)
buf_gps[count_gps]=0;
C_LED = 1; flg_rxf = 0;
}
if(var_js5==1){ L5_ComData(0); var_js5 = 0;}
if(var_js7==0){ L5_BAT(); var_js7 = 16;}
if(!(Key0&Key1&Key2)){ _nms(5); Key_deal();}
if(var_js4==1){ L5_AtWr(0); var_js4 = 0;}
if(!flg_sata){
if(var_rec>0){
if(var_jsrec==0){
at_onewr('A'); var_js4 = 10;
var_jsrec = var_rec*50; var_jsrec/=3;
}
}
}
if(flg_upload){
if(flg_sata){
uint k; uchar r;
C_LED = 0; EA = 0; flg_rx = 0; flg_rxf = 0;
for(k=0;k UART_TX(k/256); UART_TX(k%256); for(r=0;r<16;r++) UART_TX(C64_buf[r]); L5_sch(1,1,k,at_id); } EA = 1; L5_sch(0,0,0,0); C_LED = 1; } flg_upload = 0; } } } _gps.h 文件: #include "_STC90.h" #include "_LCD5110.h" #include "_AT24C64.h" #define Bat_full 10 //电量满 #define Bat_empt 11 //电量空 #define Signal 12 //信号 #define NoSignal 13 //信号 #define file 14 //文件 #define Sata_run 15 //状态运行 #define Sata_pause 16 //状态暂停 #define Ico_gps 17 //GPS #define Ico_com 18 //数据通讯 #define Ico_del 19 //删除 #define Ico_upload 20 //上传 #define Ico_wait 21 //等待 #define chr_point 22 //大'.' #define chr_degree 23 //度 #define chr_min 24 //分 #define Ico_point 25 //小度 #define Ico_degree 26 //小度 sbit Bat_Low = P1^4; //电池0低 sbit GPS_EN = P3^5; //GPS使能 uchar buf_gps[96]={0}; uchar count_gps=0; bit flg_sign=0; uchar var_seg[20]={0}; uchar ofs=0; uchar line=0x00; void get_cama(void) { uchar tp_c=0,cj; for(cj=0;cj<20;cj++) var_seg[cj] = 0; for(cj=0;cj } void Lwr_icob(uint nb){ for(;nb>0;nb--) L5_wrbyte(1,line);} void Lwr_ico(uchar ic) { uchar i0,i1; switch(ic){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': i0 = (ic-48)*4; i1 = i0+4; break; case 10: i0 = 65; i1 = 75; break; //电量满 case 11: i0 = 75; i1 = 85; break; //电量空 case 12: i0 = 40; i1 = 50; break; //信号有 case 13: i0 = 50; i1 = 60; break; //信号无 case 14: i0 = 60; i1 = 65; break; //文件 case 15: i0 = 137; i1 = 143; break; //运行图标 case 16: i0 = 143; i1 = 149; break; //暂停图标 case 17: i0 = 85; i1 = 105; break; //GPS case 18: i0 = 164; i1 = 173; break; //数据传输 case 19: i0 = 173; i1 = 180; break; //删除× case 20: i0 = 180; i1 = 187; break; //上传 case 21: i0 = 187; i1 = 194; break; //等待 case 'D': i0 = 131; i1 = 137; break; //'D' case ':': i0 = 115; i1 = 117; break; //':' case '/': i0 = 105; i1 = 109; break; //'/' case '.': i0 = 109; i1 = 111; break; //'.' case '-': i0 = 111; i1 = 115; break; //'-' case '%': i0 = 194; i1 = 202; break; //'%' case 'k': i0 = 117; i1 = 131; break; //'kmh' case 'm': i0 = 121; i1 = 127; break; //'m' case 's': i0 = 159; i1 = 164; break; //'s' case 'A': i0 = 202; i1 = 207; break; //'A' case 'H': i0 = 207; i1 = 212; break; //'H' case 'N': i0 = 212; i1 = 217; break; //'N' case 'S': i0 = 217; i1 = 222; break; //'S' case 'E': i0 = 222; i1 = 227; break; //'E' case 'W': i0 = 227; i1 = 232; break; //'N' case 22: i0 = 149; i1 = 152; break; //大'.' case 23: i0 = 152; i1 = 156; break; // ° case 24: i0 = 156; i1 = 159; break; //' case 25: i0 = 232; i1 = 235; break; //中点 case 26: i0 = 235; i1 = 238; break; //小度 default: i0 = ic*4; i1 = i0+4; break; //数字 } for(;i0 void Lwr_icos(uchar cs,uchar cl) { uchar k; for(k=0;k void Lwr_icoh(uchar *hs){ while(*hs){ Lwr_ico(*hs); hs++;}} void L5_wr_chr(uchar nc) { uchar l,n; switch(nc){ case 'N': n = 19; break; case 'S': n = 22; break; case 'E': n = 16; break; case 'W': n = 24; break; case 'H': n = 18; break; case 'A': n = 14; break; case 'G': n = 17; break; case 'P': n = 20; break; case 'R': n = 21; break; case 'M': n = 18; break; case 'C': n = 15; break; case ',': n = 11; break; case '.': n = 13; break; case '-': n = 12; break; case '*': n = 10; break; case 'V': n = 23; break; default: n = nc-48; break; } for(l=0;l<6;l++) L5_wrbyte(1,ASCII326[n][l]); } void L5_wr_chrs(uchar ch,uchar lc) { uchar k; for(k=0;k void L5_wr_chrh(uchar *hr){ while(*hr){ L5_wr_chr(*hr); hr++;}} uchar chrtodec(uchar cd){return buf_gps[cd]-48;} uchar chr_dec(uchar cf){ return chrtodec(cf)*10+chrtodec(cf+1);} /void Lwr_dec(uchar dec){ Lwr_ico(dec/10); Lwr_ico(dec%10);} void L5_RMC(void) { uchar tp_h,tp_y,tp_m,tp_d; bit flg_d=0; L5_setxy(56,5); ofs = 3; line = 0x02; tp_h = chr_dec(6)+8; if(tp_h>23){ tp_h%=24; flg_d = 1;} Lwr_dec(tp_h); Lwr_ico(':'); Lwr_icos(8,2); Lwr_ico(':'); Lwr_icos(10,2); L5_CE = 1; C64_buf[3] = tp_h; C64_buf[4] = chr_dec(8); C64_buf[5] = chr_dec(10); L5_setxy(32,5); tp_m = chr_dec(var_seg[8]+3); tp_d = chr_dec(var_seg[8]+1); if(flg_d){ switch(tp_m){ case 4: case 6: case 9: case 11:
上一篇:51单片机驱动CT1642数码管显示源程序
下一篇:L298N+AT89C52+BT-04A蓝牙控制遥控小车
推荐阅读最新更新时间:2024-11-13 09:12