Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help required .... (C function does not return)

Status
Not open for further replies.

hssn601

Member
here is my code it extract latt/longi first time only but when program executes 2nd time it stuck at serial() function and do not return to the main :(
i am using CCs compiler.
thankss ..

serial()
{
while(loop<25 )
{

ch=getch();
if
(ch=='L')
{

ch=getch();
if
(ch=='L')
{
for(loop;loop<25;loop++)
{

ch=getch();
cmd[loop]=ch;
}
}

}
}
loop=0;
ch=0;
}

void main(void)
{
while(1)
{
serial();
set_tris_c(0b10000000);
set_tris_D(0x00);
lcd_init();
delay_ms(20);
lcd_gotoxy(1,1);
printf(lcd_putc,"LAT=%c%c%c%c%c%c%c%c%c%c%c \n",cmd[1],cmd[2],cmd[3],cmd[4],cmd[5],cmd[6],cmd[7],cmd[8],cmd[9],cmd[10],cmd[11]); lcd_gotoxy(1,2);
printf(lcd_putc,"LON=%c%c%c%c%c%c%c%c%c%c%c%c",cmd[13],cmd[14],cmd[15],cmd[16],cmd[17],cmd[18],cmd[19],cmd[20],cmd[21],cmd[22],cmd[23],cmd[24]); }
}
 

Attachments

  • gpss.jpg
    gpss.jpg
    609.6 KB · Views: 150
Last edited by a moderator:
You know him as!!!! be80be...

Your serial isn't getting 'L' and 'L' .. Heres what to do... you make a 50 character buffer.. you read the serial port and place the byte in the buffer and continue IF you receive an 'L' you mark its position with a pointer IF the next char is an 'L' you then count 25 each time there was a received character... you poll the serial port using the RXSTA.RCIF.
 
well as i am new to programing i dont know how to locate 'L' through IF and when program run 1st time it sucessfully gets "L" from rx so what happen next time?
 
This is why it only works one time A while loop will only run while true your making it false with this "for(loop;loop<25;loop++)" It can't inc past 25

Should be " for (loop=0; loop<25; loop++)"

Post your whole code
 
Last edited:
Last edited:
Don't you use indenting?

Here's your code with proper indenting,
C:
#include <16F877A.h>
#fuses NOWDT,NOLVP,NODEBUG,NOPUT,HS
#use delay(clock=40000000)
#use rs232(baud=9600,rcv=PIN_C7,xmit=PIN_C6)
#include <flexlcd.c>
int loop=0;
char cmd[26];
char ch;

serial(){
    while(loop<25 ){
        ch=getch();
        if(ch=='L'){
            ch=getch();
            if(ch=='L'){
                for(loop=0;loop<25;loop++){
                    ch=getch();
                    cmd[loop]=ch;
                }
            }
        }
    }
    loop=0;
    ch=0;
}



void main(void){
    while(1){
        serial();
        set_tris_c(0b10000000);
        set_tris_D(0x00);
        lcd_init();
        delay_ms(20);
        lcd_gotoxy(1,1);
        printf(lcd_putc,"LAT=%c%c%c%c%c%c%c%c%c%c%c \n",cmd[1],cmd[2],cmd[3],cmd[4],cmd[5],cmd[6],cmd[7],cmd[8],cmd[9],cmd[10],cmd[11]);
        lcd_gotoxy(1,2);
        printf(lcd_putc,"LON=%c%c%c%c%c%c%c%c%c%c%c%c",cmd[13],cmd[14],cmd[15],cmd[16],cmd[17],cmd[18],cmd[19],cmd[20],cmd[21],cmd[22],cmd[23],cmd[24]);
    }
}
I don't have time to look at it now, just on my way out. I'll try and look tomorrow night.

Edit, can you explain what it is supposed to do?

Mike.
 
Last edited:
The indenting wasn't to fix your code, just to make it more readable/understandable. I'm kinda drunk now but tomorrow I'll try and post some code that helps you.

Mike.
 
Check this out:

Code:
#include <16F877A.h>
#fuses NOWDT,NOLVP,NODEBUG,NOPUT,HS
#use delay(clock=40000000)
#use rs232(baud=9600,rcv=PIN_C7,xmit=PIN_C6)
#include <flexlcd.c>

int loop=0;
char cmd[26];
char ch;

serial()
{
  char done=0;

  while(!done)
  {
      ch=getch();

      if(ch == 'L')
      {
        cmd[0]=ch;
        for(loop=1;loop<25;loop++)
        {
          ch=getch();
          cmd[loop]=ch;
        }
        done = 1;
      }
  }
  loop=0;
  ch=0;
}

void main(void)
{

  while(1)
  {

    serial();
    set_tris_c(0b10000000);
    set_tris_D(0x00);
    lcd_init();
    delay_ms(20);

    lcd_gotoxy(1,1);
    printf(lcd_putc,"LAT=%c%c%c%c%c%c%c%c%c%c%c \n",cmd[1],cmd[2],cmd[3],cmd[4],cmd[5],cmd[6],cmd[7],cmd[8],cmd[9],cmd[10],cmd[11]);
    
    lcd_gotoxy(1,2);
    printf(lcd_putc,"LON=%c%c%c%c%c%c%c%c%c%c%c%c",cmd[13],cmd[14],cmd[15],cmd[16],cmd[17],cmd[18],cmd[19],cmd[20],cmd[21],cmd[22],cmd[23],cmd[24]);
  }
}

This is untested since i dont know exactly what you need.
 
Last edited:
What is the data your expecting i mean? From what i can see. You are expecting 24 bytes..

First byte is "L"
Next 11 bytes is longitude data
Next byte is?
Next 11 bytes is latitude data

Am i correct?

Did u test my code?
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top