Exploring PIC 24F Series Microcontroller PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

JOURNAL OF CURRENT RESEARCH IN SCIENCE JCRS

ISSN 2322-5009 4 (2), 2016: 164-176


CODEN (USA): JCRSDJ
Available at www.jcrs010.com

Exploring PIC 24F series Microcontroller using MPLAB and Proteus


Sohaib Aslam1*, Sundas Hannan2, Arsalan Haider3, Mohammad Hamza Tariq 4

Department of Electrical Engineering, Superior University, Lahore, Pakistan.


Corresponding Author email: [email protected]

K E Y W O R D S: Interrupt Service Routine (ISR), Keypad, Liquid Crystal Display (LCD), Univeral Asynchronous
Receiver Transmitter (UART), Pulse Width Modulation (PWM), PORT

ABSTRACT: This paper aims at explore the working of a 16-bit Peripheral Interface Controller (PIC) 24F
series microcontroller using MPLAB IDE and Proteus Professional software. PICs are cost-effective
microcontrollers and provide a large number of applications in educational and industrial areas. 16-bit PIC
microcontrollers are not explored to the best potential for their hands on experience in educational and industrial
sectors. The research work demonstrates the functioning different sections of the microcontroller. Firstly Ports A
and B are initialized to use for Input-Output (I/O) interfacing. Then timers are briefly explained and simulated
for specific applications. Basic methodology of calling interrupts is defined using simulations. Pulse Width
Modulation (PWM) is generated using Output Compare Module (OCM) of microcontroller. Interfacing of the
microcontroller with Liquid Crystal Display (LCD) and Keypad through I/O ports is presented and finally
Universal Asynchronous Receiver Transmitter (UART) based asynchronous serial communication at 115200
baud rate through PIC microcontroller is done in Proteus.

Introduction
Field of embedded systems is playing an important role in facilitating the modern society. A wide range of
embedded systems are present in every sector of life like telephones, cell-phones, cameras, fax machines, baby toys,
industrial control systems, medical testing systems, life support systems, avionics systems and many more (Miha &
Mihael, 2008). Majorly embedded systems are based on microcontrollers. Current microcontrollers can perform operations
based on hundreds of thousands of transistors. Initially microprocessors had no built in peripherals like memory, I/O lines
and timers etc (Yousif, 2012). After some period of time a new device called integrated circuit (IC) came, which contains
both processor and peripherals. This IC was called microcontroller (N.Barsoum, 2010). Peripheral Interface Controllers
(PICs) developed and marketed by Microchip technology, Inc. are cost effective units with built in central processing unit
(CPU), I/O functions, memory and timers etc (S.H.LEE et al, 2004). In 1989 first 8-bit PIC microcontroller with small
amount of data ram, data rom , one timer and small number of I/O lines on single 8-pin IC was introduced. It is surprising
to see that within a decade Microchip becomes the top ranked supplier of 8-bit controllers (M.A.Mazidi et al, 2008). The
PIC developers introduced number of families of 8-bit controllers. i-e 10xxx, 12xxx, 14xxx, 16xxx, 17xxx and 18xxx. In
8-bit microcontrollers PIC18xxx has the highest performance among the PIC families and other famous 8-bit controller
manufacturers (M.A.Mazidi et al, 2008). In recent years, with the advancement in technology and requirement of high
performance in different industrial and educational projects microchip introduces 16-bit microcontroller families. These
families include 24F, 24H, dspic30F and dspic33F. PIC 24F series provides a significant increase in performance from
PIC 18xxx series with a slight cost impact (D.Schneider, 2006). In this research work working of PIC24FJ128GA010
microcontroller in different aspects is demonstrated by first developing the algorithm and generating the hex file using
MPLAB microchip developing tool and then simulating the controller in Proteus Professional. In section 2
PIC24FJ128GA010 is precisely discussed. Section 3 deals with the software tools. Ports are initialized in section 4. Timers
and Interrupts are elaborated in section 5. PWM is done in section 6. LCD and Keypad interfacing with I/O Ports of
microcontroller is elaborated in section 7. Section 8 reveals the asynchronous serial communication using UART. Finally
conclusion is summarized in section 9

