GSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLER

View with images and charts

GSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLER

Introduction

1.1 General Introduction:

PIC 16F877A is a very powerful and popular microcontroller. A lot of electronic gadgets can be controlled using a microcontroller. The microcontroller can be programmed using assembly language. However, because of extensive use of microcontrollers in embedded systems, compilers from different vendors are also available that produce machine code (absolute or HEX) files from C, Basic, Pascal etc. For this project we have used flow code programming, the flowcode is first processed into C code, then into Assembler, and finally into hexadecimal numbers or ‘Hex’. As The PICmicro device ‘understands’ Hex code.

The GSM 1308 modem, which has been controlled in this project is a compact, stand-alone wireless IP(GSM/GPRS) modem. It is also a radio transmitter and receiver contains a active SIM card and an antenna at the separation distance of at least 20cm between the antenna and the body of the user. This modem can utilize the input power ranging from 6Vdc to 40Vdc. We have used for this project the input power of 12Vdc. To connect the modem with a local computing device, one end (male end) of the 9-wire RS232 serial cable need to connect to the Modem port labeled “serial” and other end to the computer.

1.2 Project Objective:

The aim of this project is to control a GSM 1308 modem using Pic16F877A by improving the flow code microcontroller program that the modem can work as a more general mobile phone.

1.3 Organization of the project:

Different aspects of the project are discussed in different chapters in this project report. Areas covered by different chapters are brief as follows.

The chapter 1 gives introductory details about the project. It also describes the overview, aim of the project.

The chapter 2 elaborates the microcontroller, PIC16F877A used for implementation of the project. It also describes the architecture, memory, Arithmetic logic unit, I/O ports etc.

The chapter 3 describes the Components of E-Blocks, Adding power to E-Blocks, Jumper Setting of E-Blocks. The Setting of the GSM modem, Power characteristics of the Modem and Testing GSM Modem is also discussed in this chapter.

There are two software (Flowcode and PPP) has been used in this project, their basic setting, selection of component, editing of component , setting of command tools box has been described in the chapter 4. The chapter also describes RS232 setting, simulation and compiling procedure. The chapter 5 shows the developed flowcode program for calling system, sending sms, receiving sms by indicating their logic inside the program command tools as well as the theory of each program.

The chapter 6 shows the C and HEX file of the developed flowcode program, which has been created after simulation. It also shows the overall simulations and results of both flowcode software and E-Blocks for speed dialing, taking number from keypad to dial, receiving and sending sms etc.

Finally the chapter 7 brings out the significant conclusion of the entire work.

PIC 16F877A Microcontroller

2.1 Introduction:

The name PIC, (Peripheral Interface Controller), refers to a group of microcontrollers, produced by Arizona Microchip. This is a flexible 40 pin device. The operating voltage of the microcontroller is 5V. A microcontroller is a digital integrated circuit, and consists of central processing unit, memory, input ports output ports. The PICmicro is a digital device, but it can take data in both analogue and digital forms. For optimum flexibility programmers can choose whether certain pins on the PICmicro should be used as analogue inputs, digital inputs or digital outputs.

2.2 PIC 16F877A Architecture:

Figure 2.1: PIC 16F877 Architecture

2.2.1 Memory of 16F877A:

Flash or EPROM

  • EPROM (sometimes referred to as ‘Flash’) memory is the memory where the program you write is stored in.
  • The program you write is ‘compiled’ by your computer to binary code and then downloaded into the Flash memory of the PICmicro
  • The Flash memory of the 16F877 can store up to 8000 program commands.

RAM

  • RAM is the memory where the ‘variables’ (values in your program that alter as your program runs) you declare are stored in.
  • Data from inputs, outputs, analog inputs, calculations etc. is typically stored in variables inside Flowcode.
  • This memory is of the RAM-type. It’s erased every time the power gets cut or a reset occurs.
  • The Flash of the 16F877A can store up to 368 bytes of data.

EEPROM

· EEPROM is the memory where the variables can be permanently stored

· This memory is of the PROM-type. It is preserved every time the power gets cut or a reset occurs.

· The EEPROM of the 16F877A can store up to 256 bytes of data.

2.3I/O Ports:

Figure2.2: PIC 16F877A microcontroller

2.3.1 PORT A (Blue):

  • Only 6 pins of Port A can be used on a 16F877A device
  • RA0-RA5 can be used as digital inputs
  • RA0-RA5 can be used as digital outputs
  • AN0-AN4 can be used as analogue inputs (=5 analogue inputs on port A)
  • The pins of port A are connected to the 9-pin D-type connector of port A on the Multiprogrammer board

2.3.2 PORT B(Green):

  • All 8 pins of Port B can be used on a 16F877A device
  • RB0-RB7 can be used as digital inputs
  • RB0-RB7 can be used as digital outputs
  • An external interrupt pin is possible on RB0
  • An external port interrupt is possible on RB4-RB7
  • The pins of port B are connected to the 9-pin D-type connector of port B on the Multiprogrammer board.

