Hi, sorry it took me days to reply, here is my code:
void main()
{
unsigned char output[20];
TRISB.LATB0 = 0; //make PORTB pin 0 output
PORTB.LATB0 = 1;
Delay_ms(1000);
PORTB.LATB0 = 0;
Delay_ms(15000);
UART1_Init(9600); // initialize UART1
Delay_ms(100);
UART1_Write_text("ATE1\r\n");
Delay_ms(5000);
UART1_Write_text("AT+CCLK?\r\n");
if (UART1_Data_Ready() == 1)
{ // if data is received
UART1_Read_Text(output, "+2", 10); // reads text until +2 is found
Delay_ms(500);
UART1_Write_text("AT+CMGF=1\r\n");
Delay_ms(500);
UART1_Write_Text("AT+CMGS=\"0737071248\"\r\n");
Delay_ms(500);
UART1_Write_Text(output);
UART1_Write_text("\r\n");
UART1_Write(0x1A);
Delay_ms(5000);
}
}
this works fine in proteus simulation with data I enter through virtual terminal, but it doesn't work when I program it to my pic. I also tried the UART interrupt examples but what I cannot figure out is how to enable a UART interrupt only when I send "AT+CCLK?" to gsm module. I'm really messed up with the problem hope you could help me.
Thanks.