+ Post New Thread
Results 1 to 17 of 17
  1. #1
    Junior Member level 3
    Points: 1,045, Level: 7

    Join Date
    Jun 2012
    Posts
    27
    Helped
    0 / 0
    Points
    1,045
    Level
    7

    serial communication with pic 16f877a

    Hi,

    I want to do a serial communication with pic 16f877a mc and my gps module. Gps module has rx tx pins and has a ttl output. I have written a program using hitech-C to , process the receiveng nmea sentences from the module and write the putput on a LCD which re longitudanal and latitudanal data.

    I want to connect the GPS module to the microcntroller. I have no idea about how to include programming changes to activate serial port for serial cmmunicating with gps module using Hitech-C, i read the user guide of Hitech-C, but still Im strugling hot to enter the programming codes to make this happen.

    Can anybody please help me on this?

  2. #2
    Advanced Member level 5
    Points: 38,206, Level: 47
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Silicon Valley, California, USA (from Dhaka, Bangladesh)
    Posts
    4,758
    Helped
    1788 / 1788
    Points
    38,206
    Level
    47
    Blog Entries
    22

    Re: serial communication with pic 16f877a

    Since the GPS module has RX and TX pins, you can use the UART module of the PIC16F877A. The PIC168F77A has an on-board hardware UART module. First consult the datasheet to read about it. Then go through Hi-Tech C resources to find out about the UART module functions, routines, etc.

    Hope this helps.
    Tahmid.
    The blissful feeling of helping others is a unique reward that cannot be gotten from anything else.


    1 members found this post helpful.

    •   Alt6th January 2013, 12:52

      advertising

        
       

  3. #3
    Junior Member level 3
    Points: 1,045, Level: 7

    Join Date
    Jun 2012
    Posts
    27
    Helped
    0 / 0
    Points
    1,045
    Level
    7

    Re: serial communication with pic 16f877a

    thanx for your support. I really get confused when reading the PIC 16f877A . For example it has 2 modes, synchronus, asyncronus, what should I realy select? how this should be chosen?



  4. #4
    Advanced Member level 5
    Points: 38,206, Level: 47
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Silicon Valley, California, USA (from Dhaka, Bangladesh)
    Posts
    4,758
    Helped
    1788 / 1788
    Points
    38,206
    Level
    47
    Blog Entries
    22

    Re: serial communication with pic 16f877a

    Use the asynchronous mode. UART is the asynchronous mode, USART is the synchronous mode.
    The blissful feeling of helping others is a unique reward that cannot be gotten from anything else.


    1 members found this post helpful.

  5. #5
    Junior Member level 3
    Points: 1,045, Level: 7

    Join Date
    Jun 2012
    Posts
    27
    Helped
    0 / 0
    Points
    1,045
    Level
    7

    Re: serial communication with pic 16f877a

    Thank you very much for the support

    regards
    chalani

    - - - Updated - - -



    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
    }

    I could setup the serial port like this in my program, now can I connect directly the GPS module to PIC's RX and receive data?



  6. #6
    Full Member level 5
    Points: 1,942, Level: 10

    Join Date
    Apr 2012
    Location
    bangalore
    Posts
    311
    Helped
    44 / 44
    Points
    1,942
    Level
    10

    Re: serial communication with pic 16f877a

    which is the GPS u are using.............

    use this code it will display received data from GPS on LCD.................


    GPS gives lots of data in lots of formats make sure u take those data which are required...........


    1 members found this post helpful.

    •   Alt7th January 2013, 06:13

      advertising

        
       

  7. #7
    Full Member level 1
    Points: 919, Level: 6
    manikandanshine's Avatar
    Join Date
    Aug 2012
    Location
    india
    Posts
    105
    Helped
    8 / 8
    Points
    919
    Level
    6

    Re: serial communication with pic 16f877a

    Quote Originally Posted by chalani0088 View Post
    Thank you very much for the support

    regards
    chalani

    - - - Updated - - -



    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
    }

    I could setup the serial port like this in my program, now can I connect directly the GPS module to PIC's RX and receive data?
    no,microcontroller operates in 5v level and gps operates in 12v level....the devices which is operate in different voltage level,we didnt connect directly between these....one level converter is needed that level converter is max232
    Thanks and Regards,
    MANIKANDANSHINE


    1 members found this post helpful.

  8. #8
    Junior Member level 3
    Points: 1,045, Level: 7

    Join Date
    Jun 2012
    Posts
    27
    Helped
    0 / 0
    Points
    1,045
    Level
    7

    Re: serial communication with pic 16f877a

    I'm Using EM406A SIRF module, Thank You so much for the code, I Just want to extract the longitudanal lattudanal data, but herre in this program i cant recognise wot are the data, RW, EN ports of LCD, How can I recognize them?

    - - - Updated - - -

    Quote Originally Posted by manikandanshine View Post
    no,microcontroller operates in 5v level and gps operates in 12v level....the devices which is operate in different voltage level,we didnt connect directly between these....one level converter is needed that level converter is max232
    Thank you so much for the reply, Here to my project I'm using EM406A GPS module and It outputs TTL level output, So I don't need a level converter to connect with Micro controller right?

    regards
    chalani

    - - - Updated - - -

    Quote Originally Posted by jjeevan007 View Post
    which is the GPS u are using.............

    use this code it will display received data from GPS on LCD.................


    GPS gives lots of data in lots of formats make sure u take those data which are required...........
    Thank You so much for the code,I'm Using EM406A SIRF module, I Just want to extract the longitudanal lattudanal data, but herre in this program i cant recognise wot are the data, RW, EN ports of LCD, How can I recognize them?



    •   Alt7th January 2013, 15:18

      advertising

        
       

  9. #9
    Full Member level 5
    Points: 1,942, Level: 10

    Join Date
    Apr 2012
    Location
    bangalore
    Posts
    311
    Helped
    44 / 44
    Points
    1,942
    Level
    10

    Re: serial communication with pic 16f877a

    PortE 0 - RS
    PortE 1 - R/W
    PortE 2 - En

    and

    Port B are datalines


    1 members found this post helpful.

  10. #10
    Junior Member level 2
    Points: 455, Level: 4

    Join Date
    Aug 2013
    Posts
    20
    Helped
    1 / 1
    Points
    455
    Level
    4

    Re: serial communication with pic 16f877a

    i don't know what's the problem in this code. its compiling good in MPLAB +hitech c but not getting output in proteus please help me guys.
    #include<htc.h>
    #include<pic16f877a.h>

    #include<string.h>
    #include<stdio.h>
    #define _XTAL_FREQ 20e6
    __CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);




    // Comm Setup
    #define BAUDRATE 9600 //bps
    // 8 bit data mode with one stop bit
    // No flow control, no parity bit

    //Function Prototypes
    void InitUART(void);
    void SendByteSerially(unsigned char);
    void SendStringSerially(const unsigned char*);

    void main(void)
    {
    InitUART(); // Intialize UART

    SendStringSerially("Hello World!"); // Send string on UART



    while(1)
    {
    // Do nothing, as Received character is echoed back in the ISR
    // If you decide to disable interrupts, then you can
    // echo back characters by uncommenting the line below
    // SendByteSerially(ReceiveByteSerially()); //Echo Back
    }
    }


    void InitUART(void)
    {
    TRISC6 = 1; // TX Pin
    TRISC7 = 1; // RX Pin

    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 SendStringSerially(const unsigned char* st)
    {
    while(*st)
    SendByteSerially(*st++);
    }
    void SendByteSerially(unsigned char Byte) // Writes a character to the serial port
    {
    while(!TXIF); // wait for previous transmission to finish
    TXREG = Byte;
    }



  11. #11
    Banned
    Points: 23,048, Level: 36

    Join Date
    Dec 2012
    Location
    Bangalore, India
    Posts
    4,294
    Helped
    826 / 826
    Points
    23,048
    Level
    36

    Re: serial communication with pic 16f877a

    Code C - [expand]
    1
    
    TRISC6 = 0; // TX Pin



  12. #12
    Full Member level 3
    Points: 1,278, Level: 8
    mathespbe's Avatar
    Join Date
    Jul 2013
    Location
    India, Tamilnadu, Coimbatore
    Posts
    186
    Helped
    45 / 45
    Points
    1,278
    Level
    8

    Re: serial communication with pic 16f877a

    Quote Originally Posted by reachrajesh View Post
    i don't know what's the problem in this code. its compiling good in MPLAB +hitech c but not getting output in proteus please help me guys.
    #include<htc.h>
    #include<pic16f877a.h>

    #include<string.h>
    #include<stdio.h>
    #define _XTAL_FREQ 20e6
    __CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);




    // Comm Setup
    #define BAUDRATE 9600 //bps
    // 8 bit data mode with one stop bit
    // No flow control, no parity bit

    //Function Prototypes
    void InitUART(void);
    void SendByteSerially(unsigned char);
    void SendStringSerially(const unsigned char*);

    void main(void)
    {
    InitUART(); // Intialize UART

    SendStringSerially("Hello World!"); // Send string on UART



    while(1)
    {
    // Do nothing, as Received character is echoed back in the ISR
    // If you decide to disable interrupts, then you can
    // echo back characters by uncommenting the line below
    // SendByteSerially(ReceiveByteSerially()); //Echo Back
    }
    }


    void InitUART(void)
    {
    TRISC6 = 1; // TX Pin
    TRISC7 = 1; // RX Pin

    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 SendStringSerially(const unsigned char* st)
    {
    while(*st)
    SendByteSerially(*st++);
    }
    void SendByteSerially(unsigned char Byte) // Writes a character to the serial port
    {
    while(!TXIF); // wait for previous transmission to finish
    TXREG = Byte;
    }
    these lines are not needed...

    TRISC6 = 1; // TX Pin
    TRISC7 = 1; // RX Pin

    and, for 20MHZ Fosc, 9600 BR with high speed mode SPBRG = 0x129;


    1 members found this post helpful.

  13. #13
    Junior Member level 2
    Points: 455, Level: 4

    Join Date
    Aug 2013
    Posts
    20
    Helped
    1 / 1
    Points
    455
    Level
    4

    Re: serial communication with pic 16f877a

    Quote Originally Posted by mathespbe View Post
    these lines are not needed...

    TRISC6 = 1; // TX Pin
    TRISC7 = 1; // RX Pin

    and, for 20MHZ Fosc, 9600 BR with high speed mode SPBRG = 0x129;
    if i connect to this serial communication to the gsm receiver + at commands means it will send message to the mobile number?
    the example code below.

    /************************* LPG program in PIC *************************/
    #include<htc.h>
    #include<pic16f877a.h>

    #include<string.h>
    #include<stdio.h>
    #define _XTAL_FREQ 20e6
    __CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);


    #define load PORTB

    #define rs RC0 // lcd register select
    #define rw RC1 // lcd register write
    #define en RC2 // lcd register enable
    #define gas_sensor RC3 // gas sensor input to the microcontroller
    #define msg_format "AT+CMGF=1"
    #define msg_send "AT+CMGS="
    #define number "\"8344598494\""

    //#define message "Book No:1357"
    #define message1 "Gas leakage in ur home"
    void InitUART(void); // serial communication init
    void SendByteSerially(unsigned char); // serial communication data sending
    void SendStringSerially(const unsigned char*); // send byte serially
    void delayms(unsigned int); // delay ms
    void lcd_cmnd(unsigned char); //lcd command
    void lcd_data( char); // lcd indication for data sending
    void lcd_string(const char*); // lcd c0nstant value of string sending
    void lcd_init(void);// lcd init
    void main(void)
    {

    TRISB=0;
    TRISC0=0;
    TRISC1=0;
    TRISC2=0;
    TRISC3=0X00;
    load=0X00;

    TRISC3=1;
    lcd_init();
    // InitUART(); // Intialize UART
    lcd_cmnd(0X80);

    /**************** lcd command initil **********************/
    lcd_cmnd(0X01);
    lcd_cmnd(0X80);
    delayms(10);
    lcd_string("RAJESH");



    while(1)
    {

    if(gas_sensor==1)
    {
    InitUART();
    SendStringSerially(msg_format); // Send string on UART
    SendStringSerially(0X0d);
    SendStringSerially(msg_send); // send string to UART
    SendStringSerially(number); // send string to UART
    SendStringSerially(0X0d);
    delayms(50);
    SendStringSerially(message1);
    SendStringSerially(0X1a);
    delayms(50);

    /*********** lcd init again ****************/
    lcd_init();
    lcd_cmnd(0X01);
    lcd_string("GAS LEAKAGE IN YOUR HOME");
    delayms(100);
    lcd_init();
    lcd_cmnd(0X01);
    lcd_string("MESSAGE SENT ok");
    delayms(10);
    TRISC3=1;
    }


    }
    }

    /***************************** LCD INIT *************************/
    void lcd_init()
    {

    lcd_cmnd(0X38); // configuring LCD as 2 line 5x7 matrix
    lcd_cmnd(0X0C); // Display on, Cursor blinking
    lcd_cmnd(0X01); // Clear Display Screen
    lcd_cmnd(0X06); // Increment Cursor (Right side)
    }

    /************************** serial communication init ********************/

    void InitUART(void)
    {
    // TRISC6 = 1; // TX Pin
    // TRISC7 = 1; // RX Pin

    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
    }

    /********************* serial communication data sending ******************/
    void SendStringSerially(const unsigned char* st)
    {
    while(*st)
    SendByteSerially(*st++);
    }

    /********************** serial data receiving **********************************/
    void SendByteSerially(unsigned char Byte) // Writes a character to the serial port
    {
    while(!TXIF); // wait for previous transmission to finish
    TXREG = Byte;
    }



    /******************************** LCD COMMAND ***************************/
    void lcd_cmnd(unsigned char command)
    {
    load=command;
    rs=0;
    rw=0;
    en=1;
    delayms(1);
    en=0;
    }
    /********************************* LCD STRING **************************/
    void lcd_string(const char *string)
    {
    while(*string)
    {
    lcd_data(*string++);

    }
    }
    /************************************ LCD DATA *************************/
    void lcd_data(char data)
    {

    load=data;
    rs=1;
    rw=0;
    en=1;
    delayms(1);
    en=0;

    }
    /********************************** delay calling ********************/
    void delayms(unsigned int delayms)
    {
    unsigned int i,j;
    for(i=0;i<=delayms;i++)
    {
    for(j=0;j<=500;j++);
    }
    }



    •   Alt28th September 2013, 09:02

      advertising

        
       

  14. #14
    Full Member level 3
    Points: 1,278, Level: 8
    mathespbe's Avatar
    Join Date
    Jul 2013
    Location
    India, Tamilnadu, Coimbatore
    Posts
    186
    Helped
    45 / 45
    Points
    1,278
    Level
    8

    Re: serial communication with pic 16f877a

    Quote Originally Posted by reachrajesh View Post
    if i connect to this serial communication to the gsm receiver + at commands means it will send message to the mobile number?
    for each comment you are sending, you should check the response. First you check the GSM response from terminal and monitor it. After you get all the possible responses of GSM module, you can try your code on mc...


    1 members found this post helpful.

  15. #15
    Junior Member level 2
    Points: 455, Level: 4

    Join Date
    Aug 2013
    Posts
    20
    Helped
    1 / 1
    Points
    455
    Level
    4

    Re: serial communication with pic 16f877a

    i got the output in GSM modem.

    - - - Updated - - -

    thanks for your help.



  16. #16
    Full Member level 3
    Points: 1,278, Level: 8
    mathespbe's Avatar
    Join Date
    Jul 2013
    Location
    India, Tamilnadu, Coimbatore
    Posts
    186
    Helped
    45 / 45
    Points
    1,278
    Level
    8

    Re: serial communication with pic 16f877a

    Quote Originally Posted by reachrajesh View Post
    i got the output in GSM modem.

    - - - Updated - - -

    thanks for your help.
    Did you get the GSM to work with your mc with the code you have posted above? or with terminla in PC?



  17. #17
    Junior Member level 2
    Points: 455, Level: 4

    Join Date
    Aug 2013
    Posts
    20
    Helped
    1 / 1
    Points
    455
    Level
    4

    Re: serial communication with pic 16f877a

    yes i got the output its working...



--[[ ]]--