2.3.3 PORT C(violet):

  • Full 8 pins of Port C can be used on a 16F877A device
  • RC0-RC7 can be used as digital inputs
  • RC0-RC7 can be used as digital outputs
  • PWM (Pulse Width Modulation) is possible on RC1 AND RC2
  • Port C also contains a USART (Universal Synchronous – Asynchronous Receiver Transmitter) for serial communication
  • The pins of port C are connected to the 9-pin D-type connector of port C on the Multiprogrammer board.

2.3.4 PORT D(Golden):

  • Full 8 pinsof port D can be used on a 16F877A device
  • RD0-RD7 can be used as digital inputs
  • RD0-RD7 can be used as digital outputs
  • The pins of port D are connected to the 9-pin D-type connector of port D on the Multiprogrammer board.

2.3.5 PORT E (Red):

  • Only 3 pins of Port E can be used on a 16F877 device
  • RE0-RE2 can be used as digital inputs
  • RE0-RE2 can be used as digital outputs
  • AN5-AN7 can be used as analogue inputs (= 3 analog inputs on port E)
  • The pins of port E are connected to the 9-pin D-type connector of port E on the multiprogrammer board

2.4 Current limits of PICmicro:

At some stage the specification of each of the pins of the PICmicro when they are used as digital inputs, analogue inputs, or as analogue inputs. It is quite important to be aware of the limitations of the device when used for switching output devices. Exceeding these values even for a short time may cause permanent damage to the PICmicro.

Maximum current sunk/sourced by any I/O pin : 25mA

Maximum current sunk/sourced by PORTA + PORTB + PORTE : 200mA

Maximum current sunk/sourced by PORTC + PORTD : 200mA

Maximum current out of VSS (Gnd) pin : 300mA

Maximum current into VDD (5V) pin : 250mA

E-Blocks

3.1 About E-Blocks:

E-blocks are small circuit boards each of which consists of a block of electronics that can be snapped together to form an electronic system. There are two kinds of E-block

i. Upstream boards: Upstream’ is a computing term which indicates that this is the board that controls the flow of information in a system. Upstream boards are usually device programmers of some kind.

ii. Downstream boards: Downstream boards are controlled by the upstream board – but information can flow into them and from them. Examples include LED boards, RS232 boards etc

3.2 Components of E-Blocks:

E-Blocks is consisted of by the following components:-

  • EB003 Sensor board
  • EB005 LCD board
  • EB006 Multiprogrammer
  • EB008 7-segment display bard
  • EB014 Keypad

3.2.1 LCD Board (EB005):

Figure3.1: EB005 LCD Board

  • The male D-type connector fits into the Female connector of one of the ports of an upstream board.
  • Data is sent over the 4 data pins
  • Instructions like ‘shift left’ are also sent over the same 4 data pins
  • The RS pin ‘tells’ the LCD whether you are sending Data or Instructions.
  • BE AWARE of the fact that the timing of the data that sent to the LCD is quite critical. It is best to use an LCD in combination with a crystal in the PICmicro.
  • RS232:

Figure3.2: RS232 communicator

The E-Blocks provides an RS232 interface which can be used to facilitate communication between PICmicro microcontroller and third party devices PC serial port, mobile combination system etc.

There are five main parts of the RS232 interface:

1. E-Blocks downstream connector.

2. PC interface.

3. RS232 interface for Third party device.

4. Link selection for RTS, CTS, TX and RX

5. Max232 device

3.2.2Jumper Setting of E-Blocks:

The mobile phone uses the following core E-blocks: Multiprogrammer, keypad, LCD Display, RS232 board, and a GSM terminal unit (modem). The E-blocks jumper setting is given below.

Table 3.1: Jumper Setting of E-Blocks

Board PORT Settings
Keypad D No settings
LCD B Jumpers on DEFAULT
Sensor A Jumpers on DEFAULT
RS232 C CJumpers:

R& TX SELECTION

CTS & RTS SELECTION

1

Patch System wire links:

SPI/DAC C Jumpers:SDO, SDI & SCK SELECTION

A HIP EN SELECTION

1

Patch System wire links:

None

C

3.3 Setting up the GSM modem:

· The GSM modem is the heart of the mobile phone system. It can send and receive signals via the aerial, and can communicate to other systems using RS232 communication protocols.

· The GSM modem requires a mobile phone SIM card with credit on it. Just like any other mobile phone the GSM modem needs a SIM card to work.

· It is also need to be ensure that there is sufficient credit on the SIM card for the messages that will be sent. SIM card credits can be topped up in the same way as topping up a normal mobile phone.

3.3.1 Testing GSM Modem:

Before using the GSM modem with E-Block system it needs to be test by HyperTerminal using different AT Command. The AT command set are given below:

I. AT+CREG? (This command is used to test the GSM setting)

