📄 gps.s
字号:
.module gps.c
.area text(rom, con, rel)
.dbfile E:\item\GPS-1280\gps.c
.dbfunc e find_string _find_string fc
; StrLen -> R12,R13
; i -> R20,R21
; j -> R22,R23
; DataLen -> y+10
; data -> R14,R15
; string -> R10,R11
.even
_find_string::
xcall push_xgsetF0FC
movw R14,R18
movw R10,R16
.dbline -1
.dbline 32
; #include <string.h>
; #include "debug.h"
; #include "define.h"
;
; //GPRMC,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>*hh
; //<1> 当前位置的格林尼治时间,格式为hhmmss
; //<2> 状态, A 为有效位置, V为非有效接收警告,即当前天线视野上方的卫星个数少于3颗
; //<3> 纬度, 格式为ddmm.mmmm
; //<4> 标明南北半球, N 为北半球、S为南半球
; //<5> 径度,格式为dddmm.mmmm
; //<6> 标明东西半球,E为东半球、W为西半球
; //<7> 地面上的速度,范围为0.0到999.9
; //<8> 方位角,范围为000.0到 359.9 度
; //<9> 日期, 格式为ddmmyy
; //<10> 地磁变化,从000.0到 180.0 度
; //<11> 地磁变化方向,为E 或 W
; /*
; $GPRMC,072304.00,A,2231.85460,N,11404.40661,E,0.128,,261008,,,A*7C
; $GPVTG,,T,,M,0.128,N,0.238,K,A*21
; $GPGGA,072304.00,2231.85460,N,11404.40661,E,1,04,10.41,-25.4,M,-2.2,M,,*65
; $GPGSA,A,3,07,20,11,50,,,,,,,,,17.78,10.41,14.42*3C
; $GPGSV,3,1,10,04,30,234,,07,17,180,32,08,40,215,,11,34,038,29*7C
; $GPGSV,3,2,10,20,44,097,51,27,23,193,21,28,63,341,,32,28,070,*78
; $GPGSV,3,3,10,42,51,128,39,50,46,122,45*7C
; $GPGLL,2231.85460,N,11404.40661,E,072304.00,A,A*63
; */
;
; //-------------------------------------------------------------
; //从长度为DataLen数据指针*data中找出字符串*string
; //-------------------------------------------------------------
; unsigned char find_string(unsigned char *string,unsigned char *data,unsigned int DataLen)
; {
.dbline 33
; unsigned int StrLen = strlen(string);
movw R16,R10
xcall _strlen
movw R12,R16
.dbline 37
; unsigned int i;
; unsigned int j;
;
; for(i=0;i<DataLen;i++)
clr R20
clr R21
xjmp L5
L2:
.dbline 38
; {
.dbline 39
; if(string[0]==data[i])
movw R30,R20
add R30,R14
adc R31,R15
ldd R2,z+0
movw R30,R10
ldd R3,z+0
cp R3,R2
brne L6
X0:
.dbline 40
; {
.dbline 41
; for(j=1;j<StrLen;j++)
ldi R22,1
ldi R23,0
xjmp L11
L8:
.dbline 42
; {
.dbline 43
; if(string[j]==data[i+j]){
movw R30,R20
add R30,R22
adc R31,R23
add R30,R14
adc R31,R15
ldd R2,z+0
movw R30,R22
add R30,R10
adc R31,R11
ldd R3,z+0
cp R3,R2
brne L12
X1:
.dbline 43
.dbline 45
;
; }else{
xjmp L13
L12:
.dbline 45
.dbline 46
; return 0;
clr R16
xjmp L1
L13:
.dbline 48
; }
; }
L9:
.dbline 41
subi R22,255 ; offset = 1
sbci R23,255
L11:
.dbline 41
cp R22,R12
cpc R23,R13
brlo L8
X2:
.dbline 49
; if(j==StrLen) return i+1;//就算是在0位置找到的也返回0,处理时减1
cp R22,R12
cpc R23,R13
brne L14
X3:
.dbline 49
mov R16,R20
subi R16,255 ; offset = 1
sbci R17,255
xjmp L1
L14:
.dbline 50
; }
L6:
.dbline 51
; }
L3:
.dbline 37
subi R20,255 ; offset = 1
sbci R21,255
L5:
.dbline 37
ldd R0,y+10
ldd R1,y+11
cp R20,R0
cpc R21,R1
brsh X5
xjmp L2
X5:
X4:
.dbline 52
; return 0;
clr R16
.dbline -2
L1:
.dbline 0 ; func end
xjmp pop_xgsetF0FC
.dbsym r StrLen 12 i
.dbsym r i 20 i
.dbsym r j 22 i
.dbsym l DataLen 10 i
.dbsym r data 14 pc
.dbsym r string 10 pc
.dbend
.dbfunc e Greenwich_time _Greenwich_time fV
; data -> R20,R21
.even
_Greenwich_time::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 58
; }
; //-------------------------------------------------------------
; //格林尼治时间
; //-------------------------------------------------------------
; void Greenwich_time(unsigned char *data)
; {
.dbline 59
; debug_str_without_n("Greenwich time : ");
ldi R16,<L17
ldi R17,>L17
xcall _debug_str_without_n
.dbline 60
; debug_uchars_without_n(&data[0],2);
ldi R18,2
ldi R19,0
movw R16,R20
xcall _debug_uchars_without_n
.dbline 61
; debug_str_without_n(":");
ldi R16,<L18
ldi R17,>L18
xcall _debug_str_without_n
.dbline 62
; debug_uchars_without_n(&data[2],2);
ldi R18,2
ldi R19,0
movw R16,R20
subi R16,254 ; offset = 2
sbci R17,255
xcall _debug_uchars_without_n
.dbline 63
; debug_str_without_n(":");
ldi R16,<L18
ldi R17,>L18
xcall _debug_str_without_n
.dbline 64
; debug_uchars_without_n(&data[4],2);
ldi R18,2
ldi R19,0
movw R16,R20
subi R16,252 ; offset = 4
sbci R17,255
xcall _debug_uchars_without_n
.dbline 65
; debug_str("");
ldi R16,<L19
ldi R17,>L19
xcall _debug_str
.dbline -2
L16:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r data 20 pc
.dbend
.dbfunc e latitude _latitude fV
; data -> R20,R21
.even
_latitude::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 71
; }
; //-------------------------------------------------------------
; //纬度
; //-------------------------------------------------------------
; void latitude(unsigned char *data)
; {
.dbline 72
; debug_str_without_n("latitude : ");
ldi R16,<L21
ldi R17,>L21
xcall _debug_str_without_n
.dbline 74
;
; debug_uchars_without_n(&data[11],1);
ldi R18,1
ldi R19,0
movw R16,R20
subi R16,245 ; offset = 11
sbci R17,255
xcall _debug_uchars_without_n
.dbline 75
; debug_str_without_n(" ");
ldi R16,<L22
ldi R17,>L22
xcall _debug_str_without_n
.dbline 76
; debug_uchars_without_n(&data[0],10);
ldi R18,10
ldi R19,0
movw R16,R20
xcall _debug_uchars_without_n
.dbline 77
; debug_str("");
ldi R16,<L19
ldi R17,>L19
xcall _debug_str
.dbline -2
L20:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r data 20 pc
.dbend
.dbfunc e radian _radian fV
; data -> R20,R21
.even
_radian::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 83
; }
; //-------------------------------------------------------------
; //径度
; //-------------------------------------------------------------
; void radian(unsigned char *data)
; {
.dbline 84
; debug_str_without_n("radian : ");
ldi R16,<L24
ldi R17,>L24
xcall _debug_str_without_n
.dbline 86
;
; debug_uchars_without_n(&data[12],1);
ldi R18,1
ldi R19,0
movw R16,R20
subi R16,244 ; offset = 12
sbci R17,255
xcall _debug_uchars_without_n
.dbline 87
; debug_str_without_n(" ");
ldi R16,<L22
ldi R17,>L22
xcall _debug_str_without_n
.dbline 88
; debug_uchars_without_n(&data[0],11);
ldi R18,11
ldi R19,0
movw R16,R20
xcall _debug_uchars_without_n
.dbline 89
; debug_str("");
ldi R16,<L19
ldi R17,>L19
xcall _debug_str
.dbline -2
L23:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r data 20 pc
.dbend
.dbfunc e speed _speed fV
; i -> R10
; data -> R12,R13
.even
_speed::
xcall push_xgset003C
movw R12,R16
.dbline -1
.dbline 95
; }
; //-------------------------------------------------------------
; //地面速度
; //-------------------------------------------------------------
; void speed(unsigned char *data)
; {
.dbline 96
; unsigned char i=0;
clr R10
.dbline 98
;
; debug_str_without_n("speed : ");
ldi R16,<L26
ldi R17,>L26
xcall _debug_str_without_n
L27:
.dbline 100
; speed_top:
; if(data[i]!='.'){
mov R30,R10
clr R31
add R30,R12
adc R31,R13
ldd R24,z+0
cpi R24,46
breq L28
X6:
.dbline 100
.dbline 101
; debug_uchars_without_n(&data[i],1);
ldi R18,1
ldi R19,0
mov R16,R10
clr R17
add R16,R12
adc R17,R13
xcall _debug_uchars_without_n
.dbline 102
; i++;
inc R10
.dbline 103
; goto speed_top;
xjmp L27
L28:
.dbline 105
; }
; debug_str("");
ldi R16,<L19
ldi R17,>L19
xcall _debug_str
.dbline -2
L25:
.dbline 0 ; func end
xjmp pop_xgset003C
.dbsym r i 10 c
.dbsym r data 12 pc
.dbend
.dbfunc e gps_function _gps_function fc
; availability_flag_1 -> R20
; availability_flag_2 -> R12
; mes_addr -> R22,R23
; DataLen -> R14,R15
; data -> R10,R11
.even
_gps_function::
xcall push_xgsetF0FC
movw R14,R18
movw R10,R16
sbiw R28,2
.dbline -1
.dbline 109
; }
; //-------------------------------------------------------------
; unsigned char gps_function(unsigned char *data,unsigned int DataLen)
; {
.dbline 110
; unsigned int mes_addr=0;
clr R22
clr R23
.dbline 111
; unsigned char availability_flag_1=0;
clr R20
.dbline 112
; unsigned char availability_flag_2=0;
clr R12
.dbline 114
;
; if(data[0]=='$'){
movw R30,R10
ldd R24,z+0
cpi R24,36
brne L31
X7:
.dbline 114
.dbline 116
; //debug_uchars(data,DataLen);
; }
L31:
.dbline 118
;
; if(data[0]=='$'){//判断接收到的GPS数据头一个数据是否为'$'
movw R30,R10
ldd R24,z+0
cpi R24,36
breq X13
xjmp L33
X13:
X8:
.dbline 118
.dbline 119
; mes_addr = find_string("$GPRMC",data,DataLen);//找出字符串"$GPRMC"所在GPS数据中的位置
std y+1,R15
std y+0,R14
movw R18,R30
ldi R16,<L35
ldi R17,>L35
xcall _find_string
mov R22,R16
clr R23
.dbline 120
; if(mes_addr != 0){//有找到
cpi R22,0
cpc R22,R23
brne X14
xjmp L36
X14:
X9:
.dbline 120
.dbline 121
; mes_addr = mes_addr -1; //注意:减1才是真正的字符串位置
subi R22,1
sbci R23,0
.dbline 122
; availability_flag_1 = data[mes_addr + 8];//无效数据标志'V'(这个位置不存在'A')
movw R30,R22
adiw R30,8
add R30,R10
adc R31,R11
ldd R20,z+0
.dbline 123
; availability_flag_2 = data[mes_addr + 17];//无效数据标志'V',有效数据标志'A'
movw R30,R22
adiw R30,17
add R30,R10
adc R31,R11
ldd R12,z+0
.dbline 125
;
; if(availability_flag_2 == 'A'){//有效数据
mov R24,R12
cpi R24,65
brne L38
X10:
.dbline 125
.dbline 128
; //debug_str("gps data effective !");
; //<1> 当前位置的格林尼治时间,格式为hhmmss
; Greenwich_time(&data[mes_addr + 7]);
movw R16,R22
subi R16,249 ; offset = 7
sbci R17,255
add R16,R10
adc R17,R11
xcall _Greenwich_time
.dbline 130
; //纬度
; latitude(&data[mes_addr + 19]);
movw R16,R22
subi R16,237 ; offset = 19
sbci R17,255
add R16,R10
adc R17,R11
xcall _latitude
.dbline 132
; //径度
; radian(&data[mes_addr + 32]);
movw R16,R22
subi R16,224 ; offset = 32
sbci R17,255
add R16,R10
adc R17,R11
xcall _radian
.dbline 134
; //地面速度
; speed(&data[mes_addr + 46]);
movw R16,R22
subi R16,210 ; offset = 46
sbci R17,255
add R16,R10
adc R17,R11
xcall _speed
.dbline 136
; //
; debug_str("");
ldi R16,<L19
ldi R17,>L19
xcall _debug_str
.dbline 137
; }
xjmp L39
L38:
.dbline 138
; else if(availability_flag_2 == 'V'){//无效数据(这个有时间返回)
mov R24,R12
cpi R24,86
brne L40
X11:
.dbline 138
.dbline 141
; //debug_str("gps data invalid !");
; //<1> 当前位置的格林尼治时间,格式为hhmmss
; Greenwich_time(&data[mes_addr + 7]);
movw R16,R22
subi R16,249 ; offset = 7
sbci R17,255
add R16,R10
adc R17,R11
xcall _Greenwich_time
.dbline 142
; }
xjmp L41
L40:
.dbline 143
; else if(availability_flag_1 == 'V'){//无效数据
cpi R20,86
brne L42
X12:
.dbline 143
.dbline 144
; debug_str("gps data invalid !");
ldi R16,<L44
ldi R17,>L44
xcall _debug_str
.dbline 145
; }
xjmp L43
L42:
.dbline 146
; else{//信息有误或处理出错
.dbline 147
; debug_str("gps error !");
ldi R16,<L45
ldi R17,>L45
xcall _debug_str
.dbline 148
; }
L43:
L41:
L39:
.dbline 149
; }
L36:
.dbline 150
; }
L33:
.dbline 151
; return 1;
ldi R16,1
.dbline -2
L30:
.dbline 0 ; func end
adiw R28,2
xjmp pop_xgsetF0FC
.dbsym r availability_flag_1 20 c
.dbsym r availability_flag_2 12 c
.dbsym r mes_addr 22 i
.dbsym r DataLen 14 i
.dbsym r data 10 pc
.dbend
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L45:
.blkb 12
.area idata
.byte 'g,'p,'s,32,'e,'r,'r,'o,'r,32,33,0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L44:
.blkb 19
.area idata
.byte 'g,'p,'s,32,'d,'a,'t,'a,32,'i,'n,'v,'a,'l,'i,'d
.byte 32,33,0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L35:
.blkb 7
.area idata
.byte 36,'G,'P,'R,'M,'C,0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L26:
.blkb 10
.area idata
.byte 's,'p,'e,'e,'d,9,9,58,9,0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L24:
.blkb 11
.area idata
.byte 'r,'a,'d,'i,'a,'n,9,9,58,9,0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L22:
.blkb 3
.area idata
.byte 32,32,0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L21:
.blkb 12
.area idata
.byte 'l,'a,'t,'i,'t,'u,'d,'e,9,58,9,0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L19:
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L18:
.blkb 2
.area idata
.byte 58,0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
L17:
.blkb 18
.area idata
.byte 'G,'r,'e,'e,'n,'w,'i,'c,'h,32,'t,'i,'m,'e,9,58
.byte 9,0
.area data(ram, con, rel)
.dbfile E:\item\GPS-1280\gps.c
; }
;
; /*
; $GPRMC,,V,,,,,,,,,,N*53
;
; $GPVTG,,,,,,,,,N*30
;
; $GPGGA,,,,,,0,00,99.99,,,,,,*48
;
; $GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
;
; $GPGSV,1,1,02,32,,,38,50,,,46*76
;
; $GPGLL,,,,,,V,N*64
;
;
; gps error !
; */
;
; /*
; $GPRMC,075503.00,V,,,,,,,,,,N*79
;
; $GPVTG,,,,,,,,,N*30
;
; $GPGGA,075503.00,,,,,0,00,99.99,,,,,,*62
;
; $GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
;
; $GPGSV,2,1,06,11,,,34,17,,,39,20,,,36,32,,,36*74
;
; $GPGSV,2,2,06,42,,,38,50,,,46*75
;
; $GPGLL,,,,,075503.00,V,N*4E
;
;
; gps data invalid !
; */
;
; /*
; $GPRMC,075603.00,A,2231.90428,N,11404.37384,E,0.652,325.18,261008,,,A*66
; $GPVTG,325.18,T,,M,0.652,N,1.209,K,A*3B
; $GPGGA,075603.00,2231.90428,N,11404.37384,E,1,04,3.38,66.2,M,-2.2,M,,*76
; $GPGSA,A,2,32,17,20,11,,,,,,,,,3.53,3.38,1.00*0A
; $GPGSV,2,1,07,02,03,235,,11,22,045,35,17,42,332,37,20,44,074,37*7C
; $GPGSV,2,2,07,32,23,054,39,42,51,128,38,50,46,122,46*43
; $GPGLL,2231.90428,N,11404.37384,E,075603.00,A,A*60
;
; gps data effective !
; */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -