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.?
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.