II. AT%CGREG? (This command is used to test GPRS setting)

III. ATD (To dial a number)

IV. ATH (To hung up a dial number)

Figure3.3: Checking of GSM, GPRS Setting, Outgoing & Incoming Call

Project Software

To complete this project there are two software has been used. Their names are given below:

i. Flowcode

ii. PPP

4.1 About Flowcode:

Flowcode allows user to create simple microcontroller applications by dragging and dropping icons on to a flowchart to create simple programs. These programs can control external devices attached to the microcontroller such as LED’s, LCD displays etc.

Once the flowchart has been designed, its behavior can be simulated in Flowcode before the flowchart is compiled, assembled and transferred to a Chip.

4.2 Steps of Flowcode:

To achieve this using Flowcode, the following steps need to be performed:

  1. Create a new flowchart, specifying the microcontroller that the user wishes to target.
  2. Dragging and dropping icons from the toolbar onto the flowchart to program the application.
  3. Adding external devices by clicking on the buttons in the components toolbar, editing their properties, how they are connected to the microcontroller and call macros within the device.
  4. Running the simulation to check that the application behaves as expected.
  5. Transfer the application to the microcontroller by compiling the flowchart to C, then to assembler code and finally to object code.

4.2.1 Creating new Flowchart:

Figure4.1: Creating new Flowchart

· Create a new flowchart by selecting FILE…NEW

· Select the microcontroller that user wish to target from the list presented

· Flowcode will then display the microcontroller in the Microcontroller view and create an empty flowchart to start adding icons.

· User will now see a flowchart appears with a BEGIN and END icon. All flowcharts have these icons.

· By moving the cursor over the Output icon, in the Icon toolbar, and clicking and dragging it over the work area. The normal cursor changes into a tiny copy of the icon.

· By moving it in between the BEGIN and END boxes an arrow will be appeared showing where the Output box will end up.Release the mouse button to drop the Output box in between the BEGIN and END boxes.

4.2.2 Opening an existing Flowchart:

Figure4.2: Opening an existing Flowchart

There are two ways of opening an existing Flowcode flowchart.

1. Selecting the Open option from the FILE menu. This will allow browsing the file user want.

2. Selecting the file from the list of most recently used files in the FILE menu.

3. Double click on a flowchart file in Windows Explorer to launch Flowcode an open the file.

4.2.3 Basic setting of Flowcode Software:

4.2.3.1 Clock setting:

Every microcontroller needs a clock signal to operate. Internally to the device the clock signal controls the speed of operation of the device and each passing clock cycle synchronises the operation of the various internal hardware blocks.

PICmicro microcontroller devices can be clocked in several ways. The methods we are concerned with on this course are principally:

  • Crystal clock
  • RC clock
  • Internal clock

Figure4.3: clock setting

In CHIP…CONFIGURE from the Flowcode menu the setting of clock option I available and a screen will appear like above figure. Notice that Flowcode has remembered that the chip that are programming is the 16F877A. This screen allows user to choose between an external RC oscillation system, or a crystal oscillation system. if RC oscillator is selected than On the Multiprogrammer make sure SW2 is in the RC position. Make sure that SW1 is in the SLOW position. This will clock your PICmicro device at around 100Hz: this is very slow but it will allow you to see each step in your program.

4.2.4 Selection of Components:

Figure 4.4: Selection of Components

In the main program window there is a component toolbox option from their different input such as Keypad, switchbox, switch etc, output such as LED,LCD etc and communication device such as RS232, CAN, CAN2 etc can be selected for program.

4.2.4.1 Editing of Component:

Figure4.5: Editing of Component

· By Clicking once on the component in the panel to select it and the properties pane will display component properties like Figure.

· By clicking once on the next to the ‘Connections’ property. This opens the ‘Specify Component Pin Connections’ dialogue box, like the one shown above. This shows which component is connected to which port, and which bit of the port on the PICmicro chip.

  • Then Click on the arrow by the ‘ Connect to Port’ dialogue box, and select the PORT option in the menu. Than the settings for ‘PIC Port’ and ‘PIC Bit’ change for all eight LED’s.
  • By clicking on the ‘Done’ button the dialogue box will be closed.

4.2.5 Command toolbox setting:

There is a command toolbox on left side in the main window of the flowcode software. To develop the flowcode program the icon toolbar are used. The properties of an icon define how it behaves when compiled/assembled and when simulated in Flowcode. As each icon has different properties that the user can edit. To edit an icon’s properties, either select the icon and the select the Properties option from the Edit menu or simply double click on the icon in the flowchart. The icon’s properties can also be displayed by right clicking on the icon to display a context menu and then selecting properties from that menu.

4.2.5.1 Input Icon properties:

Figure 4.6: Input Icon properties

Input icons check the specified port and/or bits for their value and then place the resulting value into the specified variable.

Display Name: The name of the icon that appears on the flowchart.