PIC24FJ128GA010 Microcontroller
PIC24FJ128GA010 belongs to CMOS family with low power consumption because of power management modes
i-e sleep, idle and alternate clock modes. Its operating voltage range is 2.0 V -3.6V. it is a general purpose 100-pin
microcontroller with a modified Reduced Instruction Set computer (RISC) architecture which can operate at up to 32
MHz crystal oscillator with speed of 16 Mega Instructions Per Second (MIPS) (PIC Datasheet, 2006). The controller has a
C compiler optimized instruction set mechanism with dynamic addressing modes (S.Aslam , 2015). PIC24FJ128GA010
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

has a data memory bus of 16-bit wide while program memory bus of 24-bit wide. Its general block diagram is shown in
Figure 1.

Figure 1. PIC24FJ128GA010 General Block Diagram

165
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

It has 128 Kilo Bytes (KB) of program memory, 8KB of RAM data memory, five 16-bit timers/counters with
built in programmable prescaler. It also provides seven communication modules these are I2C, UARTs, SPIs and one
Parallel Master Port (PMP) (L.D.Jasio, 2007). The peripheral features of PIC24F family are summarized in Table 1 (PIC
Datasheet, 2006).

Table 1. Peripheral Summary of PIC24F Family

16-bit

10-bit
Input

Comparators
I2C
Timers
Device

PWM Output
(Bytes)

(Bytes)

Capture

Compare/

SPI

A/D (ch)
Pins

PMP/PSP
UART
ROM

RAM

JTAG
PIC24FJ64GA006 64 64k 8k 5 5 5 2 2 2 16 2 Y Y
PIC24FJ96GA006 64 96k 8k 5 5 5 2 2 2 16 2 Y Y
PIC24FJ128GA006 64 128k 8k 5 5 5 2 2 2 16 2 Y Y
PIC24FJ64GA008 80 64k 8k 5 5 5 2 2 2 16 2 Y Y
PIC24FJ96GA008 80 96k 8k 5 5 5 2 2 2 16 2 Y Y
PIC24FJ128GA008 80 128k 8k 5 5 5 2 2 2 16 2 Y Y
PIC24FJ64GA010 100 64k 8k 5 5 5 2 2 2 16 2 Y Y
PIC24FJ96GA010 100 96k 8k 5 5 5 2 2 2 16 2 Y Y
PIC24FJ128GA010 100 128k 8k 5 5 5 2 2 2 16 2 Y Y

Software Tools
The software tools used in this research work to develop the applications for PIC microcontroller and simulate
them are MPLAB and Proteus respectively. They are precisely discussed below

MPLAB IDE
MPLAB Integrated Development Environment (IDE) is best described as software to develop programs for PIC
microcontrollers. It is called IDE because development, debugging and software services are simultaneously available on a
single platform (MPLAB Guide, 2004). The Language tools offered by MPLAB include Assembler (MPASM), Linker
(MPLINK) and a C compiler (MPLAB C30) (M.A.Mokhtar, 2009). The latest version available at the time of this writing
is MPLAB X IDE but in this research work MPLAB 8.10 version with C 30 compiler is used. The steps required to
develop a program for the PIC controller and generate hex file using MPLAB is shown in Figure 2 (S.K.Arvind et al,
2014).

Step 1
Open MPLAB

Step 2
Project Wizard

Step 3
Chose
PIC24Fj128GA010

Step 4
Chose C30 Compiler

Step 5
Open Source File

Step 6
Write Code and Save

Step 7
Add source and link
file

Step 8
Select Build Project

Figure 2. Steps to develop program for PIC microcontroller

166
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

Proteus
Proteus is sophisticated Electronic Design Automation (EDA) simulation software. The enormous device library
and large range of peripherals are the special advantage of this simulator. The virtual instrumentation feature provides a
great opportunity for simulation of microcontroller units. Proteus Virtual System Modeling (VSM) combines mixed mode
SPICE circuit simulation, animated components and microprocessor models to facilitate complete simulations of
microcontroller based designs. For the first time ever, it is possible to develop and test such designs before a physical
prototype is constructed (J.Chen, 2011). The steps required to simulate microcontroller based applications in Proteus are
shown in Figure 3.

Step 1
Open Proteus

Step 2
Select ISIS

Step 3
Select Component
Mode

Step 4
Select Component

Step 5
Implement Circuit

Step 6
Select Properties of
Microcontroller

Step 7
Browse Hex File

Step 8
Simulate

Figure 3. Steps to Simulate PIC microcontroller

Start

Include header file


p24fj128ga010

Main ()
Initialize
TRISA,TRISB,AD1PC
FG

While(1)
Move data to both
ports

End

Figure 4. Algorithm Sequence for PORTA and PORTB

Ports Initialization
Port is a set of pins on a microcontroller which represent physical connection of Central Processing Unit (CPU)
with the outer world and microcontroller utilizes them to control or monitor other systems (N.Matic, 2003). There are six

167
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

ports in PIC24FJ128GA010 they are A, B, C, D, E, F and G. All these ports can be used as inputs or outputs according to
the requirement of the application of microcontroller. . By default all Port B pins are multiplexed with analog inputs so to
use them as output they must be connected to digital inputs (L.D.Jasio, 2007). To initialize ports as input or output and to
connect Port B pins to digital inputs TRISX and AD1PCFG control registers are used where X identifies port. By default
at reset all I/O pins are configured as input so to initialize Port as output 0x0000 must be sent to TRISX and to connect I/O
pins to digital inputs 0xFFFF is sent to AD1PCFG. In this section Port A and Port B are initialized as outputs and Port B
pins are connected to digital inputs so that information on Port B pins can be read by external device then toggling of first
4 pins of both ports are done. The program is developed in MPLAB using the following command sequence shown in
Figure 4.
In the first step of Figure 4. header file of PIC24FJ128GA010 is included which is not a proper c statement but a
pseudo- instruction for the pre-processor to read the device related information before proceeding further. In main function
initialization of control registers is done and finally the given data is sent to the output via both ports. The simulations of
PORTS A and B are done in proteus and shown in Figure 5.

(a) Implementation of Circuit Diagram in Proteus (b) Toggling of PORTA and PORTB
Figure 5. Simulation of PORTA and PORTB in Proteus

In Figure 5(a) implementation of circuit diagram in proteus is shown and Figure. 5(b) shows the toggling of first
four pins of both ports on digital oscilloscope using the VSM feature of proteus.

Timers and Interrupts


Description of timers and interrupt mechanism for PIC24FJ128GA010 is discussed below.

Timers
Timers are the basic peripherals of each microcontroller and provide number of features like timer, counter,
internal and external interrupts and A/D event trigger (Z. Milivojević & D. Šaponjić, 2008). PIC24FJ128GA010
microcontroller offers five 16-bit timers while timer 2/3 and timer 2/4 can also be used together to give 32-bit timer or
counter. The working modes and different features offered by timers are activated by the appropriate bits in TXCON
control registers (PIC Datasheet, 2006). In this section application of timer 1 to generate delay is first elaborated then
developed and finally simulated. Two special function registers are used in timer 1 applications they are TMR1 a 16-bit
counter and PR1 to produce a periodic reset mostly used for interrupt purposes (L.D.Jasio, 2007). T1CON is a 16-bit
control register shown in Figure 6 (L.D.Jasio, 2007).

Figure 6. T1CON: Timer 1 Control Register

168
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

The bits of timer1 control register are precisely defined below


TON bit is to activate timer 1.
TSIDL defines the behavior in idle mode
TGATE and TSYNC bits are used if other than MCU internal clock is used as timer clock.
TCKPS bits are used to select different level of prescaler to decide after how many clocks of MCU internal clock TMR1
should be incremented
TCS bit is used to select clock source and it is set to 0 if MCU main clock source is going to be used

