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 / Topics / problem with program of ATmega16 for sms based device control

problem with program of ATmega16 for sms based device control

|

Microcontroller › AVR › problem with program of ATmega16 for sms based device control

  • This topic has 4 replies, 3 voices, and was last updated 12 years ago by Shashank Rao.C.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • May 28, 2013 at 6:35 pm #2451
    Shashank Rao.C
    Participant

    hello friends. I have written a coding for sms based device control using ATmega16. when i try to compile this using avr studio 6 it gives an error and many warnings. i tried my self but no use. i don’t know the program logic is correct or not. please help me.

     coding is as bellow.

    erroe is conflicting type for ‘cmpr_strng’

     

     

     

     

    #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 compr_strng();
     
     
    unsigned int final_result,fresult;
     
    unsigned char msg[10] = “”;
     
    unsigned char on[]=”MTR ON”;
     
    unsigned char off[]=”MTR OFF”;
     
     
     
    int main(void)
    {
    while(1)
     
    {
     
    uart_init();                    // initialize UART port.
     
     
    usart_putch(“ATrn”);          // Sent AT into USART.
     
    _delay_ms(10000);
     
    usart_putch(“AT+CMGF=1rn”);   //Select message mode in text mode.
     
    _delay_ms(1000);
     
    usart_putch(“AT+CPMS=’SM’rn”); // Select the message memory.
     
    _delay_ms(1000);
     
    usart_putch(“AT+CMGR=1rn”);   // Read the message from index 1.
     
    usart_getch(msg[10]);
     
    compr_strng();
     
    final_result=fresult;
     
    if(final_result==0)
     
    {
     
    PORTC=0x01;
     
    usart_putch(“ATrn”);          // Sent AT into USART.
     
    _delay_ms(10000);
     
    usart_putch(“AT+CMGF=1rn”);   //Select message mode in text mode.
     
    _delay_ms(1000);
     
    usart_putch(“AT+CPMS=’SM’rn”); // Select the message memory.
     
    _delay_ms(1000);
     
    usart_putch(“AT+CMGS=+918197103408rn”);   // SEND the message.
     
    usart_putch(“MOTER IS ON.”);
     
    init_LCD();
     
    LCD_write(“MOTOR IS ON.”);
     
    }
     
    if(final_result==1)
     
    {
     
    PORTC=0x00;
     
    usart_putch(“ATrn”);          // Sent AT into USART.
     
    _delay_ms(10000);
     
    usart_putch(“AT+CMGF=1rn”);   //Select message mode in text mode.
     
    _delay_ms(1000);
     
    usart_putch(“AT+CPMS=’SM’rn”); // Select the message memory.
     
    _delay_ms(1000);
     
    usart_putch(“AT+CMGS=+918197103408rn”);   // SEND the message.
     
    usart_putch(“MOTER IS OFF.”);
     
    init_LCD();
     
    LCD_write(“MOTER IS OFF.”);
     
    }
     
    }
     
    }
     
     
     
    void init_LCD(void)              //Function to initialize LCD.
     
    {
     
    LCD_cmd(0x38);
     
     
    _delay_ms(1);
    // initialization of 16X2 LCD in 8bit mode.
     
    LCD_cmd(0x01); // clear LCD
     
    _delay_ms(1);
     
    LCD_cmd(0x0E); // cursor ON
     
    _delay_ms(1);
     
    LCD_cmd(0x80);  // FIRST ROW 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 AND STORE ADDRESS 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_putch(unsigned char send)
     
    {
     
    while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready.
     
    // for more data to be written to it
     
    UDR = send; // Send the byte
     
    }
     
     
     
     
    unsigned int usart_getch()
     
    {
     
    while ((UCSRA & (1 << RXC)) == 0);
    // Do nothing until data have beenMreceived and is ready to be read from UDR
     
    return(UDR); // return the byte
     
    }
     
     
     
     
     
    int compr_strng()            // Function to string comparison.
     
    {
     
    {
     
    char on[10],off[10], msg[10], 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;
     
    }
     
    }
    May 28, 2013 at 8:58 pm #9850
    Sagar
    Participant

    hi shashank.

    i think you moved from your previous thread to hear.

    any how.

    the function prototype for compr_strng() function your wrote is

    void compr_strng();

    however your function defination is

    /**********************************************/

    int compr_strng()          // Function to string comparison.
    {
        char on[10],off[10], msg[10], 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;
    }

    /************************************************/

     

    “void” and “int” return type.

    i went through code and found you are using multiple function for string comparision compare_string1 and compare_string2 (also finction prototype for these function is not defined), i don’t know for what reason you are doing so. both functions looks similar. i don’t think you wrote this code.

    in function main you are calling undefined function uart_init. may be u miss typed it.(usart_init()).

    you are passing pointer to string to function usart_putch() which accepts single charecter. so bascically you are passing address which then  turns character (maps between 0 to 255).

    i think first you need to study on some terminal how formatted data is received from GSM modem.

    May 29, 2013 at 4:10 am #9855
    Shashank Rao.C
    Participant

    yes sagar bhai… for string compar i didnt wrote that code, i got it from net itself. i understood it and modified it. most of the code are collected from this site only and arranged it.

     

    i have another quetion.

    function usart_getch() is reciving only one byte at a time. to recive  a string what i have to do?

    May 29, 2013 at 4:28 am #9856
    AJISH ALFRED
    Participant

    Hi Shashank,

    Your usart module cam get one byte at a time. To get the complete string you can store the bytes in an array as soon as you receive it.

    May 29, 2013 at 6:36 am #9858
    Shashank Rao.C
    Participant

    will this code work for it? i have not tried this. and not compiled also. please tell me any modification?

     

     

     

    #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();

    unsigned char msg[] = “”;

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

    usart_get_string(msg[]);
    _delay_ms(1000);
    LCD_write_string(msg[]);
    }
    }

    void init_LCD(void)              //Function to initialize LCD.
    {
    LCD_cmd(0x38);
    _delay_ms(1);
    // initialization of 16X2 LCD in 8bit mode
    LCD_cmd(0x01); // clear LCD
    _delay_ms(1);
    LCD_cmd(0x0E); // cursor ON
    _delay_ms(1);
    LCD_cmd(0x80);    //first line 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_putch(unsigned char send)                  
    {
    while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
    // for more data to be written to it
    UDR = send; // Send the byte
    }

    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
    }

     usart_get_string(unsigned char msg[])    //To recive a String
    {
        unsigned char i=0;
        for(i=0;msg
    !=’’;i++)
        usart_getch(msg
    );
    }

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Can I make two inputs from one?? June 21, 2025
  • Beats Solo 4 June 21, 2025
  • Behlke swich June 21, 2025
  • Is AI making embedded software developers more productive? June 21, 2025
  • Simple LED Analog Clock Idea June 21, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 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