Variable: Select the name of the variable that you wish to input the port state into.

Variables button: This button brings up the variables dialog window allowing you to select an existing variable or to create a new one.

4.2.5.2 Output icon properties:

Figure 4.7: properties of output icon

Output icon sends the value or variable to the specified port and/or bits. The output is received at the port in binary format.

Display Name: The name of the icon that appears on the flowchart.

Variable or value: Select the name of the variable or a numeric value that you wish to output to the port. Numeric values can be in decimal (unmarked) or in HEX format (preceded by 0x) e.g. 255 or 0xFF.

Variables button: This button brings up the variables dialog window allowing you to select an existing variable or to create a new one.

4.2.5.3 Decision icon properties:

Figure 4.8: properties of Decision icon

Decision icons allow you to test a condition and redirect the flow according to the outcome.

Icons can be placed in either branch from the decision icon.

Display Name: The name of the icon that appears on the flowchart.

Condition: The decision box tests this condition to see which branch to continue down. If the condition evaluates to 0 or false then the ‘No’ branch is chosen. If the condition evaluates to a non zero number or true then the ‘Yes’ branch is chosen. Conditions can be made up from numbers, variables and operators

Variables button: This button brings up the variables dialog window allowing you to select an existing variable or to create a new one.

Swap Yes and No: Normally the ‘Yes’ path of execution goes off to the right of the decision icon and the ‘No’ path carries on down the flowchart. Select this option to swap the two branches around.

4.2.5.4 Loop icon properties:

Figure 4.9: properties of Loop icon

Loop icons are used to repeat a task until specified conditions are fulfilled, or to perform the loop a set number of times.Note that you will need to add calculation icons that modify the variables used for the condition in order for the condition to be fulfilled.

Display Name: The name of the icon that appears on the flowchart.

Loop while: Loops the program until the specified condition becomes true.Enter the conditions which will fulfill the loop.(Setting the test condition to something that is always true will make the loop repeat forever e.g. While 1)

Variables button: This button brings up the variables dialog window allowing you to select an existing variable or to create a new one.

4.2.5.5 Macro icon properties:

Figure 4.10: properties of Macro icon

Adding a Macro: Select the Macro to use from the list, or click on Create new macro to begin creating a new macro to add to the list.

Variables button: This button brings up the variables dialog window allowing you to select an existing variable or to create a new one.

Return value: If the device macro returns a value then you can assign that value to an existing variable for use later in the flowchart. If the function returns a value but you do not wish to retrieve it then leave this field empty. The variable type of the return value will be listed. A variable of the specified type must be used to accept the return value.

4.2.5.6 Component Macro icon properties:

Figure 4.11: properties of Component Macro icon

Macros have now been split into Macros and Component macros.

Adding a component macro:

· Select the component and macro to use

· Select the component from the list of attached components on the left and select the macro to use from the list on the right.

· Add in any parameters required, and select a return value if required.

Variables button: This button brings up the variables dialog window allowing you to select an existing variable or to create a new one.

Return value:

· If the device macro returns a value then you can assign that value to an existing variable for use later in the flowchart. If the function returns a value but you do not wish to retrieve it then leave this field empty.

· The variable type of the return value will be listed. A variable of the specified type must be used to accept the return value.

4.2.5.7 Calculation icon properties:

Figure 4.12: properties of component icon

Calculation icons allow the modification of variables. They can be used to check inputs and to create outputs.

Display Name: The name of the icon that appears on the flowchart.

Calculations: One or more lines of calculations can be entered into this box

4.2.5.8 String manipulation icon properties:

Figure 4.13: properties of String manipulation icon

The properties box of the String manipulation icon allows users to manipulation, create and edit strings in a similar manner to how the calculation icon allows users to manipulate numeric variables.The variables and Function buttons allow the user to add those elements into the edit box window.

Strings:

· Strings are arrays of BYTE ASCII character values.

· String arrays are composed of the array name and an array element variable.

String manipulation Function:

The String functions are a set of string manipulation functions that can be used to edit, change and examine the strings. Clicking on a function adds the base code to the edit box window. The user can then edit this base code with the variables required.

4.2.6 RS232 setting:

The Flowcode RS232 component includes a properties section that allows the communication baud rate and flow control to be configured. The settings illustrated below should be used for all the exercises.

Figure 4.14: RS232 Component Setting , panel icon and simulator.

· BAUD rate:

The number of data and formatting bits transmitted or received per second

· Hardware flow control mode:

This allows both the controller and the modem to suspend the transmission of data to them until they are ready to handle it. The RTS and CTS lines are controlled by the controller and modem respectively, and used to signal their ability to receive data.

4.2.7 Running the simulation:

Figure 4.15: Running the simulation

To simulate a flowchart, select the Go/Continue option from the Run menu or press F5. Flowcode will go into simulation mode and will start to execute the icons in the flowchart. A red rectangle indicates the icon that is about to being executed.