To use timer 1for delay purpose T1CON should be configured as TON bit must be set to 1, TSIDL bit is of no
concern for this purpose, TGATE, TSYNC and TCS are also set to 0 because MCU internal clock of 32MHz is used as
clock source and TCS bits are set to (11)2 for maximum prescaler of 1: 256 as it has four options 1:1, 1:8, 1:16, 1:256 so
T1CON is initiated by moving 0x8030 in it. To produce delay of specific time Eq (1). is used.
( )

Where, Tdelay is the time for delay, FOSC is the frequency of MCU oscillator and Delay is the value of clocks
required for particular delay. To visualize delay in simulations first four pins of PORTA are toggled with ON time of 256
ms and OFF time of 160 ms. Delay of 16000 and 10000 is calculated for 256 ms and 160 ms of time delay respectively.
This program is developed in MPLAB using the following command sequence shown in Figure 7.

Start

Include header file


p24fj128ga010

Main ()
Initialize
TRISA,T1CON

While(1)
Toggle ON
Insert Delay1
Toggle OFF
Insert Delay2

End

Figure 7. Algorithm Sequence to generate Delay

The simulation results of above program developed in MPLAB is shown in Figure 8

Interrupts
Interrupts are sudden events in continuous flow of execution of series of commands (Z. Milivojević & D.
Šaponjić, 2008). PIC 24F family has a dynamic interrupt system which can manage 118 distinctive sources of interrupts.
These interrupts are classified as internal and external interrupts. Internal interrupt sources are timers, A/D converter,
Analog Compare Module etc while external interrupt sources include pins for level trigger detection, Pins connected to
change notification module, UARTS etc. Each interrupt source has unique piece of code which is called Interrupt Service
Routine (ISR). The syntax used for this ISR is given below.
Void _ISR _X1Interrupt (void)
{// ISR Code here}
Where, X shows the source of interrupt. Each interrupt source has five associated control bits they are; Interrupt
Enable (_IE), Interrupt Flag (_IF) and three bits of Interrupt Priority level (IPL0-IPL2). IE bit must be set to 1 to enable
interrupt, IF bit must be cleared at the end of ISR to ensure that same ISR is not immediately called again and IP bits set
the priority of the interrupt source. Interrupt sources have maximum of 7 priority levels to resolve the issue of occurrence
of two interrupts simultaneously by responding to the interrupt with higher priority level. Another important bit is
_NSTDIS to avoid interrupting a low priority level interrupt by a high priority level interrupt so this bit must be set to 1. In
this section timer 1 is elaborated as an internal interrupt source by setting a pin of PORTA to high for 100 ms after that
interrupt will be generated and in ISR PORTA pin will set to low and PORTB pin will be set to high immediately for
50ms. The required number of clock pulses to generate 160 ms is calculated from (1) and that value will be given to PR1
register of timer 1 while delay of 50 ms in ISR is generated using timer2. The application of timer 1 as an internal
interrupt source is developed in MPLAB by following the sequence of commands shown in Figure 9.

169
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

(a) Implementation of Circuit Diagram in Proteus (b) Toggling of PORTA with Delay
Figure 8. Simulation of Toggling PORTA with Delay

The above figure shows the implementation of circuit in proteus and the simulation results of toggling PORTA pins with
256ms ON time and 160 ms OFF time.

Start

Include header file


p24fj128ga010

Write ISR for Timer 1


Interrupt

Main ()
Initialize PORTA,
PORTB, Interrupt
Control bits and PR1

While(1)
Move data to Port A

End

Figure 9. Algorithm Sequence for Interrupt using Timer 1

The simulation results of above program developed in MPLAB is shown in Figure 10.

(a) Implementation of Circuit Diagram in Proteus (b) Toggling of Pins with Interuppt
Figure 10. Simulation of Internal Interrupt using Timer 1

The above figure shows the circuit implementation, PORTA and PORTB pins are connected to channel A and
channel B of digital Oscilloscope respectively. It is clear from the simulation that first PORTA pin remains high for 100

170
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

ms and after interrupt is occurred PORTA pin is set to low and PORTB pin is set to high and it remains high for 50ms and
this sequence continues.

PWM Generation Using OCM Module


PWM is a smart technique of delivering different amounts of electrical power between fully ON and fully OFF.
A normal power switch with some power source provides full power only, when switched on. PWM is a relatively new
technique, and can be developed by the recent electronic power switches (A.K.Dewangan et al, 2012). In
PIC24FJ128GA010 OCM is used to generate PWM and it has three pins to generate PWM they are OC1, OC2 and OC3.
OCM has number of operational modes i-e Single Compare Match Module, Double Compare Match Mode Generating and
Simple PWM. OCM is initialized using OCXCON control register and for generating PWM the first three bits of
OCXCON register (OCXCON<2:0>) are set to (110) 2. PWM of particular frequency is generated by writing the number of
cycles required to produce PWM period to period register of selected timer. The period register value is calculated by
using the following Eq. (2) (PIC Datasheet, 2006).

[ ]
Where PWM frequency = 1/[PWM Period] and TCY =2/FOSC
The duty cycle of PWM is set by writing its value in OCXRS register while the initial value of duty cycle is first
written to OCXR register then OCXR register becomes Read-Only duty cycle register after the OCXCON control register
is initialized for simple PWM generation (PIC Datasheet, 2006). In this research work PWM is generated with frequency
of 488 Hz using 16MHz crystal oscillator. The calculated value of clocks for period register using (2) is (7FFA) 16 and the
initial value of PWM written to OCXR register is (0F)16. Timer 2 is used for generating interrupt with a frequency of
488Hz In Proteus simulation two push buttons are connected to two pins RA1 and RA2 to increase and decrease the PWM
duty cycle respectively. The application of PWM generation is developed in MPLAB by following the sequence of
commands shown in Figure 11.

Start

Include header file


p24fj128ga010

Initialize Function
Timer 2 for PWM

Initialize PWM
Function OC1CON,
OC1R and OC1RS

Main ()
Initialize PORTA and
call functions

While (1)
Increment or
Decrement Duty Cycle
Using Push Buttons

End

Figure 11. Algorithm Sequence for PWM generation using OCM

The circuit diagram and simulation results of PWM are shown in Figure 12.

(a) Implementation of Circuit Diagram in Proteus (b) PWM generation with 50%, 75%, 100% Duty Cycle
Figure 12. Simulation of PWM generation for different Duty Cycles

171
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

Figure 12 shows the implementation of circuit and elaborates different PWM duty cycles on Digital Oscilloscope
in Proteus software.

LCD and Keypad Interfacing


Interfacing of LCD and Keypad with PIC24FJ128GA010 is elaborated. First LCD is discussed then keypad
interfacing mechanism is shown and finally a combine algorithm sequence and simulation of both LCD and keypad is
shown below.

LCD Interfacing
LCD is used to show real time results and found in number of applications. In this research work a 16*2
display LCD module is used. A 16*2 LCD has 16 characters in each line and there are two such lines. LCD operations are
based on two registers namely command and data where command register controls the operation and data register stores
the data to be displayed. The pin description of LCD is shown in Table 2 (
(S.Priyan & P.Selvaraj, 2014).

Table 2. Pin Description of 16*2 LCD


Pin No. Function Name
1 Ground 0V Ground
2 Supply Voltage 5V VCC
3 Contrast adjustment through a variable resistor VEE
4 Selects command register when low and data register when high Register Select
5 Low to write to the register, High to read from the register Read/Write
6 Sends data to data pins when a high to low pulse is given Enable
7 DB0
8 DB1
9 DB2
10 8-bit data pins DB3
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC (5V) LED+
16 Backlight Ground (0V) LED-

For LCD interfacing pin numbers 1, 3 and 5 are commonly connected to ground while pin number 2 is connected
to supply voltage. Other control and data pins are connected to the defined pins of PORT B from RB0-RB9. To define a
PORT B pin for LCD enable pin following command syntax is used
# define Enable _LCD _RB9
Similarly all the remaining control pins are defined to pins of PORT B and the direction of the pins is initiated as
output by TRISB control register. There are some commands to initialize LCD for different functions which are given
below:
lcdcmd (0x38) //Configure the LCD in 8-bit mode, 2nd line and 5×7 font
lcdcmd (0x0C) // Display On and Cursor Off
lcdcmd (0x01) // Clear display screen
lcdcmd (0x06) // Increment cursor
lcdcmd (0x80) // Set cursor position to 1st line,1st column
lcdcmd (0xC0) // Set cursor position to 2 nd line and 1st column
lcdcmd (0x0F) // Display On; Cursor On; Blink On

Interfacing of LCD with the microcontroller requires few functions to be declared before the main function so
that they can be called in main function for sending data to LCD. These functions include initialize LCD, clear screen,
toggling enable pin, write data and write string. In initialization function direction of all PORT B pins are initiated as
output using TRISB register and are connected to digital inputs using AD1PCFG register then all LCD commands are
declared. Clear function involves two commands of LCD 0x01 and 0x06. In toggling function enable bit is send a high to
low pulse to make LCD ready to receive data. In write function RS pin is set to high then toggling function is called and
finally data is sent to LCD through RB0-RB7. In write string function finally string is displayed on LCD by calling write
data function. In main function all the above functions are called and then string is continuously displayed and cleared on
LCD.

172
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

Keypad Interfacing
In this paper a 4*4 keypad is used in demonstration of keypad interfacing. The keypad uses its internal libraries to
enable scanning of 4*4 switch array and return the data related with the pressed button. The keypad has 4 pins for its
Rows[0:3] and 4 pins for its Col[0:3] and all the pins can be connected to any port and in any order so there is no
requirement to use sequential pins (Keypad Datasheet, 2013). Interfacing can be done in three ways depending on the
design requirements and pin resources. They are scanning method, logic change interrupt method and external interrupt
using IC. In this demonstration scanning method is used which needs 8 pins for interfacing. For keypad interfacing and
recognition of the pressed key by microcontroller few functions are declared outside the main function they are; initialize
keypad, scan individual column, scan keypad and get key. In initialization rows of keypad are defined at RA0-RA3 and
columns are defined at RA4-RA7. RA0-RA3 are initialized as inputs and RA4-RA7 are initialized as outputs and they are
set to high. Scan individual column recognizes the column pressed by verifying which column has 0 value as all the
columns are set to high initially. This recognition is done by following the syntax given below:
Void Scan Individual Column (unsigned char COL Number){
If (COL Number==0) {
COL 0=0;
COL 1=1;
COL 2=1;
COL 3=1; }
Similarly all columns are scanned using else if condition. In scan keypad function scan individual columns are
initialized with each row is scanned to identify which key is pressed and return the value of dialed digit. This is done by
the following syntax:
Char Scan Keypad (void) {
// for first column
Scan Individual Column(0); //Scanning Column 0
If (!ROW0) // Scanning Row 0
Return “7”;
}
Similarly all other rows are scanned for col [0] and for all other columns. Finally in get key function return value
is taken from scan keypad function. In the main function these external defined functions are called to recognize the
pressed key by the microcontroller and which will be further displayed on LCD by using the LCD interfacing
methodology. The combined application of LCD and keypad interfacing is developed in MPLAB by following the
sequence of algorithm shown in Figure 13.

Start

Include header file


p24fj128ga010

Define Pin
Connections of LCD
and Keypad

Declare Functions of
LCD i-e Initialization,
Clear Screen,
Toggling, Write Data
and Write String

Declare Functions of
Keypad i-e Initialize,
Scan Individual
Column, Scan Keypad
and Get Key

Main()
Call Functions of LCD
and Keypad

While(1)
Continuously get
Character of Pressed
Key and Display on
LCD

End

Figure 13. Algorithm Sequence for LCD and Keypad Interfacing

173
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

The circuit diagram and simulation results of LCD and Keypad interfacing is shown in Figure 14.

(a) Implementation of Circuit Diagram in Proteus (b) Display Result on LCD


Figure 14. Simulations of LCD and Keypad Interfacing

Figure 14 shows the circuit implementation and simulation results on LCD in Proteus. First a simple welcome
note is displayed on LCD to test LCD and then the key pressed on the keypad is displayed to verify the interfacing of
keypad.

UART Communication
UART is an asynchronous communication interface which does not require clock line for synchronization. The
data is sent and received by two data lines Tx and Rx respectively and optionally two lines RTS and CTS can be used to
provide hardware handshake. Synchronization between transmitter and receiver in this communication is achieved by
mining the timing information from the data information itself which include proper start and stop bits and defined fixed
baud rate (L.D.Jasio, 2007). UART communication can support data rate up to 500 kb/s and can support a range of devices
from 1 (RS232 standard) to 256 (RS485 standard) (L.D.Jasio, 2007). UART serial communication is based on number of
parameters which include baud rate, number of data bits, parity bit if present, number of stop bits and hardware handshake.
In this research work baud rate is 115200 , 8 data bits, no parity bit and 1 stop bit is used and hardware handshake is
achieved through CTS and RTS lines. There are two UARTs in PIC24FJ128GA010. UART is initialized by UXMODE
control register. U1MODE is a 16-bit control register shown in Figure 15.

Figure 15.U1MODE: UART1 Control Register

The bits of control register used for basic demonstration of UART are briefly defined below (PIC Datasheet, 2006) :
UARTEN bit is used to activate UART
UEN <1:0> bits are used for following functions
11= UxTX, UxRX pins are enabled and used, UxCTS pin is controlled by PORT latches
10= UxTX, UxRX, UxCTS, UxRTS pins are enabled and used
01= UxTX, UxRX and UxRTS pins are enabled and used , UxCTS pin is controlled by PORT latches
00= UxTX and UxRX pins are enabled and used , UxCTS and UxRTS are controlled by PORT latches
BRGH bit is used to enable or disable high baud rate generator
PDSEL <1:0> bits are used to select number of data bits and parity
STSEL bit is used to define one or two stop bits are used

In this demonstration UARTEN bit is set to high to activate UART. UEN bits are remained low. As PIC24F
family provide two modes of baud rate generation high speed and standard speed so BRGH bit is set high in this work. To

174
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

set baud rate of 115200 Baud Rate Generator (BREG1), a 16-bit counter feeds on the peripheral clock is used. A simple
formula used to calculate the value needed for BRG1 to generate required baud rate is given in Eq. (3).

( )

Where, FOSC is the frequency of Oscillator and FOSC used in this work is 32 MHz and calculated value of
BREG1 using the above relation.is 34. PDSEL bits and STSEL bit are all set to low to enable 8-bit data transmission, 1
stop bit with no parity. Hardware handshake is very crucial when UART is communicating with windows terminal
application, as windows perform multi tasks which results in unspecific long delays causing a great loss of data. For
hardware handshaking one I/O pin is used as an input for clear to send (CTS), which senses when the windows terminal is
ready to receive a new character from microcontroller and another I/O pin is initiated as output for ready to send (RTS),
which indicates the terminal that controller is ready to receive new data. Another register which is used to enable the
transmit pin of UART and shows the status of transmitter and receiver buffers by UTXBF and URXDA flags is known as
Status and Control register (U1STA) (L.D.Jasio, 2007).UART communication involves initialization of U1MODE,
U1STA BREG 1 registers. To send data to terminal first CTS is examined if gets 0 keep an eye on status of transmit buffer
flag UTXBF to become low and write data to U1TXREG to send data similarly to receive data first assert RTS line to gets
low then wait for the new character to be arrived using U1RXDA flag register and place that data to U1RXREG. The
program for UART communication is developed in MPLAB by following the sequence of algorithm shown in Figure 16.

Start

Include header file


p24fj128ga010

Define Pin
Connections for RTS,
CTS and set their
direction

Declare Function to
send data

Declare Function to
receive data

Main()
Initialize UART
registers

While(1)
Call functions for
sending and receiving
dat

End

Figure 16. Algorithm Sequence for UART Communication

The circuit diagram and simulation results of UART communication is shown in Figure 17.

(a) Implementation of Circuit Diagram in Proteus (b) Display Result on Virtual Terminal
Figure 17. Simulations of UART Communication

175
J. Curr. Res. Sci. Vol., 4 (2), 164-176, 2016

Figure 17 shows the circuit implementation and simulation of UART communication. The transmitted message is
displayed on Virtual Terminal in Proteus which plays the same role as hyper terminal in windows to test serial
transmission and results have shown that data has been successfully transmitted.

Conclusion
In this research work PIC24FJ128GA010 is explored by developing and simulating number of applications of
PIC24F series microcontroller i-e toggling of port pins, initialization of interrupts, PWM generation, LCD and keypad
interfacing and UART based serial communication by using MPLAB and Proteus software tools respectively. Simulations
have recognized that these two software tools provide a powerful combination to develop and test numerous applications
of PIC24F microcontroller before their real time hardware implementation. Moreover, this paper also advocates the idea of
using the combination of these two tools in educational sector to enhance embedded system skills. In future prospect these
tools can be used to explore other latest PIC 32-bit microcontrollers and will also provide a great help in the development
of PIC24F demonstration board for learning purposes.

References
Arvind SK, Arun TA, Madhukar TS.2014. Speed Control of DC motor using PIC16F877A Microcontroller. Multidisciplinary Journal of Research in
Engineering and Technology. 223-234.
Aslam S.2015. Implementation of Model Predictive Control on a 16-bit Microcontroller for speed control of a DC motor. Dissertation, COMSATS.
Barsoum N. 2010. Speed Control of the Induction Drive by Temperature and Light Sensors via PIC. 53-59.
Chen J. 2011. Application of Proteus Software in MCU teaching. Second International Conference on Mechanic Automation and Control Engineering.
6359-6362
Cypress Perform, “4*4 Keypad” , datasheet, 2013.
Dewangan AK., Chakarborty N. 2012. PWM based Automatic Closed loop Speed Control of DC motor. 110-112.
Jasio LD.2007. Programming 16-bit Microcontrollers in C. Elsevier, UK.
Lee SH, Li YF, Kapila V.2004. Development of a Matlab-Based Graphical User Interface Environment for PIC Microcontroller Projects. Proceedings of
the American Society for Engineering Education Annual Conference & Exposition.
Mashadany YI. 2012. Design and Implementation of Electronic Control Trainer with PIC microcontroller. Intelligent Control and Automation. 222-228
Matic N. 2008. PIC Microcontrollers for Beginners too. MikroElectronica, Belgrade
Mazidi MA, Mckinlay RD. 2008. PIC Microcontroller and Embedded Systems using Assembly and C for PIC 18. Pearson, NewJersey.
Microchip Technical Staff, MPLAB IDE Quick Start Guide, Microchip, 2004.
Microchip, “PIC24FJ128GA010”, datasheet , 2006
Milivojević Z, Šaponjić D.2008. Programming dsPIC MCU in C. MikroElectronica, Belgrade
Mokhtar MA.2009. PIC Video Game System. Dissertation. UNIVERSITI TEKNOLOGI MALAYSIA
Molnikar M, Mohorcic M. 2008. A framework for developing a microchip PIC microcontroller based applications. WSEAS Transactions on
Advances in Engineering Education. 81-91.
Schneider D. 2006. Introduction to the 16-bit PIC24F Microcontroller Family. WebSeminar byMicrochip Technology Inc.
Sethu PP, Selvaj A, Surendar A. 2014. A wireless speed control of AC Drive system. 448-456.

176

You might also like