using Gert van der Knokke´s vga lib and Ivo van Poorten´ss fastlib to receive from GPS data and display on monitor
Dependencies: mbed vga640x480g
main.cpp
00001 /* 00002 * 640x480 60Hz fullgraphic monochrome VGA Driver demo program 00003 * 00004 * Copyright (C) 2011 by Ivo van Poorten <ivop(at)euronet.nl> 00005 * and Gert van der Knokke <gertk(at)xs4all.nl> 00006 * This file is licensed under the terms of the GNU Lesser 00007 * General Public License, version 3. 00008 * 00009 * Inspired by Simon's (not Ford) Cookbook entry and Cliff Biffle's 00010 * assembly code. 00011 */ 00012 00013 #include "mbed.h" 00014 #include "fastlib/common.h" 00015 #include "fastlib/pinsel.h" 00016 #include "fastlib/gpio.h" 00017 #include "fastlib/clock.h" 00018 #include "fastlib/power.h" 00019 #include "fastlib/pwm.h" 00020 #include "fastlib/i2s.h" 00021 #include "fastlib/uart.h" 00022 #include "fastlib/dma.h" 00023 #include "fastlib/nvic.h" 00024 00025 #include "vga640x480g.h" 00026 00027 00028 // visual feedback 00029 DigitalOut myled(LED1); 00030 DigitalOut led2(LED2); 00031 DigitalOut led3(LED3); 00032 DigitalOut led4(LED4); // Data sent LED 00033 00034 // Commands for SIRF III GPS 00035 // to turn on or off data strings 00036 #define GGA_ON "$PSRF103,00,00,01,01*25\r\n" 00037 #define GGA_OFF "$PSRF103,00,00,00,01*24\r\n" 00038 #define GLL_ON "$PSRF103,01,00,01,01*24\r\n" 00039 #define GLL_OFF "$PSRF103,01,00,00,01*25\r\n" 00040 #define GSA_ON "$PSRF103,02,00,01,01*27\r\n" 00041 #define GSA_OFF "$PSRF103,02,00,00,01*26\r\n" 00042 #define GSV_ON "$PSRF103,03,00,05,01*22\r\n" 00043 #define GSV_OFF "$PSRF103,03,00,00,01*27\r\n" 00044 #define RMC_ON "$PSRF103,04,00,01,01*21\r\n" 00045 #define RMC_OFF "$PSRF103,04,00,00,01*20\r\n" 00046 #define VTG_ON "$PSRF103,05,00,01,01*20\r\n" 00047 #define VTG_OFF "$PSRF103,05,00,00,01*21\r\n" 00048 //#define WAAS_ON "$PSRF151,1*3F\r\n" 00049 //#define WAAS_OFF "$PSRF151,0*3E\r\n" 00050 #define UARTPORT 3 00051 00052 // Set up serial ports and LEDs 00053 // SIRF GPS on Pin28 and Pin7 00054 //Serial gps(p9, p10); // tx, rx - 4800 baud required 00055 00056 //TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d0-d3 00057 00058 //char buffidx; 00059 char vgatxtbuff[80]; // Data buffer for VGA output 00060 char msg[256]; // GPS data buffer 00061 char status; // GPS status 'V' = Not locked; 'A' = Locked 00062 char *parseptr; // Pointer for parsing GPS message 00063 char time_buff[7] = "000000"; 00064 char date_buff[7] = "000000"; 00065 char sens_buff[7] = "123456"; 00066 int i; 00067 00068 void putcharact(char chardata) { 00069 00070 while ((fl_uart_get_line_status(UARTPORT)& 0x60)==0) { 00071 00072 } 00073 *FL_UART(UARTPORT, THR)= chardata; 00074 } 00075 char getcharact(void) { 00076 while ((fl_uart_get_line_status(UARTPORT)& 0x01)==0) { 00077 } 00078 return fl_uart_receive_byte(UARTPORT); 00079 } 00080 00081 // Switch off all but $GPRMC string 00082 void setgps() { 00083 sprintf(msg,GGA_ON); 00084 i=0; 00085 while (msg[i]!= 0) { 00086 putcharact(msg[i]); 00087 i++; 00088 } 00089 sprintf(msg,GLL_ON); 00090 i=0; 00091 while (msg[i]!= 0) { 00092 putcharact(msg[i]); 00093 i++; 00094 } 00095 sprintf(msg,GSA_ON); 00096 i=0; 00097 while (msg[i]!= 0) { 00098 putcharact(msg[i]); 00099 i++; 00100 } 00101 sprintf(msg,GSV_ON); 00102 i=0; 00103 while (msg[i]!= 0) { 00104 putcharact(msg[i]); 00105 i++; 00106 } 00107 sprintf(msg,RMC_ON); 00108 i=0; 00109 while (msg[i]!= 0) { 00110 putcharact(msg[i]); 00111 i++; 00112 } 00113 sprintf(msg,VTG_ON); 00114 i=0; 00115 while (msg[i]!= 0) { 00116 putcharact(msg[i]); 00117 i++; 00118 } 00119 // gps.printf(WAAS_OFF); 00120 return; 00121 } 00122 00123 // Get line of data from GPS 00124 void getline() { 00125 while (getcharact() != '$'); // Wait for start of line 00126 for (int i=0; i<256; i++) { 00127 msg[i] = getcharact(); 00128 if (msg[i] == '\r') { 00129 msg[i] = 0; 00130 return; 00131 } 00132 } 00133 } 00134 00135 00136 float trunc(float v) { 00137 if(v < 0.0) { 00138 v*= -1.0; 00139 v = floor(v); 00140 v*=-1.0; 00141 } else { 00142 v = floor(v); 00143 } 00144 return v; 00145 } 00146 00147 /** The longitude (call sample() to set) */ 00148 float longitude; 00149 /** The latitude (call sample() to set) */ 00150 float latitude; 00151 float gps_time; 00152 char ns, ew; 00153 int lock,sat_used; 00154 float HDOP; 00155 float altitude; 00156 00157 int toggle_flag=0; 00158 int gps_hour; 00159 int gps_min; 00160 int gps_sec; 00161 int s; 00162 unsigned power_state; 00163 00164 int main() { 00165 // init the VGA subsystem (always do this first!) 00166 init_vga(); 00167 setbuf(stdout, NULL); // no buffering for this filehandle 00168 00169 // gps.baud(4800); // NB GPS baud rate 4800 00170 fl_power_uart3(FL_ON); 00171 fl_select_clock_uart3(FL_CLOCK_DIV1); 00172 *FL_UART(UARTPORT, LCR) = 0x00000083; //DLAB 1 for access to divisors 00173 fl_uart_set_fractional_divider(UARTPORT, 0, 0); 00174 fl_uart_set_divisor_latch(UARTPORT, 1302); 00175 *FL_UART(UARTPORT, FCR) = 0x00000007; // FIFO enable (must) and clear FIFOs 00176 *FL_UART(UARTPORT, LCR) = 0x00000003; // DLAB 0 00177 *FL_UART(UARTPORT, IER) = 0x00000000; // no interrupts 00178 fl_pinsel(0, 0, FL_FUNC_ALT2, FL_IGNORE, FL_IGNORE); // TX3 00179 fl_pinsel(0, 1, FL_FUNC_ALT2, FL_IGNORE, FL_IGNORE); // RX3 00180 fl_uart_transmitter_enable(UARTPORT, 1); 00181 00182 setgps(); 00183 00184 00185 // clear the screen 00186 vga_cls(); 00187 // circumfence the screen 00188 vga_box(0,0,639,479,WHITE); 00189 vga_putstring(400,370,"GPS DEMO",WHITE); 00190 /* // put a string on screen 00191 for (s=0; s<150; s++) { 00192 vga_putstring(400,370-s,"GPS DEMO",WHITE); 00193 wait(0.01); 00194 vga_putstring(400,370-s,"GPS DEMO",BLACK); 00195 } 00196 for (s=0; s<150; s++) { 00197 vga_putstring(400-s,220,"GPS DEMO",WHITE); 00198 wait(0.01); 00199 vga_putstring(400-s,220,"GPS DEMO",BLACK); 00200 } 00201 for (s=0; s<150; s++) { 00202 vga_putstring(250,220+s,"GPS DEMO",WHITE); 00203 wait(0.01); 00204 vga_putstring(250,220+s,"GPS DEMO",BLACK); 00205 } 00206 for (s=0; s<150; s++) { 00207 vga_putstring(250+s,370,"GPS DEMO",WHITE); 00208 wait(0.01); 00209 vga_putstring(250+s,370,"GPS DEMO",BLACK); 00210 } 00211 wait(1); 00212 for (s=0;s<30;s++){ 00213 vga_putstring(400,370,"GPS DEMO",WHITE); 00214 wait(.1); 00215 vga_putstring(400,370,"GPS DEMO",BLACK); 00216 wait(.1); 00217 } 00218 */ 00219 00220 vga_putstring(10,50,"CGA",WHITE); 00221 vga_putstring(10,70,"GLL",WHITE); 00222 vga_putstring(10,90,"GSA",WHITE); 00223 vga_putstring(10,110,"GSV",WHITE); 00224 vga_putstring(10,130,"RMC",WHITE); 00225 vga_putstring(10,150,"RMC",WHITE); 00226 00227 00228 00229 while (1) { 00230 led4=1; 00231 getline(); 00232 if (sscanf(msg,"GPGGA,%s", &vgatxtbuff)>=1){ 00233 vga_putstring(50,50,vgatxtbuff,WHITE); 00234 } 00235 if (sscanf(msg,"GPGLL,%s", &vgatxtbuff)>=1){ 00236 vga_putstring(50,70,vgatxtbuff,WHITE); 00237 } 00238 if (sscanf(msg,"GPGSA,%s", &vgatxtbuff)>=1){ 00239 vga_putstring(50,90,vgatxtbuff,WHITE); 00240 } 00241 if (sscanf(msg,"GPGSV,%s", &vgatxtbuff)>=1){ 00242 vga_putstring(50,110,vgatxtbuff,WHITE); 00243 } 00244 if (sscanf(msg,"GPRMC,%s", &vgatxtbuff)>=1){ 00245 vga_putstring(50,130,vgatxtbuff,WHITE); 00246 } 00247 if (sscanf(msg,"GPVTG,%s", &vgatxtbuff)>=1){ 00248 vga_putstring(50,150,vgatxtbuff,WHITE); 00249 } 00250 // Check if it is a GPGGA msg (matches both locked and non-locked msg) 00251 if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f", &gps_time, &latitude, &ns, &longitude, &ew, &lock, &sat_used, &HDOP, &altitude) >= 1) { 00252 if(!lock) { 00253 led4 = 1; 00254 longitude = 0.0; 00255 latitude = 0.0; 00256 } else { 00257 led4 = 0; 00258 if(ns == 'S') { latitude *= -1.0; } 00259 if(ew == 'W') { longitude *= -1.0; } 00260 float degrees = trunc(latitude / 100.0f); 00261 float minutes = latitude - (degrees * 100.0f); 00262 latitude = degrees + minutes / 60.0f; 00263 degrees = trunc(longitude / 100.0f); 00264 minutes = longitude - (degrees * 100.0f); 00265 longitude = degrees + minutes / 60.0f; 00266 gps_hour = trunc(gps_time/10000.0f); 00267 gps_min = trunc((gps_time - gps_hour*10000.0f)/100.0f); 00268 gps_sec = trunc(gps_time-gps_hour*10000.0f-gps_min*100.0f); 00269 gps_hour++; 00270 if (gps_hour>=24) { 00271 gps_hour=0; 00272 } 00273 } 00274 sprintf(vgatxtbuff, "lat: %3.7f long: %3.7f time: %2.4f sat_used: %d alt: %5.3f",latitude, longitude,gps_time, sat_used, altitude); 00275 vga_putstring(10,30,vgatxtbuff,WHITE); 00276 } 00277 } 00278 } 00279
Generated on Thu Jul 14 2022 20:51:04 by 1.7.2