CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with calling a char from GPS and writing to LCD
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

Problem with calling a char from GPS and writing to LCD
PostPosted: Wed Nov 23, 2005 3:15 pm     Reply with quote

I'm just trying to get a character from a GPS and writing it to an LCD. This should be fairly straightforward but apparently not for me.

As I understand it an fgetc(stream) statement will wait until a character has come, so I assume that a character has been saved when my fprint statement is acted on. Here is the code:
Code:
#include <16F876.h>
#fuses XT, NOWDT, NOPROTECT
#use delay (clock=4000000)
#use rs232 (baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=GPS,errors)
#include <LCD_4LINE.c>   // this file set up to use port B for LCD

char k;
int count=0;

main()
 {
  lcd_init();
  setup_adc_ports(NO_ANALOGS);
  setup_spi(FALSE);
  setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  setup_timer_1(T1_DISABLED);
  setup_timer_2(T2_DISABLED,0,1);
 
   while(1)
    {
     k = fgetc(GPS);        // get a character from GPS
     lcd_gotoxy(1,1);
     printf(lcd_putc,"char # %3u = %c",count,k);
     delay_ms(500);
     count++;
    }
 }


The GPS will send good NMEA data to a terminal program using the same cable and the LCD prints out " char # 0 = <a bit of gibberish here> and seems to stop there. A scope shows activity on PIN_C7 and a low voltage on PIN_C6 (1.2V I think).

Any idea on what I'm doing wrong?

Thanks.....Harry
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 3:26 pm     Reply with quote

What about the NOLVP fuse ?

If your PIC supports LVP mode, and you're not using it (which is the case
for 98% of all users), then you must add NOLVP to your #fuses statement.

You should have a post-it note with critical things for CCS.
The NOLVP fuse should go on the list.
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 3:30 pm     Reply with quote

Does that apply even if PIN_B3 isn't being used?

I had the NOLVP fuse set earlier but deleted it in an attempt to simplify my problem.

I'll reinsert it and try again.

Thanks....Harry
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 3:38 pm     Reply with quote

Just tried that but it didn't help. I plugged/unplugged the board several times and also hit reset a few times. One of those times count went up to "1" from it's usual "0".

The character always looks like a slightly corrupted "k".

Harry
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 3:48 pm     Reply with quote

Quote:
Does that apply even if PIN_B3 isn't being used?

Yes, you still need the NOLVP fuse.

Quote:

I plugged/unplugged the board several times and also hit reset a few
times. One of those times count went up to "1" from it's usual "0".
The character always looks like a slightly corrupted "k".

First, I would add BROWNOUT and PUT to the #fuses statement

If that doesn't fix the problem, then look at the LCD driver.
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 4:07 pm     Reply with quote

Quote:

First, I would add BROWNOUT and PUT to the #fuses statement

Adding the BROWNOUT and PUT fuses hasn't helped.

Quote:
If that doesn't fix the problem, then look at the LCD driver.

I also assigned a character to a variable and printed that out in the same printf statement and it worked. Doesn't that indicate that the LCD driver is working properly?

Thanks....Harry
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 4:10 pm     Reply with quote

Post your compiler version and I'll test this on my demo board.

Your compiler version is given at the top of the .LST file, which
is in the project folder for your current project. It will be a number
such as 3.191, or 3.239, etc.
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 4:17 pm     Reply with quote

PCM programmer wrote:
Post your compiler version and I'll test this on my demo board.


Version 3.219
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 4:36 pm     Reply with quote

To fix it, all you need to do is clear the LCD before you write to it
each time. Add \f to the start of your printf text, as shown below.
Quote:
while(1)
{
k = fgetc(GPS); // get a character from GPS
lcd_gotoxy(1,1);
printf(lcd_putc,"\fchar # %3u = %c",count,k);
delay_ms(500);
count++;
}



