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 receive complete interrupt in AVR studio 4

Problem with receive complete interrupt in AVR studio 4

|

Microcontroller › AVR › Problem with receive complete interrupt in AVR studio 4

  • This topic has 0 replies, 1 voice, and was last updated 14 years, 1 month ago by Dhruwank Vankawala.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • February 27, 2012 at 9:42 am #1628
    Dhruwank Vankawala
    Participant

    Hey, frds

    i am trying to run a code which is related with interfacing of GSM modem with ATMEGA 32.

     

    i have done programming on interupt based…..

     

    Bt incase of interupt service routine i dint come out of that routine ……………..

     

    and the code is not running on both proteus  and  atmega 32 kit………….

     

    Here is the reference code for it……….

     

     

    #include<avr/io.h>

    #ifndef F_CPU
    #define F_CPU 11059200UL    // 11.0592MHz clock speed #endif
    #endif

    #include<util/delay.h>
    #include<avr/interrupt.h>

     

    #define LCD_PRT PORTC
    #define LCD_PIN PINC
    #define LCD_DDR DDRC
    #define LCD_RS 0
    #define LCD_RW 1
    #define LCD_EN 2

    unsigned char x,abc=0,z,ch=0,i,st,flag,enter=0;
    char msg[150];
    char cmti[]=”+CMTI”;

    /*typedef struct bitfield
    {
    unsigned char bit1:1;
    }bitfield;

    bitfield flag;*/

    void UART_init()
    {
     UCSRB = ((1<<TXEN)|(1<<RXEN)|(1<<RXCIE));  // Enable UART   receiver and transmitter
        UCSRC = (1<<UCSZ1) | (1<<UCSZ0) | (1<<URSEL);
     UBRRL = 0x47;
    }

     

    void tx(unsigned char b)
    {
     while(!(UCSRA & (1<<UDRE)));
     UDR = b;
    }

    void sendSMS(char* z)
    {
     unsigned char t;
     for(t=0;z[t] != ‘’;t++)
      {
       tx(z[t]);
      }
    }

    void lcdcommand(unsigned char cmnd)
    {
     LCD_PRT = (LCD_PRT & 0x0F)| (cmnd & 0xF0);
     LCD_PRT &=~(1<<LCD_RS);
     LCD_PRT &=~(1<<LCD_RW);
     LCD_PRT |=(1<<LCD_EN);
     _delay_ms(2);
     LCD_PRT &=~(1<<LCD_EN);
     _delay_ms(2);
     LCD_PRT = (LCD_PRT & 0x0F) | (cmnd<<4);
     LCD_PRT |= (1<<LCD_EN);
     _delay_ms(2);
     LCD_PRT &=~ (1<<LCD_EN);
     _delay_ms(20);
    }

    void lcddata(unsigned char data)
    {
     LCD_PRT = (LCD_PRT & 0x0F) | (data & 0xF0);
     LCD_PRT |= (1<<LCD_RS);
     LCD_PRT &=~ (1<<LCD_RW);
     LCD_PRT |= (1<<LCD_EN);
     _delay_ms(2);
     LCD_PRT &=~ (1<<LCD_EN);
     _delay_ms(2);
     LCD_PRT = (LCD_PRT & 0x0F) | (data << 4);
     LCD_PRT |= (1<<LCD_EN);
     _delay_ms(2);
     LCD_PRT &=~ (1<<LCD_EN);
     _delay_ms(20);
    }

    void LCD_init()
    {
     LCD_DDR = 0xFF;
     LCD_PRT &=~(1<<LCD_EN);
     lcdcommand(0x33);
     lcdcommand(0x32);

     lcdcommand(0x28);
     lcdcommand(0x06);
     lcdcommand(0x0E);
     lcdcommand(0x01);
    }

    void LCD_print(char * str)
    {
     unsigned char i=0;
     while(str!=0)
     {
      lcddata(str
    );
      i++;
     }
    }

    ISR (USART_RXC_vect)
    {
     st=UDR;
     msg[ch]=st;
     
     if(flag==0)
     {
       if (msg[ch] == ‘K’)
       {
        flag=1;
       }
       ch++;
     }
     
     if(flag==2 && msg[ch]==cmti[ch])
     {
      ch++;
       if(ch==5)
       {
        flag=3;
       }
      
     }
     
     if(flag==4)
      {
       if(msg[ch]==0x0d)
       {
        enter++;
        if(enter==4)
        {
         flag=5;
        }
       }
       ch++;
      }
      
     if(flag==6)
     {
       if (msg[ch] == ‘K’)
       {
        flag=7;
       }
       ch++;
     } 
    }

    /*ISR (USART_RXC_vect)
    {
     z=UDR;
     if(z == ‘K’ || z == ‘k’)
      {
       flag = 1;
      }
    }*/

    void clear(void)
    {
     unsigned char a;
     for(a=0;a<150;a++)
      msg[a]=0x00;
    }

    int main()
    {
     unsigned char i=0;
     flag = 0;
     DDRC = 0xfc;

     UART_init();
     LCD_init();
        sei();

     tx(0x0d);
     tx(0x0a);
     _delay_ms(200);

     sendSMS(“AT”);
     tx(0x0d);
     while (flag!=1){}
     
      LCD_print(“Initialize”); 
      flag=0;
      ch=0;
     
      
     sendSMS(“ATE0”);
     tx(0x0d);
     lcdcommand(0x8a);
     while (flag!=1){}
     
      LCD_print(“.”); 
      flag=0;
      ch=0;
     

     sendSMS(“AT&W”);
     tx(0x0d);
     lcdcommand(0x8b);
     while (flag!=1){}
     
      LCD_print(“.”); 
      flag=0;
      ch=0;
     

     sendSMS(“AT+CMGF=1”);
     tx(0x0d);
     lcdcommand(0x8c);
     while (flag!=1){}
     
      LCD_print(“.”); 
      flag=2;
      ch=0;
     
     _delay_ms(1000);
     lcdcommand(0x01);

    while(1)
    {
     
     lcdcommand(0x01);
     lcdcommand(0x80);

     if(flag==3)
     {
      LCD_print(“AT+CMGR=1”);
      lcdcommand(0x80);
      LCD_print(“Reading Msg”);
      _delay_ms(2000);
      sendSMS(“AT+CMGR=1”);
      tx(0x0d);
      ch=0;
      flag=4; 
     }
     
     if(flag==5)
     {
      lcdcommand(0x01);
      lcdcommand(0x80);
      for(i=63;i<68;i++)
       lcddata(msg);
      _delay_ms(5000);
      
      lcdcommand(0x01);
      lcdcommand(0x80);
      LCD_print(“AT+CMGD=1”);
      sendSMS(“AT+CMGD=1”);
      tx(0x0d);
      ch=0; 
      enter=0;
      flag=6;
     }  
     
     if (flag==7)
     {
      lcdcommand(0x01);
      lcdcommand(0x80);
      LCD_print(“msg deleting”);
      clear();
      _delay_ms(5000);
      ch=0;
      flag=2;
     } 
    }
    return(0);
    }

     

     

    Thanx in advance…………..

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

RSS Recent Posts

  • AI algorithm for bots April 17, 2026
  • SDCC Array Access In Timer 0 Interrupt Handler April 16, 2026
  • EasyEda program has a major bug April 16, 2026
  • ANOTHER OLD PROJECT REDO April 16, 2026
  • How to set the OSCAL in a PIC 12F675 April 16, 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