Hi, I'm now trying to send SMS from p18f4520 to my phone. But I can't seem to send or receive the SMS.
I'm using BluOcean Serial GSM / GPRS Modem, attached is the connection from p18f4520 to the modem
and my code:
I'm using BluOcean Serial GSM / GPRS Modem, attached is the connection from p18f4520 to the modem
and my code:
#include <p18f4520.h>
#include <stdio.h>
#include <delays.h>
#include <string.h>
#include <usart.h>
#include <stdlib.h>
void ok_sms(void);
void main(void)
{
//Configuration of Modem
ADCON1 = 0x0F; // default all pins to digital
TRISC = 0b10111111; // RC7(RX) as input , RC6(TX) as output
SPBRG = 25; // baud rate of 9600
TXSTA = 0b00100100; // asynchronous mode, 8-bit data
// transmit enable, high baud rate select bit
RCSTA = 0b10010000; // serial port enable, 8-bit data
// continuous reception
TRISA = 0XF0; // bit 4 of PORTA as input
TRISB = 0b11110001; // bit 1-2 of PORTB as outputs, RB0 as input
while(1){
ok_sms();
}
}
void ok_sms(void)
{
putrsUSART((const far rom char *)"AT\r\n");
while(!BusyUSART());
Delay10KTCYx(50); //50x10k instruction cycle = 0.5s delay
putrsUSART((const far rom char *)"AT+CMGF=1\r\n"); //Operatng in SMS text mode
while(!BusyUSART());
Delay10KTCYx(50); //50x10k instruction cycle = 0.5s delay
putrsUSART((const far rom char *)"AT+CNMI=2,1,0,0,1\r\n"); //setting for reading SMS
while(!BusyUSART());
Delay10KTCYx(50); //50x10k instruction cycle = 0.5s delay
putrsUSART((const far rom char *)"AT+CMGS=\"96******\"\r"); //Sending SMS to recipant
while(!BusyUSART());
Delay10KTCYx(50); //50x10k instruction cycle = 0.5s delay
putrsUSART((const far rom char *)"OK\x1A\n"); //message to be sent
while(!BusyUSART());
Delay10KTCYx(50); //50x10k instruction cycle = 0.5s delay
}
Last edited: