Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Interface GSM modem with PIC16F877A and send sms from PIC16F877A to GSM MODEM

Status
Not open for further replies.

Bernard jackson

Newbie level 4
Joined
Feb 10, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Tanzania
Activity points
1,366
Hi.. hope all you doing great.
I have tried to write the code to interface microcontroller pic16f877a with simcom300, but the program did not work, when i compile then the following error occur , please help me to solve that problem.

mycode:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

#include <htc.h>
#include "Library.h"
#include "LibraryUART.h"
_CONFIG(FOSC_HS & //External Crystal at High Speed
WDTE_OFF & //Disable Watchdog Timer
PWRTE_ON & //Enable Power Up Timer
BOREN_OFF & //Disable Brown Out Reset
MCLRE_ON & //MCLR function is enabled
LVP_OFF ); //Disable Low Voltage Programming

//#define _XTAL_FREQ 20000000

void pic_init()
{
char *rec[]={"+CMTI"};
unsigned int counter[];
TRISA=1;
TRISB=0;
TRISC=1;
TRISD=0;
//ANSEL = 0;
//ANSELH = 0;
OPTION_REG=1;
INTCON=11110000;
PIE1=10010000; //Enable RX interrupt
PORTA=10001000;
PORTB=10000000;
PORTC=10000000;
PORTD=10000000;
}

static void interrupt_isr(void)
{
char z; int counter[];
if(RCIF==1){
*counter[0]= 0;
*gsm[z]=RCREG;
if(z<88)
z++;
}
if(TMR0IF==1)
{
TMR0IF=0;
if(counter[0]<20000)
counter[0]++;
//if(counter[0]== 5000)
z=0;
}
}

void main()
{
unsigned char mode = 0;
int i,j;
Pic_Init(); //initialize PIC
UART_Init(9600);
UART_Write_Text("start"); //initialize UART
Lcd_Init(); //initialize LCD
Lcd_goto(0,0); //select first line
Lcd_String(" GSM MODEM EX "); //display string
Lcd_goto(0,1); //select second line
Lcd_String(" "); //display string
Delay_ms(5000);
mode=0;
counter[1]=0;
for(;;){
counter[1]++;

switch(mode){
case 0:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CGMI "); //display string
UART_String("AT+CGMI"); //Manufacturer identification
UART_Transmit(0x0D);
} //Enter
else if(counter[1] == 3000){
counter[1]=0;
mode++;}

Lcd_goto(0,1); //select second line
for(i=0;i<=15;i++)
Lcd_Write(gsm);
break;
}
case 1:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CGMM "); //display string
UART_String("AT+CGMM"); //Model identification
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
for(i=0;i<=15;i++)
Lcd_Write(gsm);
break;
}
case 2:{
if(counter[1]==1)
{
for(i=0;i<=89;i++) gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CGMR "); //display string
UART_String("AT+CGMR"); //Software version
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
for(i=0;i<=15;i++)
Lcd_Write(gsm);
break;
}
case 3:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_string("AT+CGSN "); //display string
UART_String("AT+CGSN"); //IMEI number
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
for(i=0;i<=15;i++)
Lcd_write(gsm);
break;
}
case 4:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("ATD "); //display string
UART_String("ATD+255682006300;"); //Calling
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==10000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
Lcd_String("CALLING "); //display string
break;
}
case 5:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("ATH "); //display string
UART_String("ATH"); //Hang Up
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000){
counter[1]=0;
mode++;}

Lcd_goto(0,1); //select second line
Lcd_String("HANG UP "); //display string
break;
}
case 6:{
if(counter[1]==1)
{
for(i=0;i<=89;i++) gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CMGF=1 "); //display string
UART_String("AT+CMGF=1"); //Set text mode
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
Lcd_String("TEXT MODE "); //display string
break;
}
case 7:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CMGS "); //display string
UART_String("AT+CMGS="); //Send message
UART_Transmit(0x22); //"
UART_String("+255682006300"); //Phone no
UART_Transmit(0x22); //"
UART_Transmit(0x0D); //Enter
UART_String("Hi, I'm PIC16F877A"); //Text message
UART_Transmit(0x0D); //Enter
UART_String("Reply, if you receive this message");
UART_Transmit(0x1A);
} //Ctrl+Z
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
Lcd_String("SENT MESSAGE "); //display string
break;
}
case 8:{
if(counter[1]==1)
{
for(i=0;i<=89;i++) gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("WAITING REPLY ");
} //display string

Lcd_goto(0,1); //select second line
Lcd_String(" "); //display string

j=0;
for(i=0;i<=4;i++)
{
if(gsm[i+2]==rec) j++;
}
if(j==5) mode++;
break;
}
case 9:{
Lcd_goto(0,0); //select first line
Lcd_String("MESSAGE RECEIVE "); //display string
Lcd_goto(0,1); //select second line
Lcd_String("BERNARD.COM"); //display string
break;
}
}
}

}
Errors found:

0 304 C:/Users/Eng.Bernard JM/Desktop/PIC Exercise/GSM modem.c:19: error: Can't open include file "htc.h"
0 304 #include <htc.h>
0 304 C:/Users/Eng.Bernard JM/Desktop/PIC Exercise/GSM modem.c:20: error: Can't open include file "library.h"
0 304 #include "Library.h"
0 304 C:/Users/Eng.Bernard JM/Desktop/PIC Exercise/GSM modem.c:21: error: Can't open include file "libraryuart.h"
0 304 #include "LibraryUART.h"
0 304 3 errors in preprocessor.
0 102 Finished (with errors): 05 Mar 2012, 15:31:13 GSM modem.mcppi
 

Bernard jackson

Newbie level 4
Joined
Feb 10, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Tanzania
Activity points
1,366
yes have already installed Hi Tech compiler, and is the one i use for compiling my code. but the problem still occur ,
Can you check my code please and tell me where I'm wrong.
this is for my final project to fullfilled my bsc. degree.
 

cristianp

Full Member level 2
Joined
Jul 4, 2006
Messages
142
Helped
31
Reputation
62
Reaction score
21
Trophy points
1,298
Location
Bucharest, Romania
Activity points
1,910
The following defines not work in Hi Tech:



Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections


Use a syntax like
Code:
#define LCD_RS PORTBbits.RB4;
for all code above
 

pratyusha m

Newbie level 3
Joined
Apr 21, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
Hi.. hope all you doing great.
I have tried to write the code to interface microcontroller pic16f877a with simcom300, but the program did not work, when i compile then the following error occur , please help me to solve that problem.

mycode:
// LCD module connections
sbit LCD_RS at RB4_bit; // It should be #define LCD_RS PORTB.4
sbit LCD_EN at RB5_bit;// same thing
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;// this should be -> #define LCD_RS_direction TRISB.4
sbit LCD_EN_Direction at TRISB5_bit;//same thing
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

#include <htc.h>
#include "Library.h" // #include<16f877a.h> to be added
#include "LibraryUART.h" // you dont have to use it if you use -> #USE RS232(baud=9600,xmit=C.6,rcv=c.7,parity=N,stream=GSM,bits=8)
_CONFIG(FOSC_HS & //External Crystal at High Speed
WDTE_OFF & //Disable Watchdog Timer
PWRTE_ON & //Enable Power Up Timer
BOREN_OFF & //Disable Brown Out Reset
MCLRE_ON & //MCLR function is enabled
LVP_OFF ); //Disable Low Voltage Programming

//#define _XTAL_FREQ 20000000

void pic_init()
{
char *rec[]={"+CMTI"};
unsigned int counter[];
TRISA=1;
TRISB=0;
TRISC=1;
TRISD=0;
//ANSEL = 0;
//ANSELH = 0;
OPTION_REG=1;
INTCON=11110000;
PIE1=10010000; //Enable RX interrupt
PORTA=10001000;
PORTB=10000000;
PORTC=10000000;
PORTD=10000000;
}

static void interrupt_isr(void)
{
char z; int counter[];
if(RCIF==1){
*counter[0]= 0;
*gsm[z]=RCREG;
if(z<88)
z++;
}
if(TMR0IF==1)
{
TMR0IF=0;
if(counter[0]<20000)
counter[0]++;
//if(counter[0]== 5000)
z=0;
}
}

