/ 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 LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at 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 operation
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 = 0x02; // Configure AN1 pin as analog
ANSELH = 0; // Configure other AN pins as digital I/O
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISB = 0; // PORTB as output port
TRISD = 0; // PORTD as output port
TRISC = 0; // PORTC as output port
TRISA = 0X07; // PORTA as the input/output 0000 0111
UART1_Init(9615); // Initialize Soft UART module at 9600 bps
Move_Delay(); // Wait for UART module to stabilize
Lcd_Init(); // Initialize LCD connected to PORTB
Lcd_Cmd(_LCD_CLEAR); // clear Display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 1, text4); // "transformer at" text
Lcd_Out(1, 1, text5); // display safe operation on lcd
do
{
read_value = ADC_Read(1); // Get 10-bit results of AD conversion
PORTD = read_value; // Send lower 8 bits to PORTB
if(read_value > THRESHOLD ) // if true mean abnormal operation
{
if(change == 0)
{
writeWarning(); // call function to display warning on lcd and send sms to GSM
//gsm_SMS_Init(); // initialize gsm modem
//pic_Send_SMS(); //send an sms
//Read_SMS();
change = 1;
}
}
else // safe
{
if(change == 1) // if the previous condition is exit i.e unsafe operation
{
writeNormal(); // call function to display safe operation on lcd
change = 0; // set to safe operation
}
}
} while(1);
}
void writeWarning()
{
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // clear Display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1,1,text1);
Lcd_Out(2, 1, text2); // Print text to LCD, first row
Lcd_Out(3, 1, text3); // Print text1 to LCD 3rd row
}
void writeNormal()
{
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // clear Display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1,1, text4 ); // text to display
Lcd_Out(1, 1, text5); // display normal operation on lcd
}
void Move_Delay() // function used for text delay
{
Delay_ms(500); // 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(); //to read the sms in location 1
UART1_Write_Text("AT+CSMS= 1"); // SMS AT command
UART1_Write_Text("AT+CGMI= 1"); //gives manufacturer identification
UART1_Write_Text("AT+CMGS= +0682006300"); //Write "AT+CMGS= 1"
UART1_Write(0x0D); // mean (Enter)
Move_Delay(); // Delay
UART1_Write_Text("AT+CMGW= 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);
}