Though, please leave the NOLVP fuse in. The BROWNOUT and PUT
don't hurt, either, if you're using a wall-wart to power your board.
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 4:56 pm     Reply with quote

PCM programmer wrote:
To fix it, all you need to do is clear the LCD before you write to it
each time. Add \f to the start of your printf text, as shown below.

I had tried that previously and it didn't work. Just tried again with similar results. Can you please send me the exact code that works for you?
Quote:

Though, please leave the NOLVP fuse in. The BROWNOUT and PUT
don't hurt, either, if you're using a wall-wart to power your board.

I use all three fuses in my programs now, as you've suggested previously, and had just removed them to ensure they weren't the cause of my problem.

Thanks....Harry
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 5:02 pm     Reply with quote

I took your program and modified as little as possible, to fit my test
setup. I'm using a PicDem2-Plus board with a 16F877. It does have
the LCD on Port A and Port D. I also switched the serial to 9600 baud
just because my terminal program is setup for that.

You said that you had this problem:
Quote:
The character always looks like a slightly corrupted "k".

I got the same thing, and when I added the \f to clear the screen,
it was fixed.

Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232 (baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=GPS,errors)

// Use Mark's LCD driver from the CCS Code Library
#include <lcd_picdem2plus.c>   

char k;
int count=0;

main()
 {
  lcd_init();
  setup_adc_ports(NO_ANALOGS);
  setup_spi(FALSE);
  setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  setup_timer_1(T1_DISABLED);
  setup_timer_2(T2_DISABLED,0,1);
 
   while(1)
    {
     k = fgetc(GPS);        // get a character from GPS
     lcd_gotoxy(1,1);
     printf(lcd_putc,"\fchar # %3u = %c",count,k);
     delay_ms(500);
     count++;
    }
 }
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 5:21 pm     Reply with quote

I'm really perplexed now!

I've just tried running the code I posted with the change you made and encountered the same problems. It seems that each change alters the gibberish that is printed to the LCD. At one point it was a corrupted 'k', this last time it looked more like an 'L'.

I've been at this for a couple of days and am completely out of ideas for now.

Thanks for the help....Harry
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 5:27 pm     Reply with quote

I was using a terminal program to slowly type characters to the PIC.
Try doing that.
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Thu Nov 24, 2005 8:33 am     Reply with quote

PCM programmer wrote:
I was using a terminal program to slowly type characters to the PIC.
Try doing that.


I've done that using another board, the CCS prototyping board, with absolutly no problems. With this board, a Basic Micro 28/40, I don't have a cable to connect the rs232 to a PC. I guess I could try to put a cable together but I'm not sure what that would tell me.

Right now the LCD displays properly anything it receives directly from the PIC. Also, the GPS displays the NMEA data correctly on a terminal program.

The only thing that makes sense is that the PIC is not receiving a character from the GPS with the fgetc() function. However, the fact that the LCD prints out the fprint() function tells me that a character has been received.

Still puzzled....Harry
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 24, 2005 12:39 pm     Reply with quote

1. My test program is set at 9600 baud. Did you change it back to the
4800 baud rate which is used by your GPS ?

2. Also, I'm not sure what the purpose of your program is. A GPS will
send one or more NMEA messages every 2 seconds. The messages
might be 30 or 50 characters, or more. You're just sampling one
character every 1/2 second. All the rest of the chars just pile into
the UART and are not read, and thus cause overrun errors, which
are then detected and cleared by the CCS fgetc() code. The fgetc()
function does not provide any buffering of the incoming chars.
The only "buffer" is the 2-deep receive fifo in the hardware UART.
Once it's full, if you don't promptly read the chars, then they are lost.

So at best, you're just going to get a random character displayed on
your LCD. One time it might be a comma, then it might be a $ sign,
then a number, etc. I'm not sure what you hope to acheive by doing
this. That's why I asked if you can use a terminal program to slowly
type one char at a time. It's really the only thing this program can
properly do.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group