Step Into:

To simulate the flowchart, icon by icon, select the Step Into option from the Run menu or press the F8 key.

Step Over:

To Step Over a macro select the Step Over option from the Run menu or press the Shift + F8 keys.

4.2.8 Compiling Procedure:

Chips can only execute code that is in hexadecimal (hex.) format. Flowcode needs to process the flowcharts (for example TEST.FCF) into a format that a Chip can execute Flowcode takes a number of steps:

§ Compile Flowchart into C code

§ Compile C code into Assembler

§ Assemble the Assembler into Hex

§ Send the Hex code to the Chip

To send the Hex code into your PICmicro Flowcode runs a subsidiary program called ‘PPP’. When user select CHIP…CONFIGURE from the Flowcode menu the program PPP controls a number of PICmicro options and configurations by setting the value of registers inside the device when user configure a program.

Figure 4.16: Compiling Process

The Hex code is ‘burned’ into the program memory of the PICmicro chip. Remember that EPROM Memory is used to form the program memory? This means that the program is not lost when the PICmicro chip is removed from the programmer, allowing user to use the PICmicro in a circuit. Equally, the use of EPROM type memory means that user can reuse the PICmicro, and overwrite the program memory with a new program.

4.3 PPP:

Figure 4.17: PPP software

The PICmicro Parallel Programmer (PPP) has been developed by Matrix Multimedia Ltd. to allow easy programming of their PICmicro development systems. PPPv3 will accept 8-bit Intel HEX format files (as produced by MPASM). PPPv3 can be used on it’s own as a stand alone program, or it can be incorporated into a programming environment to provide a seamless flow from code to chip.

PPP is simple to use. At it’s heart are just three steps.

4.3.1Open the HEX file:

Figure 4.18: Open the HEX file

Use the OPEN button on the Toolbar, or the OPEN option in the File menu to open a HEX file.

4.3.2 Configure the PICmicro:

Figure 4.19: Configure the PICmicro

Open the Configuration screen and select the PICmicro, and set any required options.

Click on the CONFIGURE PICMICRO button on the Toolbar, or use the CONFIGURE PICMICRO option in the View menu.

See Configuring the PICmicro for more information.

4.3.3 Send the program:

Figure 4.20: Send the program

Finally send the program to the PICmicro.Click on SEND button on the Toolbar, or use the SEND TO PICMICRO option in the File menu to See Sending to the PICmicro for more information.

Developed Program

5.1 Introduction:

In this Project a simple telephone has been developed that is capable of dialing a number taking from Keypad, answering an incoming call by developing a macro to detect the presence and persistence of the ‘RING’ message as the indication of an incoming call, moving the system between state 0 (IDLE) and state 1 (RINGING) automatically, and terminating a connection (hanging-up). The functions will be manually controlled using individual buttons on the keypad module.

5.2 Program for calling system:

When the modem detects an incoming call it transmits the message “RING” at regular intervals (approximately 2 seconds). If the controller is able to detect this character sequence being received by the RS232 port, it can automatically control transitions between the IDLE and RINGING states. Both the IDLE and RINGING states must ‘listen’ for the “RING” message and perform the following actions:

IDLE

“RING” message detected:

· Initialize a timer with a period greater that the expected time between “RING” messages.

· Move the system to the RINGING state

RINGING

“RING” message detected:

· Re-initialize the timer with a period greater that the expected interval between “RING” messages – preventing a time-out while the messages are being received.

Timer timed out:

· Move the system back to the IDLE state

Call answered ( * key pressed):

· Send the ATA message to the modem

· Move the system to the CONNECTED state

5.2.1 Main Program:

This is the main program for dialling, receiving and disconnecting a call.

(i) (ii)

(iii)

(iv)

(v) (vi)

5.2.2 Main Program’s Tx Macro:

The Tx_Command macro has been used to send any command to modem through RS232 and also detect echoed characters.

5.2.3 Main Program’s Rx Macro:

Rx_Message macro has been used to perform the message detection function and use a non-zero value of the Rx_done variable to force the main program to test the message in Rx_Buffer.

5.3 Program for sending sms:

The AT+CMGF command sets the format of the test messages and most of the modem responses.

Text messages can be delivered in compressed PDU (Protocol Data Unit) format. This format is efficient (7 bits per character), but can be difficult to decode into readable text. Text format uses a standard, 8-bit ASCII code for each message character; these can be transferred directly into string variables.

The AT command required to configure this option is Message Format command:

AT+CMGF=1

The AT command to send a text message is:

AT+CMGS=<”number”>

The modem responds by transmitting a ‘<CR><LF>> ’ message when ready( note the space after the > character and the absence of a <CR> or <LF> character as termination) – this would indicate the start position of the text if the system was being controlled from a terminal screen and keyboard.

The message text can be transmitted to the modem after receipt of the ‘> ’ characters, and the whole sequence is terminated with the <CTRL-Z> character – value 26: a historic “End Of File” marker.

