help over microcontroller code

Thread Starter

adityabhandari54

Joined Jun 10, 2014
7
Hello,
i am facing problems understanding the following C code for microcontroller. Actually the task is to configure an external GSM modem via serial microcontroller port but i am not able to get the coding exactly. can someone please help me understand it. also it would be nice if some one can give me the assemble code for same.

Rich (BB code):
void gsmcmdsend(unsigned char *cmd);

unsigned char gsm_cmd3[]="AT&W";
unsigned char gsm_cmd4[]="AT+CMGF";
void gsmcmdsend(unsigned char *cmd)        
{
    unsigned char i;
    for(i=0;*cmd!='\0';i++)
    {
        SBUF=*cmd;
           while(TI==0);
        TI=0;
        cmd++;
        }
        SBUF=0x0A;
        while(TI==0);
        TI=0;
        SBUF=0x0D;
        while(TI==0);
        TI=0;
        while(RI==0);
        RI=0;
}

void main()
{
gsmcmdsend(gsm_cmd3);
gsmcmdsend(gsm_cmd4);
}
 
Last edited by a moderator:

tshuck

Joined Oct 18, 2012
3,534
The code sets up two string buffers: gsm_cmd3 and gsm_cmd4. The gsmcmdsend function sends the contents of one of these buffers one at a time until it reaches the null character (/0), then exits.

On each loop, the gsmcmdsend function also sends a newline character (0x0A) followed by a carriage return (0x0D) after each character sent. The function then seems to wait for something to be sent back, but without knowing more about your setup, it would be impossible to say for sure.

No one can give you "assemble" code (even if they wanted to) as you haven't said anything specific about your hardware.
 

Thread Starter

adityabhandari54

Joined Jun 10, 2014
7
this is the entire program of my project. The project is SMS based homeautomation which activates or deactivates the home appliance connected to a relay when a particulat text is sent. also there is a LCD connected to see the process. I am getting all the portion of LCD interface but am unknown to the serial interface part. All i want to do is convert the code below to "assembly"

#include<reg51.h>
sbit rs=P3^7;
sbit rw=P3^6;
sbit e=P3^5;
sbit fan=P1^0;
sbit lgt=P1^1;
void gsmcmdsend(unsigned char *cmd);
void cmm(char value);
void dat(char value);
void compare();
unsigned char card_id[96];
unsigned char header[]="EFY";
unsigned char gsm_cmd3[]="AT&W";
unsigned char gsm_cmd4[]="AT+CMGF";
void gsmcmdsend(unsigned char *cmd)
{
unsigned char i;
for(i=0;*cmd!='\0';i++)
{
SBUF=*cmd;
while(TI==0);
TI=0;
cmd++;
}
SBUF=0x0A;
while(TI==0);
TI=0;
SBUF=0x0D;
while(TI==0);
TI=0;
while(RI==0);
RI=0;
}
void delay(int count) //Function to provide delay
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}
void cmm(char value)
{
P2 = value;
rs=0;
rw=0;
e=1;
delay(1);
e=0;
delay(1);
return;
}
void dat(char value)
{
P2 =value;
rs=1;
rw=0;
e=1;
delay(1);
e=0;
delay(1);
return;
}
void lcdin()
{ cmm(0x38);
cmm(0x0e);
cmm(0x01);
cmm(0x06);
cmm(0x85);
return;
}
void recieve() //Function to recieve data serialy from RS232
{
unsigned char k;
for(k=0;k<=87;k++)
{
while(RI==0);
card_id[k]=SBUF;
RI=0;
}
}
void main()
{
int l,i;
P1=0x00;
lcdin();
TMOD=0x20; //Enable Timer 1
TH1=0XFD;
SCON=0x50;
TR1=1;
gsmcmdsend(gsm_cmd3);
cmm(0x01);
gsmcmdsend(gsm_cmd4);
cmm(0x01);
cmm(0x85);
for(i=0;i<3;i++)
{dat(header);}
cmm(0xc0);
while(1)
{
recieve();
for(l=83;l<=87;l++)
{
dat(card_id[l]);
}
compare();
}
}
void compare()
{
if ((card_id[83]=='f')&&(card_id[84]=='a') && (card_id[85]=='n') && (card_id[86]=='o') && (card_id[87]=='n'))
fan=1;
else if((card_id[83]=='f')&&(card_id[84]=='a') && (card_id[85]=='n') && (card_id[86]=='o') && (card_id[87]=='f'))
fan=0;
else if((card_id[83]=='l')&&(card_id[84]=='g') && (card_id[85]=='t') && (card_id[86]=='o') && (card_id[87]=='n'))
lgt=1;
else if((card_id[83]=='l')&&(card_id[84]=='g') && (card_id[85]=='t') && (card_id[86]=='o') && (card_id[87]=='f'))
lgt=0;
}

end; //end of program
 
Top