void Send_Sms(){
UART1_Init(9600);
Delay_ms(100);
UART1_Write_Text("AT");
Delay_ms(100);
UART1_Write_Text("AT+CMGF=1");//set mode as text message
Delay_ms(100);
UART1_Write(0x0D); //enter
UART1_Write_Text("AT+CMGS=");
Delay_ms(100);
UART1_Write(0x22);
Delay_ms(100);
UART1_Write_Text("+919243342000"); //mobile number
Delay_ms(200);
UART1_Write(0x22);
Delay_ms(100);
UART1_Write(0x0D); // Enter
Delay_ms(100);
UART1_Write_Text("Hello this is my txt in all its glory"); //your message
Delay_ms(600);
Delay_ms(100);
UART1_Write(26); //Ctr +Z --send
Delay_ms(200);
}
void main ()
{
delay_ms(1000);
UART1_Init(9600);
Delay_ms(100);
UART1_Write_Text("AT");
Delay_ms(100);
UART1_Write(0x0D); //enter
UART1_Write(0x0A);
UART1_Write_Text("AT+CMGF=1");//set mode as text message
Delay_ms(100);
UART1_Write(0x0D); //enter
UART1_Write(0x0A);
UART1_Write_Text("AT+CMGW=+6597329728");
Delay_ms(100);
UART1_Write(0x0D); // Enter
UART1_Write(0x0A);
Delay_ms(100);
UART1_Write_Text("Hello this is my txt in all its glory"); //your message
Delay_ms(600);
Delay_ms(100);
UART1_Write(26); //Ctr +Z --send
Delay_ms(200);
UART1_Write(0x0D);
UART1_Write(0x0A);
}
char rcv[10];
char myrx[4];
int i;
void main()
{
UART1_Init(9600);
Delay_ms(2000);
TRISB=0x00;
UART1_Write_Text("at");
UART1_Write(13); //Enter key = CF + LF
UART1_Write(10);
delay_ms(500);
while (1)
{
if (PIR1.RCIF == 1)
PORTB.RB0=1; // Endless loop
if(UART1_Data_Ready()) // If data is received,
rcv[0]=UART1_Read();
rcv[1]=UART1_Read();
rcv[2]=UART1_Read();
rcv[3]=UART1_Read();
rcv[4]=UART1_Read();
rcv[5]=UART1_Read();
rcv[6]=UART1_Read();
rcv[7]=UART1_Read();
rcv[8]=UART1_Read();
//UART1_Read_Text(rcv,"OK",255); // read the received data,
//UART1_Write(rcv); // and send data via UART
UART1_Write_Text(rcv);
PORTB.RB0=0;
}
}
void main(void){
INTCON = 0;
TRISA = 0x00;
TRISB=0x00;
ANSELA = 0x00;
ANSELB = 0x00;
UART1_Init(9600);
Delay_ms(10);
UART1_Write_Text("\r\nATE0\r\n");
int i = 0;
while (1){ // Endless loop
PORTB.RB0=1;
while (!UART1_Data_Ready()) { // If data in RCREG,
rcv[i]=UART1_Read();
i++;
}
rcv[i] = 0x00;
UART1_Write_Text(rcv);
i = 0;
PORTB.RB0=0;
}
}
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 void main(void){ INTCON = 0; TRISA = 0x00; TRISB=0x00; ANSELA = 0x00; ANSELB = 0x00; UART1_Init(9600); Delay_ms(10); // UART1_Write_Text("\r\nATE0\r\n"); char GSM_reply; int i = 0; while (1){ // Endless loop PORTB.RB0=1; GSM_reply = UART1_Read(); switch GSM_reply{ case 0x0A: break; case 0x0D: // if <CR> character received rcv[i] = 0x00; if (strlen(rcv) > 0){ UART1_Write_Text(rcv); i = 0; PORTB.RB0=0; } break; default: rcv[i] = GSM_reply; i++; break; } } }
char GSM_reply;
int i = 0;
char rcv[100];
void main(void){
INTCON = 0;
TRISA = 0x00;
TRISB = 0x00;
//ANSELA = 0x00;
//ANSELB = 0x00;
UART1_Init(9600);
Delay_ms(10);
UART1_Write_Text("AT\r\n");
while (1){ // Endless loop
PORTB.RB0=1;
GSM_reply = UART1_Read();
switch (GSM_reply)
{
case 0x0A:
break;
case 0x0D: // if <CR> character received
rcv[i] = 0x00;
if (strlen(rcv) > 0){
UART1_Write_Text(rcv);
i = 0;
PORTB.RB0=0;
}
break;
default:
rcv[i] = GSM_reply;
i++;
break;
}
}
}
Try, change while(!UART_Data_Ready=0) to while(UART_Data_Ready=0).Also, on using your first code, UART_Data_Ready=0, so it does not execute the loop...
void main(void){
INTCON = 0;
TRISA = 0x00;
TRISB=0x00;
UART1_Init(9600);
Delay_ms(10);
UART1_Write_Text("\r\nATE0\r\n");
while (1){ // Endless loop
PORTB.RB0=1;
if (UART1_Data_Ready()) { // If data in RCREG,
rcv[i]=UART1_Read();
i++;
}
//rcv[i] = 0x00;
UART1_Write_Text(rcv);
//i = 0;
PORTB.RB0=0;
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 UART1_Init(4800) ; ' initialize UART module Delay_ms(100); while (1){ if (UART1_Data_Ready() = 1){ ' if data is received UART1_Read_Text(output, 'OK', 10) ; ' reads text until 'OK' is found UART1_Write_Text(output); ' sends back text } }
Made delay as 1500 and also added if (PIR1.RCIF == 1).
Almost you reached there.The individual bytes are 13 10 0 0 13 10. Which means the in between OK is missing.
Yes. It is correct (if you used post #9 code). I made a mistake by mentioning as "5".But i runs only for 2 times
char GSM_reply;
int i = 0;
char rcv[10];
void main(void){
INTCON = 0;
TRISA = 0x00;
TRISB = 0x00;
UART1_Init(9600);
Delay_ms(1500);
UART1_Write_Text("AT\r\n");
while (1){ // Endless loop
PORTB.RB0=1;
GSM_reply = UART1_Read();
switch (GSM_reply)
{
case 0x0A:
break;
case 0x0D: // if <CR> character received
rcv[i] = 0x00;
if (strlen(rcv) > 0){
UART1_Write_Text(rcv);
i = 0;
PORTB.RB0=0;
}
break;
default:
rcv[i] = GSM_reply;
i++;
break;
}
}
}
void main(void){
INTCON = 0;
TRISA = 0x00;
TRISB=0x00;
UART1_Init(9600);
Delay_ms(1500);
UART1_Write_Text("\r\nATE0\r\n");
Delay_ms(1500);
while (1){ // Endless loop
if (PIR1.RCIF == 1)
PORTB.RB0=1;
while (UART1_Data_Ready()) { // If data in RCREG,
rcv[i]=UART1_Read();
i++;
}
rcv[i] = 0x00;
UART1_Write_Text(rcv);
//i = 0;
PORTB.RB0=0;
}
}
......Also, comment the line "UART1_Write_Text("AT\r\n");" and restart the GSM Modem (only) NOT PIC DEMO BOARD (it should be active by default). If so, CPIN: READY, etc will be received at "rcv" buffer (If you enabled unsolicited result code). You can call the GSM Modem from your mobile phone and check the rcv buffer....
Code C - [expand] 1 2 3 4 5 6 unsigned char getch() { /* retrieve one byte */ while(!RCIF) /* set when register is not empty */ continue; return RCREG; }
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 . . . while(1){ char GSM_DATA = getch(); switch (GSM_DATA){ case 0x0A: // if line feed break; case 0x0D: // if carriage return (enter) GSM_STRING[i] = 0x00; if (strlen(GSM_STRING) > 0){ i = 0; parse_GSM_STRING(GSM_STRING); // Process received GSM String strcpy(GSM_STRING, ""); } break; case 0x3E: GREATER_SIGN = 1; break; default: GSM_STRING[i] = GSM_DATA; i++; break; } }
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?