Hi all... I am trying to interface SIM900A with 89S52 to send messages to the mobile phone. Code:
#include<reg51.h> unsigned char *command_ATE0 = "ATE0\r"; unsigned char *command_AT = "AT\r"; unsigned char *command_CMGF = "AT+CMGF=1\r"; unsigned char *command_CMGS = "AT+CMGS=\"+9199********\"\r"; unsigned char *message = "Welcome to the world of Robotics..!"; // Msg 2 be send unsigned char CTRLZ = 0x1A; void gsm(); void puts(unsigned char* ptr); void putc(unsigned char chr); void sendsms(void); void initialize(); void delay(unsigned int time); void main() { gsm(); while(1); } void gsm() { initialize(); sendsms(); } 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 */ } void sendsms() { puts(command_ATE0); delay(50); puts(command_AT); delay(50); puts(command_CMGF); delay(50); puts(command_CMGS); delay(50); puts(message); delay(50); putc(CTRLZ); } 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 */ } void delay(unsigned int time) { unsigned int y,z; for(y=0;y<=time;y++) for(z=0;z<2400;z++) { ; } }
but while stimulating the same in proteus, i am getting an error... the virtual terminal window display something ugly which i cannot understand. it displays something like @$#%%$#435#$5#$%GBF# %#^456y456%^%$% g$^&^&%$%^% can anybody please help me....
Wrong baudrate is a great way to get random junk printed.
By the way - what do you mean by:
/*temp pointer so that the actual pointer is not displaced */
You realize that the function gets a copy of the pointer as parameter?
i have checked the baud rate of virtual terminal.... and also have set to 9600.... but still its giving an error.... also tried send command ATE after AT command... but the problem continues
can you also please let me know where do i need to change the code..... where i have made a mistake.... as i have seen... while working in a circuit... it sends the message correctly to defined phone number. but only gives error in proteus.... proteus baud rate also set to 9600....