100% found this document useful (2 votes)
113 views

Interfacing GSM Modem To PIC16F877A

This document describes interfacing a GSM modem with a PIC16F877A microcontroller. It includes definitions for connecting an LCD display and GSM modem to specific pins. Functions are defined to initialize the devices, read sensor data, and send SMS messages if the sensor exceeds a threshold. The main loop continuously reads the sensor, displays the status on the LCD, and sends a warning SMS if needed.

Uploaded by

Remigild Peter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
113 views

Interfacing GSM Modem To PIC16F877A

This document describes interfacing a GSM modem with a PIC16F877A microcontroller. It includes definitions for connecting an LCD display and GSM modem to specific pins. Functions are defined to initialize the devices, read sensor data, and send SMS messages if the sensor exceeds a threshold. The main loop continuously reads the sensor, displays the status on the LCD, and sends a warning SMS if needed.

Uploaded by

Remigild Peter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

############interface GSM Modem with PIC16F877A############################

/ LCD connection
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit
sbit
sbit
sbit
sbit
sbit

LCD_RS_Direction
LCD_EN_Direction
LCD_D4_Direction
LCD_D5_Direction
LCD_D6_Direction
LCD_D7_Direction

at
at
at
at
at
at

TRISB2_bit;
TRISB3_bit;
TRISB4_bit;
TRISB5_bit;
TRISB6_bit;
TRISB7_bit;

// Manchester module connections


sbit MANRXPIN at RC6_bit;
sbit MANRXPIN_Direction at TRISC6_bit;
sbit MANTXPIN at RC7_bit;
sbit MANTXPIN_Direction at TRISC7_bit;
// End Manchester module connections
//prototype
//void pic_Send_SMS();
//void Read_SMS(void);
//void gsm_SMS_Init(void);
void writeWarning();
void writeNormal();
void Move_Delay();
//void delay(unsigned long ctr);
void Man_send_init();
//end of prototype
// Declaration start
char output[70] = " LOW OIL LEVEL T4 ILALA ";
unsigned int *counter, i;
char return_gsm[2];
char Gsm_Receive[50];
char Gsm_Msg[100];
unsigned int THRESHOLD = 0xCd;
unsigned int read_value = 0;
char index, character;
char *set[] = " LOW OIL LEVEL T4 ILALA ";
char *text1 = " !! WARNING !!";
char *text2 = " LOW OIL LEVEL ";
char *text3 = " T4 ILALA_EAST ";
char *text5 = " SAFE OPERATION ";
char *text4 = " TRANSFORMER AT ";
//char *COMError = " Initialization error";
char *sms = " LOW OIL LEVEL T4 ILALA_EAST ";
int change = 0;
// change is 0 for safe operation and 1 for unsafe ope
ration
int ANSEL, ANSELH, C1ON_bit, C2ON_bit;
char USART_rd[] = "AT";
char USART_rd1[]= "AT+CMGF=1";
char USART_rd2[]= "AT+CMGR=1";
char USART_rd3[]= "AT+CMGS= 1";

// End of declaration part


void main()
{
// pic16f877A
ANSEL =
ANSELH =
C1ON_bit
C2ON_bit

0x02;
0;
= 0;
= 0;

TRISB = 0;
TRISD = 0;
TRISC = 0;
TRISA = 0X07;
UART1_Init(9615);
Move_Delay();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 1, text4);
Lcd_Out(1, 1, text5);

// Configure AN1 pin as analog


// Configure other AN pins as digital I/O
// Disable comparators
// PORTB as output port
// PORTD as output port
// PORTC as output port
// PORTA as the input/output 0000 0111
// Initialize Soft UART module at 9600 bps
// Wait for UART module to stabilize
// Initialize LCD connected to PORTB
// clear Display
// Turn cursor off
// "transformer at" text
// display safe operation on lcd

do
{
read_value = ADC_Read(1);
PORTD = read_value;
if(read_value > THRESHOLD )
on
{
if(change == 0)
{
writeWarning();
n lcd and send sms to GSM
//gsm_SMS_Init();
//pic_Send_SMS();
//Read_SMS();

// Get 10-bit results of AD conversion


// Send lower 8 bits to PORTB
// if true mean abnormal operati

// call function to display warning o


// initialize gsm modem
//send an sms

change = 1;
}
}
else

// safe

{
if(change == 1)
fe operation
{
writeNormal();
change = 0;
}
}
} while(1);
}
void writeWarning()
{
Lcd_Init();

// if the previous condition is exit i.e unsa

// call function to display safe operation on lcd


// set to safe operation

Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,text1);
Lcd_Out(2, 1, text2);
Lcd_Out(3, 1, text3);

// clear Display
// Turn cursor off

}
void writeNormal()
{
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1, text4 );
Lcd_Out(1, 1, text5);

// Print text to LCD, first row


// Print text1 to LCD 3rd row

// clear Display
// Turn cursor off
// text to display
// display normal operation on lcd

}
void Move_Delay()
{
Delay_ms(500);
}

// function used for text delay


// delay for half a second

void Read_SMS(void)
{
pic_Send_SMS();
// send text
UART1_Write_Text("AT+CGMM= 1");
// GET supported frequency band
UART1_Write_Text("AT");
// send AT to the GSM
//Move_Delay();
// Delay
UART1_Write_Text("AT+CMGF=1 ");
// sms configuration /SET TEXT MODE
//Move_Delay();
UART1_Write_Text("AT+CNMA= 1");
//ACKNOWLEDGE NEW SMS
UART1_Write_Text("AT+CMGR= 1\n\r");
UART1_Write_Text("AT+CGMR= 1\n\r");
// request revision identification
//Move_Delay();
UART1_Write_Text("AT+CPMS= output");
// store from the ram (BM)
UART1_Write_Text("AT+CMGL= 1");
//list message
UART1_Write_Text("AT+CMGR= 1\n\r");
// Read message
//Move_Delay();
UART1_Write_Text("AT+CPMS= output");
// read from the ram (BM)
while (UART1_Data_Ready() == 0) ;
for(i=0;i<=65;i++)
{
output[i]=UART1_Read();
}
}
void pic_Send_SMS()
{
do
{
//gsm_SMS_Init();
//Read_SMS();
UART1_Write_Text("AT+CSMS=
UART1_Write_Text("AT+CGMI=
ion
UART1_Write_Text("AT+CMGS=
UART1_Write(0x0D);
Move_Delay();
UART1_Write_Text("AT+CMGW=

1");
1");

//to read the sms in location 1


// SMS AT command
//gives manufacturer identificat

+0682006300");
//Write "AT+CMGS= 1"
// mean (Enter)
// Delay
1");
// WRITE message

UART1_Write_Text("AT+CMSS= 1");
//SEND MESSAGE
//UART1_Write_Text("AT+CMGS= ");
//Write "AT+CMGS="
UART1_Write(0x22);
UART1_Write_Text("AT = +255682006300"); // Phone Number SMS send to
UART1_Write(0x22);
UART1_Write(0x0D);
// mean (ENTER)
UART1_Write_Text("\n\r");
Move_Delay();
// Delay
UART1_Write_Text(output);
// Word to be sent
UART1_Write(26);
// send ctrl + Z
Move_Delay();
// Delay
}
while(1);
}

You might also like