void main()
{
unsigned char mode = 0;
int i,j;
Pic_Init(); //initialize PIC
UART_Init(9600);
UART_Write_Text("start"); //initialize UART
Lcd_Init(); //initialize LCD
Lcd_goto(0,0); //select first line
Lcd_String(" GSM MODEM EX "); //display string
Lcd_goto(0,1); //select second line
Lcd_String(" "); //display string
Delay_ms(5000);
mode=0;
counter[1]=0;
for(;;){
counter[1]++;

switch(mode){
case 0:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CGMI "); //display string
UART_String("AT+CGMI"); //Manufacturer identification
UART_Transmit(0x0D);
} //Enter
else if(counter[1] == 3000){
counter[1]=0;
mode++;}

Lcd_goto(0,1); //select second line
for(i=0;i<=15;i++)
Lcd_Write(gsm);
break;
}
case 1:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CGMM "); //display string
UART_String("AT+CGMM"); //Model identification
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
for(i=0;i<=15;i++)
Lcd_Write(gsm);
break;
}
case 2:{
if(counter[1]==1)
{
for(i=0;i<=89;i++) gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CGMR "); //display string
UART_String("AT+CGMR"); //Software version
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
for(i=0;i<=15;i++)
Lcd_Write(gsm);
break;
}
case 3:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_string("AT+CGSN "); //display string
UART_String("AT+CGSN"); //IMEI number
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
for(i=0;i<=15;i++)
Lcd_write(gsm);
break;
}
case 4:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("ATD "); //display string
UART_String("ATD+255682006300;"); //Calling
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==10000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
Lcd_String("CALLING "); //display string
break;
}
case 5:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("ATH "); //display string
UART_String("ATH"); //Hang Up
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000){
counter[1]=0;
mode++;}

Lcd_goto(0,1); //select second line
Lcd_String("HANG UP "); //display string
break;
}
case 6:{
if(counter[1]==1)
{
for(i=0;i<=89;i++) gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CMGF=1 "); //display string
UART_String("AT+CMGF=1"); //Set text mode
UART_Transmit(0x0D);
} //Enter
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
Lcd_String("TEXT MODE "); //display string
break;
}
case 7:{
if(counter[1]==1)
{
for(i=0;i<=89;i++)
gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("AT+CMGS "); //display string
UART_String("AT+CMGS="); //Send message
UART_Transmit(0x22); //"
UART_String("+255682006300"); //Phone no
UART_Transmit(0x22); //"
UART_Transmit(0x0D); //Enter
UART_String("Hi, I'm PIC16F877A"); //Text message
UART_Transmit(0x0D); //Enter
UART_String("Reply, if you receive this message");
UART_Transmit(0x1A);
} //Ctrl+Z
else if(counter[1]==3000)
{
counter[1]=0;
mode++;
}

Lcd_goto(0,1); //select second line
Lcd_String("SENT MESSAGE "); //display string
break;
}
case 8:{
if(counter[1]==1)
{
for(i=0;i<=89;i++) gsm=0x20;
Lcd_goto(0,0); //select first line
Lcd_String("WAITING REPLY ");
} //display string

Lcd_goto(0,1); //select second line
Lcd_String(" "); //display string

j=0;
for(i=0;i<=4;i++)
{
if(gsm[i+2]==rec) j++;
}
if(j==5) mode++;
break;
}
case 9:{
Lcd_goto(0,0); //select first line
Lcd_String("MESSAGE RECEIVE "); //display string
Lcd_goto(0,1); //select second line
Lcd_String("BERNARD.COM"); //display string
break;
}
}
}

}
Errors found:

0 304 C:/Users/Eng.Bernard JM/Desktop/PIC Exercise/GSM modem.c:19: error: Can't open include file "htc.h"
0 304 #include <htc.h>
0 304 C:/Users/Eng.Bernard JM/Desktop/PIC Exercise/GSM modem.c:20: error: Can't open include file "library.h"
0 304 #include "Library.h"
0 304 C:/Users/Eng.Bernard JM/Desktop/PIC Exercise/GSM modem.c:21: error: Can't open include file "libraryuart.h"
0 304 #include "LibraryUART.h"
0 304 3 errors in preprocessor.
0 102 Finished (with errors): 05 Mar 2012, 15:31:13 GSM modem.mcppi


Been working on a similar project ,anyways that's that.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top