Interface de um simulador GPS com controlador PIC18F458 no Proteus usando um emulador de porta serial

Interfacing a GPS simulator with PIC18F458 controller into Proteus using a serial port emulator

For this project, except a cell phone with GPS to record NMEA GPS sentences, no hardware is required. I used an Android phone and several apps are available on the Play Store that allow you to record NMEA sentences in “.txt” or “.log” format. Since not all users have access to an Android phone, I have attached two sets of GPS phrases to allow you to complete this project. Since no GPS signal could be obtained indoors, the first set of GPS sentences were recorded by walking approximately 100 meters outdoors. The second set of GPS sentences was recorded indoors for a condition with no GPS signal. The only other hardware required is a Host PC. For this project, I used an HP Pavilion G6 series laptop with a 2.1 GHz Intel processor and 3 GB of RAM running the Windows 7 Home Basic 64-bit operating system. The following software is required to successfully complete this project:

1) GPS Yes

2) Labcenter Proteus v7.6 or higher (v7.8 with SP2 was used for this project)

3) Eltima v5.0 Serial Port Splitter

GSM

Figure 1: GPS Simulator Window

Figure 1 shows the GPS Simulator window. To begin browsing to the folder containing the NMEA sentence log files, click the Browse button. Select the interval as 8 seconds. 4 seconds can also be selected; however, any range less than this will cause errors in Proteus and latitude and longitude information will not be displayed for all sentences. Additionally, select RMC as the sentence type, as only these sentences are passed to the Proteus simulation and are used to obtain latitude and longitude information. Then select the COM1 port from the port selection menu. Any available port can be selected, as long as it is not the COM2 port. The COM2 port is used on the Proteus to transmit data to the controller's USART RX pin. Additionally, the port selected in this menu must be the same one used to create a virtual link (using Eltima Serial Splitter) between the port and the COM2 port on Proteus. The GPS Simulator software can be downloaded from the following link:

Fig. 2: Serial Divider Window

Figure 2 shows the Eltima Software Serial Splitter 5.0 window. To create the virtual link between the port selected in the GPS Simulator and the COM2 port used in Proteus, select the 'Complex Bundles' tab. For the input side, select the 'Virtual Port' option and then the COM port used by the GPS Simulator to pass sentences to Proteus (COM1 in this case). Then click on the 'Add Port' button. Repeat the same procedure for the output side, but select the COM2 port. Once the input and output ports have been added, click on the 'Add Package' button. A successfully created package will appear on the left side of the software window, as shown in the figure. A 14-day trial version of Serial Splitter can be downloaded from the following link:

The Circuit Diagram tab shows the Proteus circuit for the simulation. A 15.9744 MHz crystal is connected to pins 13 and 14 of the PIC18F458 microcontroller. Switch SW1 is the reset switch. The RXD pin of the P2 COMPIM component is connected to the RX pin (pin 26) of the controller. A MAX232 IC is not required as it is integrated into the COMPIM component. The D port of the controller is connected to the parallel data lines D0:D7 of the LCD display. The VSS and VDD pins of the LCD are grounded and provide a voltage of 5V respectively. The RS, R/W and E pins of the LCD are connected to pins 38, 39 and 40 respectively on Port B.
To develop the control logic for GPS sentence analysis, the UART module was configured and latitude and longitude information was analyzed using string manipulation. To configure the UART module, the RX pin was configured for input and serial reception was enabled by assigning a value 0x90 to the RCSTA receive register. The baud rate generator register SPBRG received a value of 0x19 for baud rate of 9600bps. Asynchronous mode was chosen by clearing the SYNC bit in the transmit status and control register of the TXSTA. The receive flag was cleared and data was copied from the RCREG receive register to a temporary variable when the flag was set upon receiving the data. The CREN continuous receive enable bit in the RCSTA receive register was then cleared to allow continuous data reception.

The $GPRMC sentences were passed from the GPS simulator to the RX pin of the controller via the COMPIM component. Two sets of these sentences were pre-recorded using a GPS-enabled cell phone for two conditions – a varying GPS location and no GPS signal. For a variable GPS location, the first set of sentences was recorded at a distance of 100m. In the absence of a GPS signal, the second set of GPS sentences were recorded indoors. The sentences $GPRMC and $GPGGA (GPS signal condition found) were the same length (76 characters). If no GPS signal was found, sentences shorter than 76 characters contained no latitude and longitude information; instead, a series of commas were found in the recorded sentences. These features of the recorded sentences were used to identify the $GPRMC sentence and then extract latitude and longitude information. The identification of the $GPRMC sentence and the absence of GPS signal was obtained using string comparison. Once the GPS signal and $GPRMC were found, the latitude and longitude were extracted by determining the starting position and the number of characters in the latitude and longitude values. Figure 5 shows the control logic for parsing the $GPRMC sentence.

GPS

Figure 3: Control logic for GPS sentence analysis

