EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / Hi NK,             I have

Hi NK,             I have

|

Microcontroller › AVR › gsm based water pump controller using atmega16 › Hi NK,             I have

June 6, 2013 at 10:13 am #9898
Shashank Rao.C
Participant

Hi NK,

             I have written a code for this purpose. Actually these code were collected and rearrange from this site only. I have done small changes.

 

i have not tried this. can you please check this? Please tell me any any modifications are needed or not.

 

 

#define F_CPU 12000000UL      // set CPU freq.
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) – 1)
#include<avr/io.h>
#include<util/delay.h>

#define LCD_DATA PORTA    // LCD DATA PORT.
#define  ctrl PORTB       // CONTROL PORT FOR LCD.
#define en PB2            // ENABLE SINGNAL FOR LCD.
#define rw PB1            // READ/WRITE SIGNAL FOR LCD.
#define rs PB0            // REGISTER SELECTION SIGNAL FOR LCD.
#define MOTOR_CONTROL PORTC // MOTOR CONTROL PORT.

void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);

void usart_init();
void usart_putch(unsigned char send);
unsigned int usart_getch();
void compare_string();

unsigned int final_result;
unsigned char msg[] = “”;
unsigned char on[]=”MTR ON”;
unsigned char off[]=”MTR OFF”;

int main(void);
{
while(1)
{
uart_init();                    // initialize UART port.

usart_message(“ATrn”);          // Sent AT into USART.
_delay_ms(10000);
usart_message(“AT+CMGF=1rn”);   //Select mesage mode in text mode.
_delay_ms(1000);
usart_message(“AT+CPMS=’SM’rn”); // Select the mesage memory.
_delay_ms(1000);
usart_message(“AT+CMGR=1rn”);   // Read the message from index 1.
usart_getch(msg[]);
compare_string();
final_result=fresult;
if(final_result==0)
{
PORTC=0x01;
        usart_message(“ATrn”);          // Sent AT into USART.
       _delay_ms(10000);
        usart_message(“AT+CMGF=1rn”);   //Select mesage mode in text mode.
       _delay_ms(1000);
        usart_message(“AT+CPMS=’SM’rn”); // Select the mesage memory.
       _delay_ms(1000);
        usart_message(“AT+CMGS=+918197103408rn”);   // SEND the message.
        usart_message(“MOTER IS ON.”);
        init_LCD();
        LCD_write(“MOTOR IS ON.”);
         }
if(final_result==1)
{
PORTC=0x00;
        usart_message(“ATrn”);          // Sent AT into USART.
       _delay_ms(10000);
        usart_message(“AT+CMGF=1rn”);   //Select mesage mode in text mode.
       _delay_ms(1000);
        usart_message(“AT+CPMS=’SM’rn”); // Select the mesage memory.
       _delay_ms(1000);
        usart_message(“AT+CMGS=+918197103408rn”);   // SEND the message.
        usart_message(“MOTER IS OFF.”);
        init_LCD();
        LCD_write(“MOTER IS OFF.”);
         }
}
}

LCD_write(“MOTER IS OFF.”);
void init_LCD(void)              //Function to initialize LCD.
{
LCD_cmd(0x38);
mode
_delay_ms(1);
// initialization of 16X2 LCD in 8bit
LCD_cmd(0x01); // clear LCD
_delay_ms(1);
LCD_cmd(0x0E); // cursor ON
_delay_ms(1);
LCD_cmd(0x80);
0th position
_delay_ms(1);
return;
}

void LCD_cmd(unsigned char cmd)           //Function to LCD command.
{
LCD_DATA=cmd;
ctrl =(0<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl =(0<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return;
}

void LCD_write(unsigned char data)            //Function to write a letter in LCD.
{
LCD_DATA= data;
ctrl = (1<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl = (1<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return ;
}

void LCD_write_string(unsigned char *str)         //Function to write a string in LCD.
value of the string in pointer *str
{
int i=0;
while(str!=’’)
go on till the NULL character in the string
{
LCD_write(str
);
sending data on LCD byte by byte
i++;
}
return;

void usart_init()                                // Function to initialize USART.
{
UCSRB |= (1 << RXEN) | (1 << TXEN);
// Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 <<
UCSZ1);
// Use 8-bit character sizes
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate
value..
// into the low byte of
the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the
baud rate value..
// into
the high byte of the UBRR register
}

void usart_message(unsigned char *var) // transmits ASCII string
{
int h;
while(*var)
usart_putch(*var++);
for(h=0;h<=200;h++); //sends characters one by one till string ends
}

unsigned int usart_getch()
{
while ((UCSRA & (1 << RXC)) == 0);
// Do nothing until data have been
received and is ready to be read from UDR
return(UDR); // return the byte
}

 
int compare_string();              // Function to string comparition.
{
 
{
    char on[],off[], msg[], result,fresult;
 
    
    result = compare_string1(on, msg);
     if(result==0)
     {
     fresult=1;
     return fresult;
     }

     result = compare_string2(off,msg);

    if ( result == 0 )
      {
          fresult=0;
          return fresult;
      }
}
        
   
 
int compare_string1(char *on, char *msg)
{
   while(*on==*msg)
   {
      if ( *on == ‘’ || *msg == ‘’ )
         break;
 
      on++;
      msg++;
   }
   if( *on == ‘’ && *msg == ‘’ )
      return 0;
   else
      return -1;
}

int compare_string2(char *off, char *msg)
{
   while(*off==*msg)
   {
      if ( *off == ‘’ || *msg == ‘’ )
         break;
 
      off++;
      msg++;
   }
   if( *off == ‘’ && *msg == ‘’ )
      return 0;
   else
      return -1;
}
}

 

RSS Recent Posts

  • SDCC Array Access In Timer 0 Interrupt Handler April 14, 2026
  • Voltage comparator circuit verification April 13, 2026
  • EasyEda program has a major bug April 13, 2026
  • Chatter April 13, 2026
  • understanding transmission line properties from TDR plot April 13, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise