PIC16F877 and GPS module (EM-406A)

My project is to get latitude and longitude from the gps module and print it on the LCD using PIC 16F877

I wrote this code

but it does’t work

also I try to increase the bound rate

but nothing appear to the lcd

char uart_rd;
char uart[11];
 
// LCD module connections
sbit LCD_RS at LATB2_bit;
sbit LCD_EN at LATB3_bit;
sbit LCD_D4 at LATB4_bit;
sbit LCD_D5 at LATB5_bit;
sbit LCD_D6 at LATB6_bit;
sbit LCD_D7 at LATB7_bit;
 
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
 
void main() {
  TRISB = 0;
  PORTB = 0x00;
 
  UART1_Init(4800);              // Initialize UART module at 9600 bps
  Delay_ms(3000);                 // Wait for UART module to stabilize
 
  //UART1_Write_Text("Start");
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);           // Cursor off
 
  lcd_out(1,1,"lcd");
  delay_ms(1000);
 
  uart1_write(0x08);
  delay_ms(5000);
  while(1) {
      // uart1_write_text("$GPGGA,002153.000,3342.6618,N,11751.3858,W,1,10,1.2,27.0,M,-34.2,M,,0000*5E,0x0d,0x0a");
     //uart1_write_text("$GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41,0x0d,0x0a");
     //uart1_write(0x0d);
     //uart1_write(0x0a);
     delay_ms(2000);
     delay_ms(10000);
     if(UART1_Data_Ready()) {      // If data is received,
     uart_rd=uart1_read();
   //  gps_value=gps_data(GPS_LATHIGH);
     lcd_chr(2,12,uart_rd);
     uart1_read_text(uart, ".", 15);
     lcd_out(1,5, uart);
     delay_ms(500);
  }
  }
}

any suggestions

thank u.

Hi,

The voltage swing of the EM-406 Tx output is incompatible with the Schmitt trigger input of the PIC Rx input. You need a buffer to boost the signal level between the GPS and the PIC.

John

please can you explain more

and what type of buffer I need

You need to boost up the voltage of the GPS units output to be high enough to trigger the PIC’s UART input.

Even though that GPX unit runs on 5v, the datasheet shows that the GPS TX only pushes out 2.85v.

Try a pull up resistor across 5v and the GPS TX line, maybe 4.7K, maybe as low as a 1K.

If that doesn’t work…

http://www.sparkfun.com/products/8745

Hi,

The problem is that the Tx output from the GPS module swings from 0V to 2.85V, and the Rx input of the PIC requires a minimum of 4V to trigger reliably. I’ve tried the resistor “pullup” trick" on the GSP output, and it doesn’t work in this application, so you’ll need to use a buffer to boost the signal. Two NPN small-signal transistors and a couple of resistors are all you’ll need to do the job, although the Sparkfun level converter will work well also!

John

PS I’m not in a position to post a schematic right now, but if you need one I’ll do it tomorrow!

Hi,

Here is a simple circuit for a buffer that works well with the EM-406, and a PIC.

John

OR…a simpler fix…

Lower the operating voltage of the PIC itself to 3.8v. That’ll put the voltage from the GPS barely into the .75Vdd range of the ST input on the PIC. Drop the voltage a tad lower to get it more into range. You’ll be below the spec’d lower operating voltage for the 16F877 (who uses the 16F877 anymore?), but it’ll likely work at 3.8volts (or less) if you run the PIC slow enough.

Or…somewhat simple-r yet…

Move the GPS TX input over to a TTL input pin (Port A or B) and use a software “bit-banged” serial routine instead of the hardware UART.

Hi,

I disagree with both your “OR…a simpler fix…” solutions. First, it’s a bad idea to be operating a device outside of the range specified by the manufacturer. Those specifications are published for a reason, and to be sure, not all of them are hard and fast under all conditions, but you’re

certainly operating in an area where odd things can happen if you operate outside the specified range. It’s just a bad engineering practice to design that into a project. Second, Microchip added a hardware UART to a lot of PICs for a reason. The serial interrupt capability, and two byte input buffer of the hardware UART make this feature highly desirable for a GPS data input. I hardly think 5 discrete components is worth the aggravation of giving this feature up, not to mention the hassle of the software “bit-banged” approach!

Is this supposed to be some sort of a “one-upman-ship” thing with you? First, I tell the OP that he’s going to need a buffer between his GPS and his PIC. You concur and suggest trying a pull-up, or a Sparkfun level translator. I then check back in to give the OP a simple circuit that I’ve actually been using with a EM-406 and a PIC 16F689, and then you pop back in with some (IMHO) questionable advise that’s even “simpler”… I fail to see how your last post does anything to help the OP??

John

No…no…no…just a couple quick tricks/tries to verify that the thing is just plain ol’ working and have something to play with.

If the guy has a few parts hanging around, or a few things to try without having to wait around for the next UPS or FedEx shipment to arrive, AND won’t blow anything up in the process, AND can get back to where they started from, then why not?

Sure it’s a bad idea to operate out of spec’s…if I was trying to talk him into running the thing just outside of the upper range on 6 volts rather than just outside of the lower range on 3 volts.

3 out of 4 16F877"A" I’ve got in my box work fine down to 3volts @ 10Mhz (don’t have any “LF”), the 4th takes 3.4v @ 10Mhz.

Hassle of the software ‘bit-banged’ approach? Ok…whatever. 99% of the newb don’t know the different between a UART and a bit-banged serial port anyways. Look at that code. You think the overhead incurred by a ‘bit-bang’ routine is going to matter with all those delays?

5 discrete components (or 1 logic-level converter BOB)…well…if the guy ain’t got 'em in his “box-o-parts”, then those 5 discrete components aren’t going to help out in the first place now are they?

Jeeze dude…get off it. It’s about the hobby, not saving lives. Methinks I’m glad I pissed in your Wheaties this morning.

Hi,

Ummm, the OP could launch his own constellation of GPS satellites too, and make his own receivers also, right? On the other hand, my assumption was that he was merely looking for a simple solution to a simple problem. I think I gave him that, while your primary objective seems to have been flexing your intellectual muscle…

In any event, don’t flatter yourself, internet forum skirmishes don’t interest me! Your phraseology, BTW, is quite illuminating. At least, now I know who I’m dealing with! So, next time you venture up from the basement, please say ‘hi’ to your mom :-)!

John

ezflyr:
So, next time you venture up from the basement, please say ‘hi’ to your mom :-)!

Next time I venture up from the basement, or more accurately, back into the house from the shop, I'll say hi to **YOUR** mom.

Hi guys, Thank you for all your replys

we’ve been trying to get any data for so long now but still nothing is apearing

what we did so far:

  1. we added Op-Amp to get higher voltage

  2. BC 818 transistor buffer

  3. changing the baud rate from 4800 to 9600, 19200, 38400

// uart1_write_text(“$PSRF100,1,9600,8,1,0*0C”);

//uart1_write(0x0D);

// uart1_write(0x0A);

and still no results :frowning:

we are starting to lose hope :((

Thank you guys

ibrahim:
// uart1_write_text(“$PSRF100,1,9600,8,1,0*0C”);

Recheck your checksum.

finaly I recive data but it shown for me in the 2x16 lcd like this:

?M??A?D?DJMS??Q???ih*???jiL?K?$???%?$%?M??DD?6???I???i?d?j???j

?G???hh???$?M???B???TJ4I???dj??I??5?J???hhF???

and also in the pc terminal !!

what do you think is the wrong ??

Baud rate mismatch.

I check the Baud rate again

and also I got the same result :frowning:

A) Unless you changed your checksum in your code, it’s still wrong. And I don’t know if this is the case or not, if the EM406A maintains settings between power ups and you haven’t done some sort of hard reset, the you will probably end up trying a lot of possible combinations of the format of the serial data because you don’t know WHAT the EM406A is expecting due to the fact that you weren’t using the correct checksum in the first place. In fact, and again, I don’t know if this is the case or not, if the checksum is wrong, the EM406A would likely ignore that command.

B) If the PC terminal is wrong and your LCD is wrong, maybe your hookup is wrong…in that you’re trying to receive TTL-RS232 when you are actually receiving inverted TTL-RS232.