To run the simulation, the following steps must be performed in the order indicated:

1) Start the Serial Splitter and create the complex packet between the input port of the GPS Simulator and the COM2 port of the Proteus circuit

2) Open 'gps.DSN' in Proteus

3) Start GPS Simulator and select log file

4) Start the simulation in Proteus and then start transmitting the log file in GPS Simulator

The LCD display will show that the GPS signal has been found and will display latitude and longitude information. Only part of this information is shown in Figure 6, as the LCD display is turned off and the following latitude and longitude information is shown. For the second log file, the LCD display will show that the GPS signal is not found.

GPS

Fig. 6: Latitude information partially showing

Project source code

###


 #include
#include
#pragma configuration OSC=HS #pragma OSCS configuration = OFF #pragma WDT configuration = OFF #pragma configuration DEBUG = OFF #pragma LVP configuration = OFF #define rsPORTBbits.RB7 #define rw PORTBbits.RB6 #define in PORTBbits.RB5 #define LCD PORTD void mydelay(unsigned character); void data_wrt(unsigned character); void init_lcd(void); void cmd_wrt(unsigned character); void lat_long(void); void nothing(void); unsigned character cmd ={0x38,0x01,0x0C,0x06}; //LCD command unsigned char strcompare(char *s1, char *s2, size of unsigned char); //String comparison function unsigned character gps(77)={'�'}; unsigned character status; signed character; /**/ unsigned char lati(11) = "Latitude: "; unsigned char longi(12) = "Longitude: "; unsigned char deg(9) = "degrees"; unsigned character mins(10) = "minutes", "; main void(void) { // check phrase variables unsigned static character gprmc(7), gprmctemp(7)="$GPRMC"; static int gp1,gp2; static int st=0,len=6; static int i,j,k; //check satellite correction variables unsigned static character sc(2), sctemp(2)="V"; static int sc1,sc2; static int sc_st=8,sc_len=1; static unsigned char nogps(14) = "No GPS signal"; static unsigned char yesgps(17) = "GPS signal found"; internal x,y; state = 0; ret = 0; TRISB = 0x00; //make portB as output TRISD = 0x00; //make portD as output PORTCbits.RX = 1; //Defines the RX pin as input TXSTAbits.SYNC = 0; //asynchronous mode TXSTAbits.BRGH = 1; //high baud rate RCSTA = 0x90; //enable serial port and receiver SPBRG = 0x19; //9600 baud rate, 16MHz xtal init_lcd; my delay(1); cmd_wrt(0x80); //force the cursor to the beginning of the 1st line while(1) { for(x=0;x<76;x++) { while(PIR1bits.RCIF==0); //wait to receive gps(x) = RCREG; } //Checks if the $GPRMC sentence was received for (gp1=st,gp2=0; gp2 gprmc(gp2)=gps(gp1); gprmc(gp2)='�'; for (sc1=sc_st,sc2=0;sc2 sc(sc2)=gps(sc1); sc(sc2)='�'; if (strcompare(gprmc,gprmctemp,6)==1 && (strcompare(sc,sctemp,1)==0)) //Checks if the GPS signal was found { //cmd_wrt(0x80); for(j=0;j<16;j++) data_wrt(simgps(j)); mydelay(500); cmd_wrt(0xC0); my delay(1); cmd_wrt(0x80); my delay(1); lat_long ; } if ((strcompare(gprmc,gprmctemp,6)==1) && (strcompare(sc,sctemp,1)==1)) { //cmd_wrt(0x80); for(l=0;l<13;l++) data_wrt(nogps(i)); mydelay(500); cmd_wrt(0x01); my delay(1); cmd_wrt(0x80); my delay(1); } RCSTAbits.CREN=0; //Clears the continuous receive enable bit RCSTAbits.CREN=1; //Set the continuous receive enable bit for continuous reception } } empty lat_long(empty) { unsigned static character latitude(13), longitude(14); static int lat_a,lat_b,long_c,long_d; static int lat_st1=19,long_st2=33,lat_len1=13,long_len2=14; /****Latitude****/ //Declarations to separate digits and characters static int lat1_a,lat2_b,lat1_c,lat2_d; static int la_st1=0,la_st2=11,la_len1=12,la_len2=1; unsigned static character latF1(12), latF2(1); //Statements to separate degrees and minutes from digits static int laa,lab,lac,lad; static int last1=0,last2=1,lalen1=2,lalen2=9; static unsigned char latFinal1(2), latFinal2(9); //Variables for display static int i1,j1,k1,l1,m1,n1; /****Longitude****/ //Declarations to separate digits and characters static int long1_a,long2_b,long1_c,long2_d; static int long_st1=0,lo_st2=12,long_len1=12,lo_len2=1; static unsigned char longF1(12), longF2(1); //Statements to separate degrees and minutes from digits static int loa,lob,loc,lod; static int lost1=0, lost2=2,lolen1=2,lolen2=9; static unsigned char longFinal1(3), longFinal2(9); static int i2,j2,k2,l2,m2,n2; /*latitude*/ // Extracting latitude information for (lat_a=lat_st1,lat_b=0; lat_b latitude(lat_b)=gps(lat_a); latitude(lat_b)='�'; //Separating digits and characters for (lat1_a=la_st1,lat2_b=0; lat2_b latF1(lat2_b)=latitude(lat1_a); latF1(lat2_b)='�'; for (lat1_c=la_st2,lat2_d=0; lat2_d latF2(lat2_d)=latitude(lat1_c); latF2(lat2_d)='�'; //Display in degrees and minutes for (laa=last1,lab=0; laboratory latFinal1(lab)=latF1(laa); latFinal1(lab)='�'; for (lac=last2,lad=0; boy latFinal2(lad)=latF1(lac); latFinal2(lad)='�'; /*put the code to display latitude here*/ cmd_wrt(0x01); my delay(1); cmd_wrt(0x80); for(i1=0;i1<10;i1++) data_wrt(lati(i1)); my delay(50); cmd_wrt(0xC0); my delay(1); for(j1=0;j1<2;j1++) data_wrt(latFinal1(j1)); for(k1=0;k1<8;k1++) data_wrt(deg(k1)); mydelay(500); cmd_wrt(0x01); my delay(1); cmd_wrt(0x80); for(l1=0;l1<9;l1++) data_wrt(latFinal2(l1)); cmd_wrt(0xC0); for(m1=0;m1<9;m1++) data_wrt(mins(m1)); my delay(1); for(n1=0;n1<1;n1++) data_wrt(latF2(n1)); mydelay(500); /*longitude*/ cmd_wrt(0x01); my delay(1); cmd_wrt(0x80); for(i2=0;i2<10;i2++) data_wrt(longi(i2)); my delay(50); cmd_wrt(0xC0); my delay(1); // Extracting longitude information for (long_c=long_st2,long_d=0; long_d longitude(long_d)=gps(long_c); longitude(long_d)='�'; //Separating digits and characters for (long1_a = long_st1, long2_b = 0; long2_b longF1(long2_b)=longitude(long1_a); longF1(long2_b)='�'; for (long1_c=lo_st2,long2_d=0; long2_d longF2(long2_d)=longitude(long1_c); longF2(long2_d)='�'; //Display in degrees and minutes for (loa=lost1,lob=0; lob longFinal1(lob)=longF1(loa); longFinal1(lob)='�'; for (loc=lost2,lod=0; lod longFinal2(lod)=longF1(loc); longFinal1(lod)='�'; /*insert the code to display the longitude here*/ for(j2=0;j2<3;j2++) data_wrt(longFinal1(j2)); for(k2=0;k2<8;k2++) data_wrt(deg(k2)); mydelay(500); cmd_wrt(0x01); my delay(1); cmd_wrt(0x80); for(l2=0;l2<9;l2++) data_wrt(longFinal2(l2)); cmd_wrt(0xC0); for(m2=0;m2<9;m2++) data_wrt(mins(m2)); my delay(1); for(n2=0;n2<1;n2++) data_wrt(longF2(n2)); mydelay(500); cmd_wrt(0x01); my delay(1); cmd_wrt(0x80); my delay(1); RCSTAbits.CREN=0; //Clears the continuous receive enable bit RCSTAbits.CREN=1; //Set the continuous receive enable bit for continuous reception main ; } strcompare from unsigned char (char *s1, char *s2, size of unsigned char) { unsigned character i; for (l=0;l { if(*s1 != *s2) { return 0; } other { //Do nothing } s1++; s2++; } return 1; } /*****LCD Code*****/ empty init_lcd { int j; for(j=0;j<4;j++) cmd_wrt(cmd(j)); } /*************************************/ void cmd_wrt (unsigned char cmddata) { rs=0;// selects rs as reg command rw=0;//to write to the LCD lcd=cmddata; en=1; my delay(1); en=0; my delay(1); } void data_wrt (unsigned character data) { rs=1;// selects rs as data record rw=0; lcd=data; en=1; my delay(1); en=0; my delay(1); } void mydelay (unsigned character value) { for(;val>=1;val--) { Delay1KTCYx(1); } }

###

Circuit diagrams

gps_proteus

Conteúdo Relacionado

Determinar uma localização precisa é necessário em várias indústrias...
A network of sensors is embedded in every vehicle,...
The motor controller is one of the most important...
ESP32-CAM is a compact camera module that combines the...
A evolução dos padrões USB foi fundamental para moldar...
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A Sealevel Systems anuncia o lançamento da Interface Serial...
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
O mercado embarcado tem uma necessidade de soluções de...
You have probably come across the term ' drag...
You probably have a support insulator if you've noticed...
You've probably seen stand an insulator sit on power...
You've probably seen shackle insulators enthroned on electricity poles,...
You have probably experienced situations where controlling a circuit...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.