urgent does anyone know about writing AT-COMMAND in c language???

Status
Not open for further replies.

Ni yanfang

Member level 3
Joined
Jul 30, 2013
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
432
does anyone know about writing AT-COMMAND in c language in KEil. My project will use gsm modem with AT89C51 (MCU). My main purpose is sending message when press button. Please give me some sample.
 

first study about Serial communication in following link

**broken link removed**

then just send AT Commands via serial communication then the gsm will work... for more detail just refer this code
Code:
#include <reg51.h>              
#include <stdio.h>              
#define dataport P1;
sbit irout=P2^1;
sbit rs=P2^2;
sbit rw=P2^3;
sbit e=P2^4;

void serial_init(void);
void delay(int);
void lcdinit();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void convert(unsigned char *);
void serial_init(void)
{
   SCON = 0x50;                 
   TMOD = 0x20;             
   TH1   = 0xFD;         
   TR1   = 1;               
   TI   = 1;                
}
void serial(void) interrupt 4
{
unsigned int y[25];
if(RI==1)
{
y[25]=SBUF;
RI=0;
lcdinit();
convert(y[25]);
}
}
void lcdinit()
{
lcdcmd(0x38);  //2 Line, 5X7 Matrix
lcdcmd(0x0c);  //Display On, Cursor Blink
delay(1);
lcdcmd(0x01);  // Clear Screen
delay(1);
lcdcmd(0x81);  // Setting cursor to first position of first line
delay(1);
}
void convert(unsigned char *strs)
{
unsigned char m;
while(strs[m]!='\0')
{
lcddata(strs[m]);
m++;
}
}
void lcddata(unsigned char dat)
{
dataport = dat;
rs=1;
rw=0;
e=1;
delay(1);
e=0;
return;
}
void lcdcmd(unsigned char dat)
{
dataport = dat;
rs=0;
rw=0;
e=1;
delay(1) ;
e=0;
return;
}
void delay(int n)
{
   int i,j;
   for(i=0;i<n;i++)
   for(j=0;j<1000;j++);
}

void main(void)
{
IE=0x90;
irout=1;
irout=0;           
while(1)
{
       
	   if(irout==1)
	   {  
	    delay(200); 
        serial_init();                                                                                            
        printf("AT+CMGF=1%c",13);                                        
	    delay(200);            
        printf("AT+CMGS=\"9747358520\"%c",13);
	    delay(200);           
        printf("Hi :-) GSM Modem Test");                     
		delay(20); 
        printf("%c",0x1A);                                                             
		delay(200); 
		while(irout==1);
		}
        
}}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…