Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

at command code

Status
Not open for further replies.

chancelier

New Member
Hi everyone,..
i am interfacing sagem modem with a 16F877 to send sms via serial RS232 port.
My only problem is:
How to write the AT-commands in mikroC language?

For example:
AT+CMGR=1 --> This command will read the sms stored in location 1.

I want to know how to translate this command into mikroC.?

help please

regards
 
The AT code is sent as a serial byte string over the RS232 port in ASCII coded letters.
 
Well, for a PIC that has a hardware UART, the following would be correct (check baud rate for modem though):
Code:
UART1_Init(9600); //For the first hardware UART
Delay_ms(100);   //Allow for the UART to initialise properly
UART1_Write('A');
UART1_Write('T');
UART1_Write('+');
UART1_Write('C');
UART1_Write('M');
UART1_Write('G');
UART1_Write('R');
UART1_Write('=');
UART1_Write('1');
UART1_Write(13);
UART1_Write(10);
Delay_ms(500);

Note the code above, the end UART1_Write with the 13 and 10 are NOT in '' speach marks, this is because it is not a character, but a code, 13 10 is the ascii code for CR(13) LF(10), carriage return line feed.

We add a 500ms delay to allow the UART buffer to write it's data.

This will only work for a hardware UART, there are routines for a software UART i believe if necessary.

To recieve from the UART, you will need a loop and do something like the following:
Code:
char received_rd;
while(1)
{
   if(UART1_Data_Ready())
   {
      received_rd = UART1_Read();
      //Process received data
   }
}

All of this was taken from the Mikro C examples and just rearranged to suit your question.

Hope this helps!

Wilksey.
 
Last edited:
Note: To check the command you could look for the "OK" or "ERROR" messages that the modem responds with.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top