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.

Not able to communicate with gsm module from controller pic16f877a

Status
Not open for further replies.
your problem is placing the TX,RX,GROUND in GSM board. you have to connect these pin from micro controller to directly max rs 232 in GSM modem just check and tell.
 
your problem is placing the TX,RX,GROUND in GSM board. you have to connect these pin from micro controller to directly max rs 232 in GSM modem just check and tell.

#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 BAUDRATE 9600
#define load PORTB
#define rs RC0 // lcd register select
#define rw RC1 // lcd register write
#define en RC2 // lcd register enable
#define swit RD0 // gas sensor input to the microcontroller
#define msg_init "AT\r"
#define msg_format "AT+CMGF=1\r"
#define msg_send "AT+CMGS="
#define number "9578671198" // ashok number
#define message1 "\rGSM CHECKING\r"
void InitUART(void); // serial communication init
void SendByteSerially(unsigned char); // serial communication data sending
unsigned char UART_Read(void);
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 interrupt ISR(void);
void sms_modem(void);
unsigned int value;
unsigned char uart_rd[20], k = 0, m = 0;
void main(void)
{
TRISC = 0x80;
TRISB=0;
TRISC0=0;
TRISC1=0;
TRISC2=0;
TRISC3=0;
TRISD0=0;
swit=0;
load=0X00;
lcd_init();
lcd_cmnd(0X01);
lcd_cmnd(0X80);
lcd_string("Welcome !");
InitUART();// Intialize UART
GIE = 1;
PEIE = 1;
while(1)
{
if(swit==1)
{
// InitUART(); // Intialize UART
sms_modem();


}
}
}
void sms_modem(void)
{
InitUART();

SendStringSerially(msg_init);
SendByteSerially(0X0D);
SendByteSerially(0X0A);
delayms(20);
SendStringSerially(msg_format);
SendByteSerially(0X0D); // Send string on UART
SendByteSerially(0X0A);
delayms(20);
SendStringSerially(msg_send); // send string to UART
SendByteSerially(0X22);
SendStringSerially(number); // send string to UAR
SendByteSerially(0X22);
SendByteSerially(0X0D);
SendByteSerially(0X0A);
delayms(20);
SendStringSerially(message1);
SendByteSerially(0X0D);
SendByteSerially(0X1A);
SendByteSerially(0X0D);
delayms(30);
lcd_init();
lcd_cmnd(0X01);
lcd_cmnd(0X80);
lcd_string("GSM WORKING");

}
/************************************* interrupt declare *********************/
void interrupt ISR(void)
{
if(RCIF)
{
if(OERR)
{
CREN = 0;
CREN = 1;
}

uart_rd[m] = RCREG;

if(uart_rd[m] == '"')
{
k++;
m = 0;

}

if(k == 6)
{

uart_rd[m] = '\0';
k = 0;
m = 0;
}

}
}



/************************** 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
//BRGH = 1; // Fast baudrate
// SYNC = 0; // Asynchronous
SPEN = 1; // Enable serial port pins
CREN = 1; // Enable reception
SREN = 0; // No effect
TXIE = 0; // Disable tx interrupts
RCIE = 1; // Enable rx interrupts
TX9 = 0; // 8-bit transmission
RX9 = 0; // 8-bit reception
TXEN = 0; // Reset transmitter
TXEN = 1; // Enable the transmitter
TRISC = 0x80;
// TXSTA = 0x24;
// RCSTA = 0x90;
}

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


/************************** write from uart **********************/
unsigned char UART_Read(void)
{
if(OERR)
{
CREN = 0;
CREN = 1;
}

while(!RCIF);

return RCREG;
}




/***************************** 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)
}
/******************************** 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++);
}
}
please tell me what is the problem in this code. its not working in hardware working good in proteus..
 

hi brothers i developed some of the basic code for controlling the devices through gsm mobile before that i want to test the working of the given strings in terminal.program is to light the LEDS when given the command #ON and to off the LEDS when given #OFF from terminal .i am checking the received char from terminal again sending back to terminal,here some of received characters are missing.kindly check the code and correct .i am had tried this for the whole night. still confused with the concepts

Code:
//SATHISH
//10/16/13
/* this program is to control the devices through the commands on and off .
this is checked with terminal and has to implement with mobile phone to control with gsm interfaced with pic16f877a
*/
#include<pic.h>
#include<string.h>
#define _XTAL_FREQ 20000000
uart_init();
uart_receive();
uart_transmit();
usart_str(unsigned char *c);
unsigned int a,b;
static unsigned char c[10],d[10],e;
void interrupt isr()
{

}
void main()
{
TRISC=0X80;
TRISB=0X00;

uart_init();

do
{
// FUNCTION TO RECEIVE DATAS FROM UART
uart_receive();
// checking the received datas by sending back to termainal whether all characters are present in the string.
for(a=0;a<4;a++)
{
TXREG=c[a];
while(TRMT==0)
;
__delay_ms(2000);
// CONDITION TO CHECK WHETHER THE GIVEN STRING MATCH OR NOT FOR LIGHTING THE LEDS.
if(strcmp("#on",c)==0)
PORTB=0XF0;
else if (strcmp("#off",c)==0)
PORTB=0X0F;
}

}
while(1);

}
uart_init()
{
SPBRG=129;
BRGH=1;
SYNC=0;
SPEN=1;
TXEN=1;
CREN=1;
//GIE=1;
//PEIE=1;
//RCIE=1;
}
uart_receive()
{
for(a=0;a<3;a++)
{
c[a]=RCREG;
while(RCIF==0)
;
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top