5.3.1 Main program:

(i)

(ii) (iii)

5.3.2 Main Program’s Tx Macro:

The original Tx_Command macro transmits a <CR> character at the end of each command string. There are now a number of requirements for strings to be transmitted without the automatic addition of <CR>. This will allow commands to be sent to the modem in sections with the <CR> only being added to the last section. A byte variable (Send_CR) has been used to control the transmission of the <CR> character by the Tx_Command macro.

5.3.3 Main Program’s Rx Macro:

Detection of the “> “characters cannot be achieved with the existing Rx_Message macro due to the absence of a <CR> character. So The Rx_Message macro has been now modified by creating term_ch variable to use a character supplied by the main program to detect the completion of a message ,or message segment. Now The macro will compare each received character with Term_ch, instead of <CR>, but perform the same message completion functions as previously developed. As before, <CR> and <LF> must not be added to the Rx_Buffer string. The value of Term_ch might need to be changed regularly, depending on the expected messages.

5.4 Program for receiving sms:

A text message is received as a stream of characters that include large amounts of data in addition to the original text. The AT command required to achieve this is the New Message Indication command:

AT+CNMI=2,2

The incoming message has been spliced into segments using the RX_Message macro. Correct selection of the termination character will allow the required information to be isolated and extracted. A simple state machine has been used to count the message segments, control the operation of the program, and select the appropriate termination character.

A byte variable (SEGMENT) has been used to control the message segment detection function.

Detection of the message header has been achieved by setting the RX_Message terminator character to ‘ ‘ (the space character). When the macro indicates a message reception the buffer string will compare with “+CMT:“.

If the +CMT: header is detected, the program will increment the SEGMENT value and progress to detection of the caller ID, date, and time. The information is not required for LCD l, so by setting the delimiter character to <CR> will retrieve all the characters in a single operation.

Detection of the first <CR> character will allow the SEGMENT variable to be incremented, indicating that the following data will be the original text message.

Detection of the second <CR> character will indicate completion of the message reception, allowing the SEGMENT value to be reset to the header detection value and the delimiter character to be reset to ‘ ‘. The original text message will be stored as a string in Rx_Buffer, allowing it to be displayed, tested, or manipulated, as the application requires (displayed in this case).

5.4.1 Main program:

(i)

(ii)

5.4.2 Main Program’s Rx Macro:

Simulation and Result

After simulating the developed program for calling, sending sms and receiving sms C and HEX file has been created. The C and HEX files are too long so some portion of that files for every program are given below.

6.1 C and HEX files of calling system:

The C and HEX file which has been created after simulation are given below:

6.1.1 C file:

#define MX_PIC

#define MX_CLK_SPEED 19660800

#ifdef _BOOSTC

#include <system.h>

#endif

#ifdef HI_TECH_C

#include <pic.h>

.

.

(0)::PrintString(“TALK”)

FCD_LCDDisplay0_PrintString(“TALK”,4)

}

} else {

//Set IDLE state

//Calculation:

// STATE = 0

FCV_STATE = 0;

//Clear LCD

LCDDisplay(0)::Clear

FCD_LCDDisplay0_Clear();

//Call Component Macro: LCDDisplay(0)::PrintString(“MISSCALL”)

FCD_LCDDisplay0_PrintString(“MISSCALL”,8);

}

}

//CONNECTED state

if (FCV_STATE == 2)

{

//Test keypad

//Call Component Macro: Key_val=KeyPad(0)::GetKeypadAscii

FCV_KEY_VAL = FCD_KeyPad0_GetKeypadAscii();

if (FCV_KEY_VAL == ‘*’)

{

//Make ATH string

//String Manipulation:

// COMMAND = “ATH”

FCI_CONCATENATE(“ATH”,3,””,0,FCV_COMMAND,FCSZ_COMMAND);

//Send ATH string

//Call Macro: Tx_Command

FCM_Tx_Command();

//Call Component Macro

//Call Component Macro: LCDDisplay(0)::Clear

FCD_LCDDisplay0_Clear();

//Clear LCD

//Call Component Macro: LCDDisplay(0)::PrintString(“CALL TERMINATED”)

FCD_LCDDisplay0_PrintString(“CALL TERMINATED”,15);

//Set IDLE state

//Calculation:

// STATE = 0

FCV_STATE = 0;

}

}

}

mainendloop: goto mainendloop;

}

void MX_INTERRUPT_MACRO(void)

{

}

6.1.2 Hex file:

:040000008A15622AD1

:08000800FF00030E8316031331

:10001000D8000A0ED900040EDA008A150A128C2ABA

:10002000000000009C0B10280800AA08031D1928D6

:10003000080009300000FF3E031D1A2800000000E0

:100410000F2A9608031D0F2A01309E00192A170380

.

.

:10044000FF2902309E00FF291E08023A031D462A9A

