GL865_ON_OFF at RC3_bit;
//
RTS == Hardware Handshake
GL865_ON_OFF_Direction at TRISC3_bit;
RTS at RC4_bit;
RTS_Direction at TRISC4_bit;
// buffer
// - UART 2 == Terminal zu PC
// void UART2interrupt() iv IVT_UART_2 ilevel 6 ics ICS_AUTO {
void UART2interrupt() iv IVT_UART_2 ilevel 7 ics ICS_AUTO{
uart_rd = UART2_Read();
// read the received data
UART5_Write(uart_rd);
// and send data via UART
U2RXIF_bit = 0;
// Interrupt register flag zurcksetzen auf 0
}
// - UART 5 == Modem
//void UART5interrupt() iv IVT_UART_5 ilevel 6 ics ICS_AUTO {
void UART5interrupt() iv IVT_UART_5 ilevel 7 ics ICS_AUTO{
uart_rd = UART5_Read();
// read the received data
buffer[write] = uart_rd;
write = write + 1;
// Buffer index
UART2_Write(uart_rd);
if (write == (BUFFER_SIZE-1))
write = 0;
U5RXIF_bit = 0;
// Interrupt register
}
void InitUart2Interrupt();
void InitUart5Interrupt();
int search_in_string(char*);
int wait_response(char*);
void send_to_GL865(char*);
void send_Msg(char*);
// funcion for sending Text messages
void main(){
int i;
AD1PCFG = 0xFFFF;
JTAGEN_BIT = 0;
TRISA = 0XFFFF;
TRISB = 0XFFFF;
TRISC = 0X0000;
UART2_Init(115200);
Delay_ms(100);
UART5_Init(115200);
Delay_ms(100);
InitUart2Interrupt();
InitUart5Interrupt();
EnableInterrupts();
RTS = 0;
// erase buffer
for(i=0;i<BUFFER_SIZE;i++){
buffer[i]='0';
}
write = 0;
// Port: RC3 == Reset des Modems // Turn on the GM862 module
GL865_ON_OFF = 1;
// hardware reset
Delay_ms(1500);
// hold it at least for two seconds
GL865_ON_OFF = 0;
Delay_ms(1500);
// hold it at least for two seconds
send_to_GL865(atc16);
// Query SIM Status #2 == SIM INSERTED and PIN UNLO
CKED(Page 310)
wait_response(SIM_READY);
/* Set Message Receive Mode */
send_to_GL865(atc17);
wait_response(GSM_OK);
Send_Msg(SMS_Message); // send message "hello World"
while (1) {
rs
WDTCONSET = 0x01;
// Watchdog service
}
}
void InitUart5Interrupt(){
U5IP0_bit = 1;
U5IP1_bit = 1;
U5IP2_bit = 1;
WDTCONSET = 0x01;
U5RXIE_bit = 1;
}
void InitUart2Interrupt(){
U2IP0_bit = 1;
U2IP1_bit = 1;
U2IP2_bit = 1;
WDTCONSET = 0x01;
U2RXIE_bit = 1;
}
// Watchdog service
send_to_GL865(atc2);
// Set message type as TXT
Wait_response(GSM_OK);
atc[0] = 0;
// clear atc string
strcat(atc, atc3);
// atc3 command for sending messages
strcat(atc, phone_number);
// add phone number
strcat(atc, "\"");
// complete AT command -- ein " am ende des
Kommandos
send_to_GL865(atc);
// send AT command for SMS sending
Wait_response(GSM_Ready_To_Receive_Message); // wait for ">" signal
send_to_GL865(Msg);
UART5_Write(26);
Wait_response("+CMGS:");
WDTCONSET = 0x01;
// Watchdog service
}