Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

serial communication with pic 16f877a

Status
Not open for further replies.

chalani0088

Junior Member level 3
Junior Member level 3
Joined
Jun 19, 2012
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,562
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?
 

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.
 
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?
 

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?
 

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...........
 

Attachments

  • Serial_Rx_LCD.txt
    1.4 KB · Views: 146
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
 
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 - - -

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 - - -

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?
 

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;
}
 

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;
 
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++);
}
}
 

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...
 
i got the output in GSM modem.

- - - Updated - - -

thanks for your help.
 

yes i got the output its working...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top