Bernard jackson
Newbie level 4
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
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