EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / c program for gps based warning system when crossing boundaries

c program for gps based warning system when crossing boundaries

|

Microcontroller › PIC › c program for gps based warning system when crossing boundaries

  • This topic has 3 replies, 2 voices, and was last updated 12 years, 11 months ago by AJISH ALFRED.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • July 25, 2012 at 8:43 am #1890
    chalani
    Participant

     

    #include <htc.h>

    #define RX_PIN TRISC7
    #define TX_PIN TRISC6
    #define _XTAL_FREQ 4000000


    __CONFIG(1,XT & WDTDIS & LVPDIS);

    /****** serial comms using USART to comm port ***************/

    void serial_setup()
    {
    SYNC=0; //Asynchronous mode
    BRGH=1; //High Speed
    SPBRG=25; //9600 bps
    SPEN=1; //Enable serial port
    CREN=1; //Enable reception
    SREN=0; //No effect
    TXIE=0; //Desable interrupts
    RCIE=0; //disable rx interrupts
    TX9=0; //8-bit transmission
    RX9=0; //8-bit reception
    TXEN=1; // Enable transmission
    }

    void putch(unsigned char byte) 
    {
    /* output one byte */
    while(!TXIF) /* set when register is empty */
    continue;
    TXREG = byte;
    }

    unsigned char getch() {
    /* retrieve one byte */
    while(!RCIF) /* set when register is not empty */
    continue;
    return RCREG;
    }



    unsigned char getch();
    unsigned char longi_data[12];
    unsigned char lati_data[12];
    unsigned char data,value=0;
    unsigned int i=0,pos;

    float latitude;

    void main(void){
    RX_PIN = 1;
    TX_PIN = 0;
    unsigned char input1;
    unsigned char input2;
    unsigned char input3;
    serial_setup();
    INTCON=0; // purpose of disabling the interrupts.




    while(1){

    {
    data=getch(); // Check the string ‘$GPGGA,’
    if(data==’$’)
    {
    data=getch();
    if(data==’G’)
    {
    data=getch();
    if(data==’P’);
    {
    data=getch();
    if(data==’G’);
    {
    data=getch();;
    if(data==’G’)
    {
    data=getch();
    if(data==’A’)
    {
    data=getch();
    if(data==’,’)
    {
    data=getch();
    while(data!=’,’)

    data=getch();

    for(i=0;data!=’N’;i++)
    { data=getch();
    lati_data=data; // Store the Latitude data

    putch(data);
    }
    } data=getch();
    if(data==’,’)
    {
    for(i=0;data!=’E’;i++)
    {
    data=getch();

    longi_data=data; // Store the Longitude data
    putch(data);
    }
    }




    i=0;

    while(i<11)
    {
    PORTB=lati_data; // Print the Latitude data

    i++;
    }

    i=0;

    while(i<12)
    {
    PORTD=longi_data; // Print the Longitude data


    i++;
    }





    }









    }
    }
    }
    }
    }
    }

    __delay_ms(10);
    for(i=0;i<12;i++)
    {
    data=0;
    lati_data=0;
    longi_data=0;
    }
    }


    }

     

     

     

     

     

    am doing my final project on gps based warning system for fishermen, and i want to receive gps data into my controller and exctract only the longitudanal and latitudanal data, and then i have to compare it with my previously stored boundaries and make nececsary outputs by comaparing, In my program i could exctract only the longitudanal and latitudanal data , and stored them as character strings. This worked fine and i checked using pic simulator i gave the sentence $GPGGA,100156.000,2650.9416,N,07547.8441,E,1,08,1. 0,442.8,M,-42.5,M,,0000*71 to the hardware UART simulation interface and it correctly worked.I am using MPLAB IDE V8.83 and now i want to convert this character string in to numerics in order to compare with my boundaries. i hv no idea how to do this and compare with boundaries.. It would be grateful if u can help me on this or give any support 


    Thank you

     

    July 25, 2012 at 5:37 pm #8331
    AJISH ALFRED
    Participant

    Hi Chalani,

    So you need to convert the string to intger value, right?

    Here is a simple code for string to intger conversion. Please refer it, and apply in your code.

    I’m not sure the atoi() will work on your compiler.

     

    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    int main() {
      int i;
      i = atoi("100");                  // HERE IS THE CONVERSION
      printf("The integer value is: %d", i);
      getch();
      return 0;
    }

     

    Try and update the result

    July 26, 2012 at 4:04 pm #8334
    chalani
    Participant

    hi ajish,

     

    thnak you so much, for your kind consideration on my problem. yes its work fine on my compiler..

    thnk you again

     

    regards 

    chalani

     

     

     

    July 27, 2012 at 2:23 pm #8344
    AJISH ALFRED
    Participant

     

    You are welcome. If you face any further issues regarding your project, just update here.

    All the best

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Fixing board, Easy question HEX SCHMITT July 9, 2025
  • Can I make two inputs from one?? July 9, 2025
  • The Analog Gods Hate Me July 9, 2025
  • How to make string LEDs? July 9, 2025
  • It's Amazing What A Buck And A Quarter.... July 8, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise