Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

GSM SMS 8051 controlling relays

Status
Not open for further replies.
Re: gsm relay

guys ,
I want to interface 8051(at89s52) with nokia 6070...when I connect the fbus with the pc's db-9 connector and through hyper terminal, if a send 'at', i get back an 'ok' response from the mobile on hyper terminal...as fbus is ttl-to-rs232 level converter, so i decided to directly connect the tx,rx pins of mc with the tx ,rx of the mobile and also interfaced an 16*2 lcd with mc,,,Now when i send 'at' to mobile phone, then it does not send an 'ok' on the lcd screen,,,what could be the problem then,,,i guess could it be:: since sbuf is an 8-bit reg but mobile sends 'ok' which is a 16-bit word ,so is the sbuf overrun??,,,,,plzzzzzzzzzzzz tell me what could be the problem, guide me friends,,,also below i have given the code which i am using ,,what could be the problem guys???????


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
$MOD51
 
ORG 0000H
 
; INDICATE FOR SERIAL TRANSMISSION
MOV TMOD,#20H ; TIMER 1 MODE 2
MOV TH1,#-3 ; FOR Baud rate
MOV SCON,#50H
 
start: clr P2.0
mov dptr,#100h
setb tr1
back: clr a
movc a,@a+dptr
jz here_2
acall send
inc dptr
 
sjmp back
 
 
 
send: mov sbuf,a;////transmit
here: jnb ti,here
clr ti
ret
 
 
here_2: jnb ri,here_2 ;/////receive
clr ri
 
mov r1,sbuf
 
mov a,#38h ; 16 x 2 LCD 5 x 7 Matrix
acall command 
acall ready
mov a,#0fh ; Disply on,Cursor Blinking
acall command
acall ready
mov a,#06h ; Increment Cursor
acall command
acall ready
mov a,#01h ; Clear Disply
acall command
acall ready
mov a,#80h ; Force Cursor to Begining of First Line
acall command
acall ready
 
 
lcd: mov a,r1
acall display
acall ready
 
here6: sjmp here6
 
command:
mov P1,a
clr P2.5 ;RS=0 For COMMAND REGISTER
clr P2.6 ; READ/WRITE 
setb P2.7
acall ready
clr P2.7
ret
 
display:
mov P1,a
setb P2.5 ;RS=1 For DATA REGISTER
clr P2.6 ; READ/WRITE 
setb P2.7
acall ready
clr P2.7
ret
 
; Approx. 20ms Delay 
ready:
mov tmod,#01h ;timer0,mode1(16-bit mode)
mov th0,#03eh
mov tl0,#0b8h
setb tr0
again: jnb tf0,again
clr tr0
clr tf0
RET
 
;%%%%%%%%%%%%%%%%%%%%%%%%%%
 
org 100h
db 'a','t',0h
END

 
Last edited by a moderator:

hey friend ronydc can u send me ur code and schematic because i'm doing project about gsm modem and control relays and i need your help please
 

controlling relay by sms
hiiiiii friend i am new in this forum, my project is controlling relay by sms
if any body have this relay controlling code please post it.

thanks in advance
 
Last edited by a moderator:

Re: $crystal at+cmgf=1

ok ok.. friends..

no need to reply this post.
i have got the solution and i am able to make 8 relays on and off with SMS with IC 8051.

THANKS ANY WAY.

will you please share the solution with us
 

Dear Yasir;

I have written the code for sending & recieving SMS with ATMEGA32 & wavecom modem in CODEVISION AVR compiler. My code does not work with Modem. Some times it work with PC Hyper terminal. Can you please find the problem?



Code:
Chip type               : ATmega16
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/
#include <mega16.h>

// Standard Input/Output functions
#include <stdio.h>
#include <string.h>
#include <delay.h>

// Declare your global variables here

#define NO_OF_SEND_TRY 3

// Declare your global variables here
char data; // Use for data read purpose
char Msg_source[15];
char Msg_command[30];

int New_msg_flag =0;
int Handshake_status =0;
int Delete_status=0;

int No_of_send_msg1=0;
int No_of_send_msg2=0;
//int i;
//1. This function is used to read the available data
//from USART. This function will wait untill data is
//available.
char USARTReadChar()
{
   //Wait untill a data is available
   while(!(UCSRA & (1<<RXC)))
   {
      //Do nothing
   }
       //Now USART has got data from host and is available is buffer
   return UDR;
}
//This fuction writes the given "data" to the USART which then transmit it via TX line

void USARTWriteChar(char data)
{
   //Wait untill the transmitter is ready
  while(!(UCSRA & (1<<UDRE)))
   {
      //Do nothing
   }

   //Now write the data to USART buffer
   UDR=data;
}

int Handshake()
{
    int response1=0;
    int response2=0;
     /* Now send the AT command */    
    USARTWriteChar('A');
    USARTWriteChar('T');
    USARTWriteChar('\n');          
    //Check whether response is OK or not
     delay_ms(300);
    data=USARTReadChar();                
    if(data=='O')    
     {
      data=USARTReadChar();
      if(data=='K')        
              response1=1;
      else
              PORTA |=(1<<2);
     } 
    else
          PORTA |=(1<<1);
    USARTWriteChar('A');
    USARTWriteChar('T'); 
    USARTWriteChar('+');         
    USARTWriteChar('C');
    USARTWriteChar('M');
    USARTWriteChar('G');
    USARTWriteChar('F');
    USARTWriteChar('=');
    USARTWriteChar('1');
    USARTWriteChar('\n');
//Check whether response is OK or not
 delay_ms(300);
    data=USARTReadChar();                
    if(data=='O')        
     {
       data=USARTReadChar();
       if(data=='K')        
              response2=1;
    else
      PORTA |=(1<<4);
     }  
    else
       PORTA |=(1<<3);   
              
if (response1 && response2)    
    return 1;
else
    return 0;
}

void Create_send_msg(int index)
{
  char Output_msg [80];  
  char Ctrl_Z[3];
  int i=0;
                                
  Ctrl_Z[0]=(char)26;
  Ctrl_Z[1]='\0';
  
  strcpy (Output_msg,"AT+CMGS=\"01711136358\"\n");
  if (index == 7)
       strcat (Output_msg,"Port D bit 7 is ON");
  if (index == 6)                         
       strcat (Output_msg,"Port D bit 6 is ON");
      
  strcat (Output_msg,Ctrl_Z);
  while (Output_msg[i]!='\0')
  {
   USARTWriteChar(Output_msg[i]);
   i++; 
  }       
   delay_ms(100);
}

void Delete_msg()
{
    Delete_status=0;
    USARTWriteChar('A');
    USARTWriteChar('T'); 
    USARTWriteChar('+');         
    USARTWriteChar('C');
    USARTWriteChar('M');
    USARTWriteChar('G');
    USARTWriteChar('D');
    USARTWriteChar('=');
    USARTWriteChar('1');
    USARTWriteChar(',');
    USARTWriteChar('2'); 
    USARTWriteChar('\n');
  //Check whether response is OK or not
   delay_ms(100);
    data=USARTReadChar();                
    if(data=='O')        
      data=USARTReadChar(); 
    if(data=='K')
      {       
        Delete_status=1;
        PORTA |=(1<<5);
       //PORTA3=1;
        delay_ms(100);
       } 
}

void Process_msg()
{
 int i; 
  /*This function is called when it comes from authenticated source
and then it already read the send device no and so discard the next
25 charecter to find the original message */
  for(i=0;i<25;i++)  
     data=USARTReadChar();         
  i=0;   
  data=USARTReadChar();  
  //check for '.' as command ends with . Valid command can be 
  // bit 7 on. or bit 7 off. 
  while (data!='.')
  {
   Msg_command[i]=data;
   i++;                
   data=USARTReadChar();
  }
  Msg_command[i]='\0';
  if (strcmp(Msg_command, "bit 6 on")==0)
        PORTA |=(1<<6);                  
  //if (strcmp(Msg_command, "bit 5 on")==0)
    //    PORTB |=(1<<5);
  if (strcmp(Msg_command, "bit 6 off")==0)
        PORTA &=~(1<<6);                  
 // if (strcmp(Msg_command, "bit 5 off")==0)
   //     PORTB &=~(1<<5);       
  delay_ms(100);     
     
  Delete_msg();
   delay_ms(100);       
}        

void Read_msg()
{
 /* Now send the AT + CMGL =1 command; This will read the 1st SMS*/    
 int i;
    USARTWriteChar('A');
    USARTWriteChar('T'); 
    USARTWriteChar('+');         
    USARTWriteChar('C');
    USARTWriteChar('M');
    USARTWriteChar('G');
    USARTWriteChar('R');
    USARTWriteChar('=');
    USARTWriteChar('1');
    USARTWriteChar('\n');
                     
    delay_ms(100);
//Check whether response starts with '+' which indicate message arrives
    data=USARTReadChar();                
    if(data!='+')        
     {
      New_msg_flag=0;
     }  
     else
     {
        New_msg_flag=1; 
        PORTA |=(1<<7);
       //PORTA7=1;
        delay_ms(300);
        New_msg_flag=0;
        for(i=0;i<20;i++)  //discard the following 20 charecter to find the mobile no //
          data=USARTReadChar();
        for (i=0;i<14;i++) //collect the source device Identification Number //
        {
          data=USARTReadChar();
          Msg_source[i]=data;
        }
        Msg_source[i]='\0'; 
             
        if (!strcmp(Msg_source, "+8801711136358"))  
         {
          Process_msg();
          Delete_msg();
         }
        else
        {
         //From other source, so delete the message
         Delete_msg();
        } 
     
     }
}

// Declare your global variables here



void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTA=0x00;
DDRA=0xFF;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

while (1)
      {
      // Place your code here
      //Check whether AT command performs correctly or not 
      //return positive if success
      Handshake_status=Handshake();
      if(Handshake_status==0)
       {
       PORTA |=(1<<0);
       //PORTA0=1;
       } 
       //Led will go high to indicate red as handshake failed 

      
         Read_msg();
      
       //if (PORTD7==1 || PORTD6==1)
      if ((PIND & (1<<PIND7))&&(No_of_send_msg1<NO_OF_SEND_TRY))
         {
           Create_send_msg(7);
           delay_ms(300);    
           No_of_send_msg1++;
         }    
          
      if(No_of_send_msg1==NO_OF_SEND_TRY)
            {
             //PORTD &=~(1<<7);
             No_of_send_msg1=0;
             Delete_msg();
            }
         
     if ((PIND & (1<<PIND6))&&(No_of_send_msg2<NO_OF_SEND_TRY))
          {
           Create_send_msg(6);  
           No_of_send_msg2++;
           }    
       
    if(No_of_send_msg2==NO_OF_SEND_TRY)
            {
             //PORTD &=~(1<<6);  
             No_of_send_msg2=0;
             Delete_msg();
             }          
       }

}



Sir, have u cmpltd this project. I am having some problem with interfacing SIM300 gsm modem with ATMEGA16.
Please help .
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top