UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100);
UART1_Write(2);
UART1_Write(13);
UART1_Write_Text("AT+CMGS=");
Delay_ms(1000);
UART1_Write(0x22); // double qoute
Delay_ms(2000);
UART1_Write_Text("9800220107"); // Telephone Number
cd_chr_cp(uart_rd);
UART1_Write(0x22); // double qoute
UART1_Write(0x0D); // mean Enter
UART1_Write(0x22);
UART1_Write_Text("Wasti"); //My Text Test
UART1_Write(0x22); // double qoute
Delay_ms(2000);
UART1_Write(26); //Ctr +Z
Delay_ms(2000);
UART1_Write(0x0D); // mean Enter
Delay_ms(2000);
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 void main() { //Set UART Tx and Rx pins as input pins here using TRISx UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); while(1) { UART1_Write_Text("AT\r"); Delay_ms(2000); UART1_Write_Text("AT+CMGS=1\r"); Delay_ms(2000); UART1_Write_Text("AT+CMGS=\"9800220107\"\r"); Delay_ms(3000); UART1_Write_Text("Wasti"); UART1_Write(26); Delay_ms(6000); } }
Hi, Try this code.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 void main() { //Set UART Tx and Rx pins as input pins here using TRISx UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); while(1) { UART1_Write_Text("AT\r"); Delay_ms(2000); UART1_Write_Text("AT+CMGS=1\r"); Delay_ms(2000); UART1_Write_Text("AT+CMGS=\"9800220107\"\r"); Delay_ms(3000); UART1_Write_Text("Wasti"); UART1_Write(26); Delay_ms(6000); } }
(This is just the part of my code. Some part is missing here.)
void main()
{
LCD_Init();
Lcd_Cmd(_LCD_CLEAR);
UART1_Init(9600);
UART1_Write_Text("ATE0");
UART1_Write(13);
UART1_Write(10);
Delay_ms(1500);
UART1_Write_Text("AT+CMGF=1");
UART1_Write(13);
UART1_Write(10);
Delay_ms(1500);
while(1){
UART1_Write_Text("AT+CMGS=") ;
Delay_ms(500);
UART1_Write_Text("\"+9231234567\"");
Lcd_Out(2,1,"031234567");
UART1_Write(13);
UART1_Write(10);
Delay_ms(1500);
Lcd_Cmd(_LCD_CLEAR);
UART1_Write_Text("HI HELLO");
Lcd_Out(2,1,"HI HELLO");
UART1_Write(26) ;
Delay_ms(1500);
}
}
Zip and attach your mikroC Project files. I will add the code to receive SMS. Also post screenshot showing SIM900 response for AT+CMGR=x\r
x can be any index value. It will be usually 0 to 25 for SIM memory.
// Lcd pinout settings
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
// Pin direction
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
void main()
{
TRISD = 0;
TRISC = 0;
PORTD=0 ;
LCD_Init();
Lcd_Cmd(_LCD_CLEAR);
UART1_Init(9600);
Lcd_Out(1,1,"Hello");
UART1_Write_Text("ATE0");
Lcd_Out(2,1,"ATE0");
UART1_Write(13);
UART1_Write(10);
Delay_ms(1500);
Lcd_Cmd(_LCD_CLEAR);
UART1_Write_Text("AT+CMGF=1");
Lcd_Out(2,1,"AT+CMGF=1");
UART1_Write(13);
UART1_Write(10);
Delay_ms(1500);
Lcd_Cmd(_LCD_CLEAR);
while(1){
UART1_Write_Text("AT+CMGS=") ;
Lcd_Out(2,1,"AT+CMGS=");
Delay_ms(500);
UART1_Write_Text("\"+92331234567\"");
Lcd_Out(2,1,"0331234567");
UART1_Write(13);
UART1_Write(10);
Delay_ms(1500);
Lcd_Cmd(_LCD_CLEAR);
UART1_Write_Text("HI HELLO");
Lcd_Out(2,1,"HI HELLO");
UART1_Write(26) ;
Delay_ms(1500);
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 signed char sms_in[95]; bit flag; char i=0; void interrupt() { if (PIR1.RCIF==1) { if (UART1_Data_Ready()) { sms_in[i] = UART1_Read(); i++; if(i==88) { flag=1; } Suppose I received message like "+CMGR: \"REC UNREAD\",\"+919325457889\",\"\",\"2014/12/27 17:04:02+22\"\r\nONN\r\nOK\r\n"; Then led should be ON & when message received like "+CMGR: \"REC UNREAD\",\"+919325457889\",\"\",\"2014/12/27 17:04:02+22\"\r\nOFF\r\nOK\r\n"; Then led should be OFF } } } void main() { INTCON.GIE = 1; INTCON.PEIE = 1; PIE1.RCIE=1; TRISC5_bit = 0; UART1_Init(9600); Delay_ms(500); UART1_Write_Text("AT"); Delay_ms(1000); UART1_Write_Text("AT+CMGF=1"); Delay_ms(1000); UART1_Write_Text("AT+CMGR=1"); Delay_ms(1000); while(1) { if(flag==1) { char q=79; if(sms_in[q]=='A'&& sms_in[q+1]=='R'&& sms_in[q+2]=='T') { RC5_bit=1; UART1_Write(0X0D); UART1_Write(0X0A); flag=0; i=0; } else if(sms_in[q]=='O'&& sms_in[q+1]=='F'&& sms_in[q+2]=='F') { RC5_bit=0; UART1_Write(0X0D); UART1_Write(0X0A); flag=0; i=0; } } } }
signed char sms_in[90];
bit flag;
char i=0;
void interrupt()
{
if (PIR1.RCIF==1)
{
if (UART1_Data_Ready())
{
sms_in[i] = UART1_Read();
i++;
if(i==88)
{
flag=1;
}
}
}
}
void main()
{
INTCON.GIE = 1;
INTCON.PEIE = 1;
PIE1.RCIE=1;
TRISC5_bit = 0;
UART1_Init(9600);
Delay_ms(500);
UART1_Write_Text("AT");
Delay_ms(1500);
UART1_Write_Text("AT+CMGF=1");
Delay_ms(1500);
while(1)
{
UART1_Write_Text("AT+CMGR=1");
Delay_ms(1500);
if(flag==1)
{
char q=75;
if(sms_in[q]=='O'&& sms_in[q+1]=='N'&& sms_in[q+2]=='N')
{
RC5_bit=1;
UART1_Write(0X0D);
UART1_Write(0X0A);
flag=0;
// i=0;
}
else if(sms_in[q]=='O'&& sms_in[q+1]=='F'&& sms_in[q+2]=='F')
{
RC5_bit=0;
UART1_Write(0X0D);
UART1_Write(0X0A);
flag=0;
// i=0;
}
}
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?