Problem in Interfacing SIM 300 with 8051

Status
Not open for further replies.

mpatibandla

Newbie level 1
Joined
Feb 21, 2013
Messages
0
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,280
Activity points
1,280
Guys I am currently on a project working with 8051, specifically AT89S52.
I want to send SMS to the GSM Module, in this case I have used SIM 300, whenever one pin of the 8051 gets high.
The GSM Module is working fine because it has responded to the commands when connected to the PC Hyper Terminal.
I am even sure about the hardware and circuit I have connected because I have checked all the voltage differences and they are exactly fine the way they need to be.
I think the problem lies in the code.

Here I am posting the code. Anybody who has already worked on this can kindly help me solving this

#include <REGX51.H>

unsigned char *command_AT = "AT\r";
unsigned char *command_CMGF = "AT+CMGF=1\r";
unsigned char *command_CMGS1 = "AT+CMGS =\"+918125883588\"\r";

unsigned char *message = "ALERT";
unsigned char CTRLZ = 0x1A;
void puts(unsigned char* ptr);
void putc(unsigned char chr);
void sendsms(void);
void initialize();
void delay();

int main(void)
{
P1 = 0x00;
P3 = 0x00;
while(1)
{

if(P1_0!=0x00 || P1_1!=0x00 || P1_2!=0x00 || P1_3!=0x00 || P1_4!=0x00 || P1_5!=0x00 || P1_6!=0x00 || P1_7!=0x00)
{
initialize();
sendsms();
P1=0x00;
}

}
return 0;
}
void initialize()
{
SCON = 0x50; /*SCON: mode 1, 8-bit UART, enable receive */
TMOD |= 0x20; /*TMOD: timer 1, mode 2, 8-bit */
TH1 = 0xFD; /*TH1: for 9600 baud */
TR1 = 1; /*TR1: timer 1 run */
IE=0X90;
}
void delay(int ms){

char k;
while (ms--)
{
for (k=0; k < 1; k++)
{
}
}
}

void sendsms()
{
puts(command_AT);
delay(1);
puts(command_CMGF);
delay(1);
puts(command_CMGS1);
delay(1);

puts(message);
delay(1);
putc(CTRLZ);
delay(1);
puts(command_AT);
}

void puts(char* p)
{
char *temp = p; /*temp pointer so that the actual pointer is not displaced */
while(*temp != 0x00)
{
putc(*temp);
temp++;
}
}

void putc(unsigned char chr)
{
SBUF = chr;
while(TI!=0); /*Wait until the character is completely sent */
TI=0; /*Reset the flag */
}
 

try connecting your hardware to the PC and check if you are getting the commands sent on the hyperterminal. generally the problem lies in mismatch of baud rates.
 

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…