:10150000D401D501D601D701E001E101DF018A153F

:101510000A1221228A11382D831603135A0E8400D1

:0E152000590E8A00580E8300FF0E7F0E090040

:02400E003A3F37

:00000001FF

6.2 C and HEX files of sending sms:

The C and HEX file which has been created after simulation are given below:

6.2.1 C file:

#define MX_PIC

//Defines for microcontroller

#define P16F877A

#define MX_EE

#define MX_EE_TYPE2

#define MX_EE_SIZE 256

#define MX_SPI

#define MX_SPI_C

#define MX_SPI_SDI 4

.

(0)::PrintString(TEXT)

FCD_LCDDisplay0_PrintString(FCV_TEXT,FCSZ_TEXT);

}

}

if ((FCV_DONE == 0) == 0) break;

}

//Calculation

// term_ch = 13

FCV_TERM_CH = 13;

//Call Macro: Rx_Message

FCM_Rx_Message();

mainendloop: goto mainendloop;

}

void MX_INTERRUPT_MACRO(void)

{

}

6.2.2 Hex file:

:020000006A2E66

:08000800FF00030E8316031331

:10001000D8000A0ED900040EDA008A110A12932EB3

:10002000000000009D0B10280800A408031D1928DB

:10003000080009300000FF3E031D1A2800000000E0

:10004000A40B192808001B089F009E0103109F0D98

:100050009E0D9F0D9E0D9F0703189E0A9F07031874

:100060009E0A3C309F0703189E0A00301E078A0034

.

.

:10094000A500AB0046309A004D309F005030A60005

:10095000533096006230A1006530A400AA00B000B8

:100960006830A7006930A2006C30A3006D3097009A

:100D20000A122926882C831603135A0E8400590EA2

:0C0D30008A00580E8300FF0E7F0E0900A1

:02400E003A3F37

:00000001FF

6.3 C and HEX files of receiving sms:

The C and HEX file which has been created after simulation are given below:

6.3.1 C file:

#define MX_PIC

//Defines for microcontroller

#define P16F877A

#define MX_EE

#define MX_EE_TYPE2

#define MX_EE_SIZE 256

#define MX_SPI

#define MX_SPI_C

#define MX_SPI_SDI 4

#define MX_SPI_SDO 5

#define MX_SPI_SCK 3

#define MX_UART

#define MX_UART_C

.

.

.

.

.

.

(0)::PrintString(Rx_buffer)

FCD_LCDDisplay0_PrintString(FCV_RX_BUFFER,FCSZ_RX_BUFFER); //Calculation

//Calculation:

// msg_seg = 0

// term_ch = ‘ ‘

FCV_MSG_SEG = 0;

FCV_TERM_CH = ‘ ‘;

}

}

}

}

mainendloop: goto mainendloop;

}

void MX_INTERRUPT_MACRO(void)

{

}

6.3.2 Hex file:

:020000001C2DB5

:08000800FF00030EFC000A0ECC

:0C001000FD00040EFE008A110A12452DAE

:1000200000000000C10B10280800C308031D192898

:10003000080009300000FF3E031D1A2800000000E0

:10004000C30B1928080083160313DA010230DB0002

:100050001030DC006F30DD00E001DD08031908001E

:100060005C08DE00DF015B18DE17DB185F1483130A

:100070005F1883175E0884000008E100E11B742804

:100080007F306105E20062086002031849286208B7

:10018000DB001030DC006F30DD00DD08031936299C

:1006500056088000D20A162B4F085406031D342B6F

:10066000500855060319392B5408D6005508D700F1

:10067000AD205308D6000800C901CA0144084A0247

:1006800003189E2B47084A0203188E2B83133D182C

:1006900083173C084A0784000008CB0083134618E0

:1006A000831745084A0784000008CC004B02031852

:1006B0006F2BC80803196C2B61304C02031C6C2B88

:1006C0004C087A3C031C6C2BDF304B05CD00DF302F

:1006D0004C054D060319892BFF30CE0008004B084E

:1006E0004C020318892BC8080319862B61304B0272

:100A3000BF00E42CBF01E42CD530F000C430F1003D

:100A4000BB30F200DC30F300F401F501F601F701F0

:100A5000F801F901FA01FB0183160313A001A101BA

:100A6000A201A301AD01AE01A801A901AF01B0012E

:100A7000B101B201A401A501A601A701AB01AC011E

:100A8000AA018A110A12DB242E2C7E0E84007D0E10

:0C0A90008A007C0E8300FF0E7F0E090020

:02400E003A3F37

:00000001FF

6.4 Software Output:

The developed program has been run using the flowcode software those output are given below:

6.4.1 Speed dialling (out going call):

The program has been developed to allocate different phone numbers to more of the numeric keys on the keypad module; creating a useful ‘speed dial’ phone.

Figure 6.1: Software Output for Speed dialling

