CLICK HERE FOR FREE BLOGGER TEMPLATES, LINK BUTTONS AND MORE! »

Thursday - 2 August 2012

Read SMS Using AT Commands (AT+CMGR, AT+CMGL)

The +CMGL AT command can be used to read all SMS messages stored in the message storage area. To list all SMS in message storage, the command line should be:
List All SMS from SIM to Hyper Terminal

Here are the message details that can be retrieved by the +CMGL AT command in SMS text mode from Hyper Terminal:-

+CMGL: <index>,<stat>,<oa/da>,[<alpha>],[<scts>][,<tooa/toda>,<length>]<CR><LF><data>[<CR><LF>

  • The index specifying the location of the SMS message in the message storage area.
  • Status of the SMS message ("received unread", "received read", "stored unsent", "stored sent", etc).
  • Originator/recipient phone number stored in the SMS message header and the type of the phone number.
  • Text associated to the originator/recipient phone number in the phonebook.
  • Time and date at which the SMS message arrived at the SMSC (available to incoming SMS messages only).
  • Body of the SMS message and its length.

Wednesday - 1 August 2012

Today, my group start to doing receive SMS on GSM Modem. This is some of coding that useful to receive SMS on GSM modem.

AT command
Meaning
+CNMI
New message indications
+CMGL
List messages
+CMGR
Read messages
+CNMA
New message acknowledgement

Delete SMS from Message Storage (AT+CMGD)

The AT command +CMGD (command name in text: Delete Message) is used to delete SMS message(s) from message storage. The message storage area from which SMS messages are deleted is specified by the +CPMS AT command (command name in text: Preferred Message Storage).

AT+CMGD=index[,flag]

The SMS specification has defined these flag values: 0, 1, 2, 3 and 4.

  • 0. Meaning: Delete only the SMS message stored at the location index from the message storage area. This is the default value.
  • 1. Meaning: Ignore the value of index and delete all SMS messages whose status is "received read" from the message storage area.
  • 2. Meaning: Ignore the value of index and delete all SMS messages whose status is "received read" or "stored sent" from the message storage area.
  • 3. Meaning: Ignore the value of index and delete all SMS messages whose status is "received read", "stored unsent" or "stored sent" from the message storage area.
  • 4. Meaning: Ignore the value of index and delete all SMS messages from the message storage area
Delete SMS on SIM using AT Command


Tuesday - 31 July 2012

Continue task on sending SMS from GSM Modem. This is the simple program code to sending GSM modem. GSM doesn't response anything before because MAX232 IC was damaged. Today, i try the simple program code to ensure that the GSM modem is OK.


#include <pic.h>
#fuses hs, nowdt, noprotect, nobrownout
#use delay(clock=20000000)
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=GSM)

#int_rda
void serial_isr()
{
   char c;
   c=fgetc(GSM);
}

void main()
{
    enable_interrupts(INT_RDA);
    enable_interrupts(GLOBAL);
   
    fprintf(GSM, "AT\n\r");
    delay_ms(15000);
    fprintf(GSM, "AT+CMGF=1\n\r");
    delay_ms(3000);
    fprintf(GSM, "AT+CMGS=\"+6**********\"\n\r");
    delay_ms(3000);
    fprintf(GSM, "hello FROM mcu");
    putc(26);
}

Monday - 30 July 2012


Serial Communication trough RS232 cable

Simple program code for Serial Communication

#include <pic.h>
#use delay(clock=20000000)
#fuses hs, nowdt, nolvp, noprotect
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7, parity=n)

int mystatus=0; //here can't declare byte coz not detected by compiler
char mydata;

void main()
{
int count=0;

set_tris_c(0b10001000); //here c6 must be 0, c7 must be 1 (input)
printf("Enter your character : A or S or Z or X");

while(true)
{
if(kbhit()) //monitor incoming charactor from RS232
{
   mydata=toupper(getch()); //receive charactor dan save in mydata
   printf("\n\rYou entered: %c",mydata); //display on hyper terminal
   count++;
   mystatus=1;
}
if (mystatus==1)
{
if(mydata=='A')
{
    output_high(pin_c4); //led on
}
if (mydata=='S')
{
    output_low(pin_c4); //led off
}
if (mydata=='Z')
{
    output_high(pin_c1); //buzzer on
}
if (mydata=='X')
{
    output_low(pin_c1);  //buzzer off
}
mystatus=0;
}//end if
}//end while
}//end void main

Explanation for Example Program Code Above

  • Kbhit ()
Kbhit () is use to check or monitor the incoming character from hardware RS232. When a key is pressed, this function will returns to true or non-zero. When nothings pressed, kbhit () will returns false or zero.

  • Toupper ()
Toupper () is special function to convert input lowercase letter to uppercase letter. If the input data is ‘a’ so that the toupper () will convert the character to uppercase ‘A’.

  • Getch ()
Getch () is returns an 8-bit character. This function is to gets a single-byte (8-bit) character from the terminal. This functions only allow a single character as an input from hardware RS232 to the PIC 16F877A.

Wednesday, 25 July 2012


Example coding to know the response from GSM Modem.

#include <pic.h>
#use delay (clock=20000000)
#fuses hs,nolvp,nowdt,noprotect,nobrownout
#use rs232(baud=9600, bits=8, xmit=pin_C6, rcv=pin_C7, parity=n, stream=GSM)
#byte porta=5
#byte portb=6
#byte portc=7
#include "flex_lcd.c"

volatile int  counter_search=0;            //counter to traverse the array
volatile int  counter_read=0;             //counter to fill the array
volatile Char Recieve_String[70];   //buffer for incoming data
int GET_OK(int Stop_Search);             // Just searches for an OK.
int TEST_AT();

void main()
{
       
         set_tris_a( 0x00 );     // to avoid floating pins
         set_tris_b( 0x00 );
         output_b(0X00);
         set_tris_c( 0x80 );
       
         enable_interrupts(INT_RDA);  // enable RDA interrupts
         enable_interrupts(GLOBAL);   // enable global ints
       
         delay_ms(500);
         lcd_init();
         lcd_gotoxy(3,1);
         lcd_putc("GET RESPONSE");
         delay_ms(1000);
       
         delay_ms(1000);
         TEST_AT();

}

int TEST_AT()
{
         counter_read=0;

         lcd_gotoxy(8,2);
         lcd_putc("AT");
         printf("AT\n\r");                //send command

         While(counter_read<=8)             //"A T \R \R \N O K \R \N" characters returned by modem
         {
         }

         counter_read=0;
         Delay_ms(500);

         if(GET_OK(0X0A))
         {  lcd_gotoxy(8,2);
            lcd_putc("OK");
            return(1); }
         else return(0);

}

int GET_OK(Stop_Search)
{
         counter_search=0;

         while((Recieve_String[counter_search]!='O')&&(counter_search<Stop_Search))
         {
            counter_search++;     //obvious
         }

         if((Recieve_String[counter_search]=='O')&&(Recieve_String[counter_search+1]=='K'))
         {
            counter_search=0;
            return(1);
         }
         return(0);
         counter_search=0;
}

#int_RDA
void RDA_isr()
{
   Recieve_String[counter_read]=getchar(GSM);
   counter_read++;
   if(counter_read==69)
      counter_read=0;
}

Tuesday, 24 July 2012

find info I to V converter dgn btol kn cct connection

Monday, 23 July 2012

btol kn cct in ares..tmbah voltage regulator