2019独角兽企业重金招聘Python工程师标准>>>
1、程序
主程序
#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 2ggavoid get_gpsmode(void)
{if(!flg_mode){if(buf_gps[3]=='M' && buf_gps[4]=='C') flg_rmcgga = 1; //RMCelse{if(buf_gps[3]=='G' && buf_gps[4]=='A') flg_rmcgga = 2; //GGAelse flg_rx = 0; }}else{if(buf_gps[3]=='S' && buf_gps[4]=='V') flg_rmcgga = 3; //GGAelse 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<at_id;k++){AT24C64_RdPage(k*16);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<count_gps;cj++)if(buf_gps[cj]==','){ var_seg[tp_c] = cj; tp_c++;}
}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; //GPScase 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<i1;i0++) L5_wrbyte(1,(dip_ico[i0]<<ofs)|line);
}void Lwr_icos(uchar cs,uchar cl)
{uchar k;for(k=0;k<cl;k++) Lwr_ico(buf_gps[cs+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<lc;k++) L5_wr_chr(buf_gps[ch+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:tp_h = 30; break;case 2: tp_y = chr_dec(var_seg[8]+5);if(tp_y%4==0) tp_h = 29;else tp_h = 28;break;default: tp_h = 31; break; } if(tp_d<tp_h) tp_d++;else{tp_d = 1;if(tp_m<12) tp_m++;else tp_m = 1;}Lwr_dec(tp_m); Lwr_ico('-'); Lwr_dec(tp_d); }else{Lwr_icos(var_seg[8]+3,2); Lwr_ico('-'); Lwr_icos(var_seg[8]+1,2); }L5_CE = 1;C64_buf[1] = tp_m; C64_buf[2] = tp_d; L5_setxy(0,0); ofs = 0; line = 0x40;if(buf_gps[17]=='A'){ Lwr_ico(Signal); flg_sign = 1;} else{ Lwr_ico(NoSignal); flg_sign = 0;} L5_CE = 1;if((var_seg[4]-var_seg[2])==12){L5_setxy(0,3); ofs = 0; line = 0x00; L5_wr_chr(buf_gps[29]); L5_setxy(12,3); L5_wr_chrs(19,2); Lwr_ico(chr_degree);L5_wr_chrs(21,2); Lwr_ico(chr_point);L5_wr_chrs(24,4); L5_CE = 1;if(buf_gps[29]=='N') C64_buf[6] = 0x00; //N78 S83else C64_buf[6] = 0x10;C64_buf[7] = chr_dec(19); C64_buf[8] = chr_dec(21);C64_buf[9] = chr_dec(24); C64_buf[10] = chr_dec(26);}if(var_seg[6]>41){ L5_setxy(0,4); tp_y = buf_gps[var_seg[5]+1]; L5_wr_chr(tp_y); //E/W tp_h = chr_dec(31);if(var_seg[5]>40){ L5_wr_chrs(31,3);tp_h = tp_h*10+chrtodec(33);}else{ Lwr_icob(6); L5_wr_chrs(31,2);} Lwr_ico(chr_degree); L5_wr_chrs(var_seg[5]-7,2); Lwr_ico(chr_point); L5_wr_chrs(var_seg[5]-4,4); L5_CE = 1;if(tp_y=='E') C64_buf[6]&=0xf0; //E69 W87else C64_buf[6]|=0x01;C64_buf[11] = tp_h; C64_buf[12] = chr_dec(var_seg[5]-7);C64_buf[13] = chr_dec(var_seg[5]-4); C64_buf[14] = chr_dec(var_seg[5]-2); }L5_setxy(52,2); tp_h = var_seg[7]-var_seg[6]; if(tp_h>4){ uint tp_v=0;if(tp_h==7) tp_y = 6; else tp_y = tp_h;for(tp_m=1;tp_m<tp_y;tp_m++){if(tp_m==3) tp_m++;tp_v = tp_v+chrtodec(var_seg[7]-tp_m)*185;if(tp_m<5){if(tp_v%10>4) tp_v = tp_v/10+1;else tp_v/=10;}}if(tp_h==7) tp_v = tp_v+chrtodec(var_seg[6]+1)*1850;if(tp_v<100) Lwr_icob(8); else{if(tp_v<1000) Lwr_icob(4);else{ Lwr_ico(tp_v/1000); tp_v%=1000;}Lwr_ico(tp_v/100); tp_v%=100;}Lwr_ico(tp_v/10); Lwr_ico('.'); Lwr_ico(tp_v%10);}else Lwr_icoh("---.-"); //Lwr_ico('k'); -.-kmhL5_CE = 1;L5_setxy(24,2); tp_h = var_seg[8]-var_seg[7]; if(tp_h>4){uint tp_dg=0;tp_h-=4;for(tp_y=0;tp_y<tp_h;tp_y++)tp_dg = tp_dg*10+buf_gps[var_seg[7]+1+tp_y]-48;if(tp_dg>90 && tp_dg<270){Lwr_ico('S'); Lwr_ico(Ico_point);if(tp_dg<180){ Lwr_ico('E'); tp_dg = 180-tp_dg;}else{ Lwr_ico('W'); tp_dg = tp_dg-180;} }else{Lwr_ico('N'); Lwr_ico(Ico_point); if(tp_dg<180) Lwr_ico('E');else{ Lwr_ico('W'); tp_dg = 360-tp_dg;} }Lwr_dec(tp_dg); Lwr_ico(Ico_degree); }else Lwr_icob(24);L5_CE = 1;
}void L5_GGA(void)
{uchar tp_h; L5_setxy(10,0); ofs = 0; line = 0x40;Lwr_icos(var_seg[6]+1,2); L5_CE = 1;L5_setxy(74,4); ofs = 0; line = 0x00;Lwr_ico(buf_gps[var_seg[5]+1]); L5_CE = 1;L5_setxy(74,3);if((var_seg[8]-var_seg[7])==4){Lwr_icos(var_seg[7]+1,3);tp_h = chrtodec(var_seg[7]+1)*10 +chrtodec(var_seg[7]+3);}else{ Lwr_icoh("-.-"); tp_h = 0;} L5_CE = 1;C64_buf[15] = tp_h;L5_setxy(56,1);tp_h = var_seg[9]-var_seg[8]; if(tp_h>3){Lwr_icob(28-tp_h*4); Lwr_icos(var_seg[8]+1,tp_h-1); }else Lwr_icoh("----.-"); L5_CE = 1;
}bit flg_lowbat=0;
void L5_BAT(void)
{L5_setxy(74,0); ofs = 0; line = 0x40;if(!Bat_Low){if(flg_lowbat) Lwr_icob(10);else Lwr_ico(Bat_empt);flg_lowbat = !flg_lowbat;}else Lwr_ico(Bat_full); L5_CE = 1;
}bit flg_sata=0;
void L5_SATA(void)
{L5_setxy(22,5); ofs = 0; line = 0x02;if(!flg_sata) Lwr_ico(Sata_run); else{ Lwr_ico(Sata_pause); flg_sign = 0;} L5_CE = 1;
}void L5_ComData(bit tp_cd)
{L5_setxy(20,0); ofs = 0; line = 0x40;if(tp_cd) Lwr_ico(Ico_com); else Lwr_icob(10);L5_CE = 1;
}void L5_sch(bit sen,uchar stype,uint s0,uint s1)
{L5_setxy(0,1); ofs = 0; line = 0x00;if(sen){Lwr_ico(file);if(stype==0) Lwr_ico(Ico_wait);else{if(stype==1) Lwr_ico(Ico_upload);else Lwr_ico(Ico_del);}s0 = s0*100/s1; s1 = s0/5; //20份'%'if(s0<10) Lwr_icob(8); else{if(s0<100){Lwr_icob(4); Lwr_ico(s0/10);}else Lwr_dec(s0/10);}Lwr_ico(s0%10); Lwr_ico('%'); line = 0x1f; Lwr_icob(1+s1); line = 0x11;Lwr_icob(20-s1); line = 0x1f; Lwr_icob(1);}else{ _nms(255); _nms(255); _nms(255); Lwr_icob(54);}L5_CE = 1;
}uint at_id=0;
void L5_FileN(void)
{L5_setxy(42,0); ofs = 0; line = 0x40;Lwr_dec(at_id/10); Lwr_ico(at_id%10); L5_CE = 1;
}void at_getid(void)
{uchar tp_r;at_id = 0;do{tp_r = AT24C64_RD(at_id*16);if(tp_r==0xff) break;at_id++;L5_sch(1,0,at_id,512); }while(at_id<512);L5_FileN(); L5_sch(0,0,0,0);
}void at_format(void)
{uint tp_f;if(flg_sata){ if(at_id>0){for(tp_f=0;tp_f<at_id;tp_f++){AT24C64_WR(tp_f*16,0xff); L5_sch(1,2,tp_f,at_id); }at_id = 0; L5_FileN(); L5_sch(0,0,0,0);}}
}void L5_AtWr(uchar wen)
{L5_setxy(30,0); ofs = 0; line = 0x40;if(wen==1) Lwr_ico(Ico_wait);else{if(wen==2) Lwr_ico(Ico_del);else Lwr_icob(7);} L5_CE = 1;
}void at_onewr(uchar hdat)
{if(flg_sign && at_id<512){ L5_AtWr(1);C64_buf[0] = hdat; AT24C64_WrPage(at_id*16); at_id++; L5_FileN();}else L5_AtWr(2);
}uchar var_rec=0;
void L5_recty(void)
{L5_setxy(0,2); ofs = 0; if(var_rec==0){ line = 0x00; Lwr_icob(6); Lwr_ico('H'); Lwr_icob(7);}else{ line = 0x20; Lwr_ico('A'); Lwr_dec(var_rec); Lwr_ico('s');}L5_CE = 1;
}void rec_add(void)
{switch(var_rec){case 0: var_rec = 90; break;case 90: var_rec = 60; break;case 60: var_rec = 30; break;case 30: var_rec = 10; break;default: var_rec = 0; break;}L5_recty();
}void Lgps_disp_dt(void)
{//第1行 L5_setxy(56,1); ofs = 0; line = 0x00; Lwr_icoh("----.-m"); L5_CE = 1; //第2行L5_setxy(52,2); Lwr_icoh("---.-k"); L5_CE = 1;//第3行L5_setxy(0,3); L5_wr_chr('N');L5_setxy(12,3); L5_wr_chrh("--"); Lwr_ico(chr_degree); L5_wr_chrh("--"); Lwr_ico(chr_point); L5_wr_chrh("----"); Lwr_ico(chr_min); L5_CE = 1;L5_setxy(74,3); Lwr_icoh("-.-"); L5_CE = 1;//第4行L5_setxy(0,4); L5_wr_chrh("E---"); Lwr_ico(chr_degree); L5_wr_chrh("--");Lwr_ico(chr_point); L5_wr_chrh("----"); Lwr_ico(chr_min); L5_CE = 1;L5_setxy(74,4); Lwr_icoh("0D"); L5_CE = 1;//第2行L5_recty();
}void Lgps_disp_init(void)
{L5_clear();L5_setxy(0,0); ofs = 0; line = 0x40;Lwr_ico(NoSignal); Lwr_icoh("00"); Lwr_icob(19);Lwr_ico(file); Lwr_icoh("000/512"); Lwr_icob(4);Lwr_ico(Bat_empt); L5_CE = 1;Lgps_disp_dt();L5_setxy(0,5); ofs = 0; line = 0x02; Lwr_ico(Ico_gps); Lwr_icob(2); Lwr_ico(Sata_run); Lwr_icob(4); ofs = 3;Lwr_icoh("00-00"); Lwr_icob(4); Lwr_icoh("--:--:--");L5_CE = 1;at_getid();
}unsigned char code g_sign[] = {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
void L5_GSV(void)
{ uchar tp_j,tp_jk,tp_g,tp_n;tp_n = buf_gps[8]-48; ofs = 2; line = 0x01; for(tp_j=0;tp_j<4;tp_j++){if(tp_n==1) L5_setxy(tp_j*14,2);else{if(tp_n==2){if(tp_j<2) L5_setxy((tp_j+4)*14,2);else L5_setxy((tp_j-2)*14,4);}else L5_setxy((tp_j+2)*14,4);}Lwr_icob(2);tp_jk = tp_j*4+3;if(var_seg[tp_jk+1]>(var_seg[tp_jk]+1)) Lwr_icos(var_seg[tp_jk]+1,2);else Lwr_icoh("--");Lwr_icob(4);}for(tp_j=0;tp_j<4;tp_j++){tp_jk = tp_j*4+6;if(var_seg[tp_jk+1]>(var_seg[tp_jk]+1)) tp_g = chr_dec(var_seg[tp_jk]+1);else tp_g = 0;if(tp_n==1) L5_setxy(tp_j*14,1);else{if(tp_n==2){if(tp_j<2) L5_setxy((tp_j+4)*14,1);else L5_setxy((tp_j-2)*14,3);}else L5_setxy((tp_j+2)*14,3);} line = g_sign[tp_g/12]; Lwr_icob(4);line = 0x00; Lwr_dec(tp_g);}L5_CE = 1;
}