This speed dialling output from flowcode software simulation is showing a dialled number “01717253772” after pressing the “2” key on keypad. When we will press ‘*’ key than a AT command will send to modem with this mobile number as “ATD01717253772”, Similarly for every key on key pad a mobile number has been assigned for speed dialling.

6.4.1 Speed dialling call termination:

Figure 6.2: Speed dialling Call termination

The above figure is showing that if we press ‘*’ key on keypad the dialling call will be terminated by sending a AT command that is “ATH” to Modem.

6.4.2 Taking and Dialling a Number from Keypad:

Figure 6.3: Dialling a Number from Keypad

When the main program of calling system is being executed than if we press the ‘5’ key on keypad a option will be appeared showing “Enter No” on Software LCD .than we have to enter a mobile number which will be saved in a variable named “K_Buffer”.

Figure 6.4: Dialing Number from Keypad

Now if we press the ‘#’ Key on keypad, the entered number will be dialled By a AT command that is “ATD01739128450;”

6.4.3 Sending of sms:

Figure 6.5: Sending of sms by taking Number from keypad

This figure is showing that sms is sending to “01717253772” taking number from keypad by pressing ‘#’ on the keypad than a preloaded sms will send from a Variable Named ‘TEXT’. When we will press the ‘#’ key a AT command that is “AT+CMGS=<”01717253772”> ” is sent to the modem.

6.5 E-Blocks output:

The developed program has been compiled into multi programmer chip using the PPP software those output are given below:

6.5.1 Speed dialling:

The program has been developed to allocate different phone numbers to more of the numeric keys on the keypad module, creating a useful ‘speed dial’ phone.

Figure 6.6: Software Output for Speed dialling

This speed dialling output from E­-Blocks system is showing a dialled number “01717405762” after pressing the “0” key on keypad. When we will press ‘*’ key than a AT command will send to modem with this mobile number as “ATD01717405762”, Similarly for every key on key pad a mobile number has been assigned for speed dialling.

6.5.1.1 Speed dialling call termination:

Figure 6.7: Speed dialling Call termination in E-Blocks

The above figure is showing that if we press ‘*’ key on keypad in E-Blocks the dialling call will be terminated by sending a AT command that is “ATH” . It is also showing a message on E-Blocks LCD that “CALL TERMINATED” and a “1MISSED CALL” indication on the dialled mobile.

6.5.2 Taking and Dialling a Number from Keypad:

Figure 6.8: Taking a number from keypad

When the main program of calling system is being executed than if we press the ‘5’ key on keypad a option will be appeared showing “Enter No” on Software LCD .than we have to enter a mobile number which will be saved in a variable named “K_Buffer”.

Figure 6.9: Dialling a number from keypad

Now if we press the ‘#’ Key on keypad, the entered number will be dialled By a AT command that is “ATD01710036458;”

6.5.3 Incoming call:

Figure 6.10: Incoming call

The figure is showing an incoming indicating the caller Id number that is “01717405762” form a the remote caller mobile phone. Now if we press the ‘#’ key on the keypad the incoming call will be received by sending a AT command to modem as “ATA”.

Figure 6.11: Incoming call not answered

The above figure shows that if we don’t receive the incoming call than after call end a message will be appear on LCD as “MISSCALL”.

6.5.4 Sending of sms:

Figure 6.12: Message Sending

This figure is showing that sms is sending to “01717405762” taking number from keypad by pressing ‘#’ on the keypad than a preloaded sms will send from a Variable Named ‘TEXT’. When we will press the ‘#’ key a AT command that is “AT+CMGS=<”01717405762”> ” is sent to the modem.

6.5.5 Receiving of sms:

Figure 6.13: Receiving message

The figure is showing received message from a remote mobile phone.

Conclusion

In this project a GSM1308 has been controlled by a PIC16F877A microcontroller with E-Blocks system by Flowcode programming. The Flowcode software and the PIC16F877A have different options of the input clock; if the both clock setting does not match the program will not work. There are three existing program has been modified separately for calling, sending and receiving sms which is necessary to developed a general phone. The microcontroller worked with HEX file so at first the flowcode has been compiled to C file than HEX file. After compiling the HEX file to chip it is found that the GSM modem with E-Block system is working like a general phone. But it works slowly because of during the execution of large program the device faces some delay as its fixed clock speed and also for limitation of LCD display and KEYPAD.

Reference:

[1] www.matrixmultimedia.com

[2] www.matrixmultimedia.com/usersuport

[3] www.datasheetsite.com/datasheet/PIC16F877A

[4] John peatman: Design with PIC Microcontroller

[5] E Blocks User guide, Qty Code: EB355

[6] An Intro to Microcontroller Programming, Qty Code: ELFCS2SI

[7] Mobile phone module GM28 or GM29, Qty Code: EB182

[8 ] Mobile phone solution Course Notes, Qty Code: EB463

[9] en.wikipedia.org/wiki/Wireless modem

[10]www.enfora.com