+ All Categories
Home > Documents > 72267797 PIC Training Report

72267797 PIC Training Report

Date post: 24-Apr-2015
Category:
Upload: apsingh8105
View: 157 times
Download: 5 times
Share this document with a friend
43
A SUMMER TRAINING REPORT On PIC16F877A Microcontroller At Centre for Development of Advanced Computing Mohali Submitted in the partial fulfillment of the requirements of Degree, Bachelor of Technology in Electronics & Communication Engineering. By VATSALA SHARMA (1508229) DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING N.C.COLLEGE OF ENGINEERING, ISRANA, PANIPAT (Affiliated To Kurukshetra University, Kurukshetra, Haryana, India) Oct.2011 1
Transcript
Page 1: 72267797 PIC Training Report

A

SUMMER TRAINING REPORT

On

PIC16F877A Microcontroller

At

Centre for Development of Advanced ComputingMohali

Submitted in the partial fulfillment of the requirements of Degree, Bachelor of Technology in

Electronics & Communication Engineering.

By

VATSALA SHARMA

(1508229)

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

N.C.COLLEGE OF ENGINEERING, ISRANA, PANIPAT

(Affiliated To Kurukshetra University, Kurukshetra, Haryana, India)

Oct.2011

1

Page 2: 72267797 PIC Training Report

ACKNOWLEDGEMENT

A formal statement of acknowledgement is hardly sufficient to express my gratitude towards the persons who have helped me to undertake and complete this training.

Training in an organization Centre for Development of Advanced Computing, Mohali is in itself a true learning experience. I hereby convey my thanks to all who have rendered their valuable help, support and guidance.

I am highly thankful to Mr. Vikas Malhotra for the valuable guidance, technical acumen, round the clock encouragement and support that he has provided to me.

I would also like to thank all the staff of C.D.A.C. Mohali, who has directly or indirectly helped in making my training a success and making it a fulfilling and a memorable experience.

I also take this opportunity to thank my H.O.D and faculty members at college who consistently supported me and guided me during the training period. Though not physically present with me but your constant guidance not only through phone but the valuable acumen you provided me with during the college was practically put to use during the training and was a key factor in its successful completion.

VATSALA SHARMARoll No.1508229B. Tech (E.C.E)(IVth Year)NCCE, ISRANAPANIPAT

2

Page 3: 72267797 PIC Training Report

3

Page 4: 72267797 PIC Training Report

LIST OF FIGURES

1. Microcontroller Architecture……………………………………………………...112. Block diagram……………………………………………………………………....143. Pin diagram………………………………………………………………………....154. CPU Memory…………………………………………………………………….….195. Basic Connection……………………………………………………………………246. Interfacing…………………………………………………………………………..257. Interfacing switch to PIC…………………………………………………………..268. Interfacing LED to PIC…………………………………………………………….279. Interfacing LCD to PIC…………………………………………………………….2810. Seven segment display………………………………………………………………30

10.1 Common anode……………………………………………………….3010.2 Common cathode……………………………………………………..30

11. Interfacing seven segment display to PIC…………………………………………31

4

Page 5: 72267797 PIC Training Report

LIST OF TABLES

1. Pin description…………………………………………………………162. Address banks………………………………………………………….213. Instruction Set………………………………………………………….224. Pin configuration for LCD…………………………………………….29

5

Page 6: 72267797 PIC Training Report

CONTENT

Acknowledgements.................................................................................................................2

Certificate……..……………..……………………………………………………………….3

List Of Figures……………………………………………………………………………….4

List of tables………………………………………………………………………………….5

Contents………………………………………………………………………………………6

Chapter 1: Introduction

1.1 Training Organizational Details……………………………………………......81.2 Training Introduction……………………………………………………….......9

Chapter 2:Microcontrollers

2.1 Microcontroller over Microprocessor…………………………………………102.2 Microcontroller Architectures…………………………………………………11

Chapter 3:PIC16F877A

3.1 Advantages………………………………………………………………………123.2 Features………………………………………………………………………….133.3 Block Diagram…………………………………………………………………..143.4 Pin Discription…………………………………………………………………..15

Chapter 4: Central Processing Unit……………………………………………………….19

4.1 Memory………………………………………………………………………….194.1.1 ROM…………………………………………………………...194.1.2 EEPROM……………………………………………………...194.1.3 RAM…………………………………………………………...19

4.2 Registers………………………………………………………………………....204.2.1 General Purpose Register…………………………………….204.2.2 SFR Register…………………………………………………..20

4.3 Stack……………………………………………………………………………..204.4 RAM Memory Banks…………………………………………………………...21

Chapter 5: Instruction Set……………………………………………………………….…22

Chapter 6: Basic Connection……………………………………………………………….24

Chapter 7: Interfacings……………………………………………………………………..25

7.1 Interfacing Switch Display to PIC…………………………………………….267.2 Interfacing LED Display to PIC……………………………………………….277.3 Interfacing LCD Display to PIC………………………………...……………..287.4 Interfacing 7 Segment Display to PIC…………..……………………………..30

6

Page 7: 72267797 PIC Training Report

Limitations…………………………………………………………………………………..32

Summary...…………………………………………………………………………………..33

Bibliography………………………………………………………………………………...34

7

Page 8: 72267797 PIC Training Report

1.1 TRAINING ORGANIZATION DETAILS

Centre for Development of Advanced Computing(C-DAC) is the premier R&D organization

of the Department of information technology (DIT), Ministry of Communication &

Information technology (MCIT) for carrying out R&D in IT, Electronics and associated

areas.

A different areas of C-DAC, had originated at different times, many of which came out as a

result of identification of opportunities.

Starting from its initial mission on building indigenous supercomputers, Centre for

Development of advanced computing(C-DAC) has progressively grown to build an eco-

system and institutional framework for innovation, technology development, skills, delivery

plans, collaboration, partnership and market orientation in a number of skills, delivery plans,

collaboration, partnership and market orientation in a number of niche areas of national

importance and market relevance in ICT and Electronics. C-DAC’s focus has been on

emerging as a leader in chosen enabling technology areas and work towards integration of

these in end-to-end solutions in various verticals/domains including infrastructure. The latter

is undertaken oftentimes by C-DAC itself but equally or more often in

conjunction/collaboration with other public and private agencies through a consortium and

partnership mode. Institutional innovation to support scaling up process of such efforts is also

one of the priority objectives. The focal areas in terms of enabling technologies as outlined

above would be:-High Performance Computing & Grid Computing, Language Computing,

Software Technologies with special reference to free/open source software, Professional

Electronics including VLSI and Embedded System, Cyber security, Health Informatics,

Education &training with special reference to finishing School and areas of specialized skills

8

Page 9: 72267797 PIC Training Report

1.2 TRAINING INTRODUCTIONA microcontroller is a programmable logic and integrated circuit which can be programmed to do a number of tasks. It is possible to control just about anything with the program written by the user. Basically, a microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals.Some of the functions of a microcontroller are-

Ability to execute a stored set of instructions to carry out user defined task. Ability to access external memory chips to read & write data from/to memory. Ability to interface with the I/O devices.

Basic components of a Microcontroller are- A CPU to execute programmed code Memory, both RAM and ROM Internal timers and input/output system, in form of i/o pins

Some Microcontrollers have some extra features like-UART for serial communication, Internal EEPROM and PWM modules for analogue output

Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools, toys and other embedded systems. By reducing the size and cost compared to a design that uses a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control even more devices and processes. Mixed signal microcontrollers are common, integrating analog components needed to control non-digital electronic systems.

9

Page 10: 72267797 PIC Training Report

2.1 MICROCONTROLLER OVER MICROPROCESSOR

With development in computer technology, newer versions of processing units are coming into existence. Every new unit have some advantages over previous one which results in replacement of older units. Microprocessors were used quite significantly in large number of applications but it was soon replaced by the microcontroller because of the following reasons:

A microprocessor (µP) is a one-chip CPU such as the Intel 80x86, or Pentium series, the Motorola 68000 series, the PowerPC series and so on…

These single-chip systems were called microprocessors because they replaced an older generation which used multiple chips and even multiple pc boards to perform the same functions.

A µP needs additional chips such as RAM, ROM, serial and parallel ports, timers, interrupt controllers and so on to make a complete cpu (motherboard).

A microcontroller (µC) has the CPU and most, if not all of these peripheral functions built into a single chip.

µCs tend to be much smaller than modern µPs, with memory in tens of bytes to kilobytes.

µCs can also include other features such as oscillator-on-chip, A/D converters, reset circuitry, high current I/O drive capability, watchdog timers etc.

Basically, the benefit of µCs in embedded systems is that complete systems can be built with a very low component count, frequently just one chip. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications.

10

Page 11: 72267797 PIC Training Report

2.2 MICROCONTROLLER ARCHITECTURES

There are two types of basic architectures:Von-Neumann Architecture- It has only one bus which is used for both data transfers and instruction fetches, and therefore data transfers and instruction fetches must be scheduled - they cannot be performed at the same time.Harvard Architecture- It has physically separate signals and storage for code and data memory. It is possible to access program memory and data memory simultaneously.

Fig 1. Microcontroller Architectures

When we look at a typical microcontroller one of the first things we notice is that the microcontroller contains its own memory, parallel ports, clock and very often a good number of peripheral functions not found on a microprocessor. In the case of PIC microcontrollers we will find both flash program memory where instructions are stored and a separate ram memory space where only data is stored. Computers that have separate memory spaces for data and program instructions are classified as the Harvard Architecture. One particular advantage of the Harvard Architecture is that data access operations can be taking place simultaneously with program instruction execution. Each memory area has its own data bus to the CPU so operations can go on during the same time frame. Many different manufacturers use the Harvard Architecture for designs of microcontrollers because this design is very efficient for designing specific purpose controllers that go into other systems. Microcontrollers usually get embedded into other products such as microwave ovens, automobile engine controllers, power tools, appliances, industrial instruments, hand held devices, cell phones and many other areas. The design and programming for these types of products and applications has become so specialized that it has taken on its own identity as “embedded design”.

11

Page 12: 72267797 PIC Training Report

3. PIC16F877A MICROCONTROLLER

The PIC16F887 is one of the latest products from Microchip. It features all the components which modern microcontrollers normally have. For its low price, wide range of application, high quality and easy availability, it is an ideal solution in applications such as: the control of different processes in industry, machine control devices, measurement of different values etc.

3.1 ADVANTAGES OF PIC16F877A

The PIC architectures have these advantages: Small instruction set to learn RISC architecture Built in oscillator with selectable speeds Easy entry level, in circuit programming plus in circuit debugging PIC Kit units

available from Microchip.com for less than $50 Inexpensive microcontrollers Wide range of interfaces including I2C, SPI, USB, USART, A/D, programmable

Comparators, PWM, LIN, CAN, PSP, and Ethernet

12

Page 13: 72267797 PIC Training Report

3.2 FEATURES OF PIC16F877A

RISC architecture o Only 35 instructions to learno All single-cycle instructions except branches

Operating frequency 0-20 MHz Precision internal oscillator

o Factory calibratedo Software selectable frequency range of 8MHz to 31KHz

Power supply voltage 2.0-5.5V o Consumption: 220uA (2.0V, 4MHz), 11uA (2.0 V, 32 KHz) 50nA (stand-by

mode) Power-Saving Sleep Mode Brown-out Reset (BOR) with software control option 35 input/output pins

o High current source/sink for direct LED driveo software and individually programmable pull-up resistoro Interrupt-on-Change pin

8K ROM memory in FLASH technology o Chip can be reprogrammed up to 100.000 times

In-Circuit Serial Programming Option o Chip can be programmed even embedded in the target device

256 bytes EEPROM memory Data can be written more than 1.000.000 times 368 bytes RAM memory A/D converter:

o 14-channelso 10-bit resolution

3 independent timers/counters Watch-dog timer Analogue comparator module with

o Two analogue comparatorso Fixed voltage reference (0.6V)o Programmable on-chip voltage reference

PWM output steering control Enhanced USART module

o Supports RS-485, RS-232 and LIN2.0o Auto-Baud Detect

Master Synchronous Serial Port (MSSP) o supports SPI and I2C mode

13

Page 14: 72267797 PIC Training Report

3.3 BLOCK DIAGRAM

Fig 2. Block Diagram

14

Page 15: 72267797 PIC Training Report

3.4 PIN DESCRIPTION

Fig 3. Pin Diagram

As seen in Fig.2, most of the pins are multi-functional. For example, designator RA3/AN3/Vref+ for the fifth pin specifies the following functions:

RA3 Port A third digital input/output AN3 Third analog input Vref+ Positive voltage reference

15

Page 16: 72267797 PIC Training Report

PIN NAMENUMBER

FUNCTION DESCRIPTION

MCLR/VPP 1 MCLRMaster Clear (Reset) input. This pin is active low

  VPP Programming voltage input.

RA0/AN0 2 RA0 Digital I/O.    AN0 Analog input 0

RA1/AN1 3 RA1 Digital I/O.    AN1 Analog input 1.

RA2/AN2/VREF-/CVREF 4 RA2 Digital I/O.    AN2 Analog input 2.    VREF A/D reference voltage (Low) input.    CVREF Comparator VREF output.

RA3/AN3/VREF+ 5 RA3 Digital I/O.    AN3 Analog input 3.    VREF+ A/D reference voltage (High) input.

RA4/T0CKI/C1OUT 6 RA4Digital I/O – Open-drain when configured as output.

    T0CKI Timer0 external clock input.    C1OUT Comparator 1 output.

RA5/AN4/SS/C2OUT 7 RA5 Digital I/O.    AN4 Analog input 4.    SS SPI slave select input.    C2OUT Comparator 2 output.

RE0/RD/AN5 8 RE0 Digital I/O.    RD Read control for Parallel Slave Port.    AN5 Analog input 5.RE1/WR/AN6 9 RE1 Digital I/O.    WR Write control for Parallel Slave Port.    AN6 Analog input 6.RE2/CS/AN7 10 RE2 Digital I/O.    CS Chip select control for Parallel Slave Port.    AN7 Analog input 7.

VDD 11 Positive supplyVSS 12   Ground

OSC1/CLKI 13 OSC1 Oscillator crystal input

    CLKIExternal clock source input. Always associated

    with pin function OSC1

OSC2/CLKO 14 OSC2 Oscillator crystal output.    CLKO In RC mode, OSC2 pin outputs CLKO,

16

Page 17: 72267797 PIC Training Report

which    has 1/4 the frequency of OSC1 RC0/T1OSO/T1CKI 15 RC0 Digital I/O.    T1OSO Timer1 oscillator output.    T1CKI Timer1 external clock input

RC1/T1OSI/CCP2 16 RC1 Digital I/O.    T1OSI Timer1 oscillator input.

    CCP2Capture2 input, Compare2 output, PWM2 output.

RC2/CCP1 17 RC2 Digital I/O.

    CCP1Capture1 input, Compare1 output, PWM1 output.

RC3/SCK/SCL 18 RC3 Digital I/O.

    SCKSynchronous serial clock input/output for SPI mode.

    SCLSynchronous serial clock input/output for I2C mode.

RD0/PSP0 19 RD0 Digital I/O.    PSP0 Parallel Slave Port data.

RD1/PSP1 20 RD1 Digital I/O.    PSP1 Parallel Slave Port data.

RD2/PSP2 21 RD2 Digital I/O.    PSP2 Parallel Slave Port data.

RD3/PSP3 22 RD3 Digital I/O.    PSP3 Parallel Slave Port data.

RC4/SDI/SDA 23 RC4 Digital I/O.    SDI SPI data in.    SDA I2C data I/O

RC5/SDO 24 RC5 Digital I/O.    SDO SPI data out.

RC6/TX/CK 25 RC6 Digital I/O.    TX USART asynchronous transmit.    CK USART1 synchronous clockRC7/RX/DT 26 RC7 Digital I/O.    RX USART asynchronous receive.    DT USART synchronous data.

RD4/PSP4 27 RD4 Digital I/O.    PSP4 Parallel Slave Port data.

RD5/PSP5 28 RD5 Digital I/O.    PSP5 Parallel Slave Port data.

RD6/PSP6 29 RD6 Digital I/O.    PSP6 Parallel Slave Port data.

RD7/PSP7 30 RD7 Digital I/O.

17

Page 18: 72267797 PIC Training Report

    PSP7 Parallel Slave Port data.

VSS 31   GroundVDD 32 Positive supply

RB0/INT 33 RB0 Digital I/O.    INT External interrupt.

RB1 34 Digital I/O.RB2 35   Digital I/O.

RB3/PGM 36 RB3 Digital I/O.

    PGMLow-voltage ICSP programming enable pin.

RB4 37   Digital I/O.

RB5 38   Digital I/O.

RB6/PGC 39 RB6 Digital I/O.

    PGCIn-circuit debugger and ICSP programming clock.

RB7/PGD 40 RB7 Digital I/O.

    PGDIn-circuit debugger and ICSP programming data.

Table 3. Pin discription

18

Page 19: 72267797 PIC Training Report

4. CENTRAL PROCESSING UNIT (CPU)

CPU is manufactured with in RISC technology which is an important factor when deciding which microprocessor to use.

RISC Reduced Instruction Set Computer, gives the PIC16F887 two great advantages: The CPU can recognizes only 35 simple instructions (In order to program some other

microcontrollers it is necessary to know more than 200 instructions by heart). The execution time is the same for all instructions except two and lasts 4 clock cycles

(oscillator frequency is stabilized by a quartz crystal). The Jump and Branch instructions execution time is 2 clock cycles. It means that if the microcontroller’s operating speed is 20MHz, execution time of each instruc tion will be 200nS, i.e. the program will be executed at the speed of 5 million instructions per second!

Fig. 4. CPU Memory

4.1 MEMORYThis microcontroller has three types of memory- ROM, RAM and EEPROM. All of them will be separately discussed since each has specific functions, features and organization.

4.1.1 ROM Memory ROM memory is used to permanently save the program being executed. This is why it is often called “program memory”. The PIC16F887 has 8Kb of ROM (in total of 8192 locations). Since this ROM is made with FLASH technology, its contents can be changed by providing a special programming voltage (13V).Anyway, there is no need to explain it in detail because it is automatically performed by means of a special program on the PC and a simple electronic device called the Programmer.

4.1.2 EEPROM MemorySimilar to program memory, the contents of EEPROM is permanently saved, even the power goes off. However, unlike ROM, the contents of the EEPROM can be changed during operation of the microcontroller. That is why this memory (256 locations) is a perfect one for permanently saving results created and used during the operation.

4.1.3 RAM MemoryThis is the third and the most complex part of microcontroller memory. In this case, it consists of two parts: general-purpose registers and special-function registers (SFR).

19

Page 20: 72267797 PIC Training Report

Even though both groups of registers are cleared when power goes off and even though they are manufactured in the same way and act in the similar way, their functions do not have many things in common.

4.2REGISTERS4.2.1General-Purpose RegistersGeneral-Purpose registers are used for storing temporary data and results created during operation. For example, if the program performs a counting (for example, counting products on the assembly line), it is necessary to have a register which stands for what we in everyday life call “sum”. Since the microcontroller is not creative at all, it is necessary to specify the address of some general purpose register and assign it a new function. A simple program to increment the value of this register by 1, after each product passes through a sensor, should be created. Therefore, the microcontroller can execute that program because it now knows what and where the sum which must be incremented is. Similarly to this simple example, each program variable must be preassigned some of general-purpose register.

4.2.2 SFR RegistersSpecial-Function registers are also RAM memory locations, but unlike general-purpose registers, their purpose is predetermined during manufacturing process and cannot be changed. Since their bits are physically connected to particular circuits on the chip (A/D converter, serial communication module, etc.), any change of their contents directly affects the operation of the microcontroller or some of its circuits. For example, by changing the TRISA register, the function of each port A pin can be changed in a way it acts as input or output. Another feature of these memory locations is that they have their names (registers and their bits), which considerably facilitates program writing. Since high-level programming language can use the list of all registers with their exact addresses, it is enough to specify the register’s name in order to read or change its contents.

4.3 STACK A part of the RAM used for the stack consists of eight 13-bit registers. Before the microcontroller starts to execute a subroutine (CALL instruction) or when an interrupt occurs, the address of first next instruction being currently executed is pushed onto the stack, i.e. onto one of its registers. In that way, upon subroutine or interrupt execution, the microcontroller knows from where to continue regular program execution. This address is cleared upon return to the main program because there is no need to save it any longer, and one location of the stack is automatically available for further use.It is important to understand that data is always circularly pushed onto the stack. It means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored with the first push. The tenth push overwrites the second push and so on .In addition, the programmer cannot access these registers for write or read and there is no Status bit to indicate stack overflow or stack underflow conditions. For that reason, one should take special care of it during program writing.

20

Page 21: 72267797 PIC Training Report

4.4 RAM Memory BanksThe data memory is partitioned into four banks. Prior to accessing some register during program writing (in order to read or change its contents), it is necessary to select the bank which contains that register. In order to facilitate operation, the most commonly used SFRs have the same address in all banks which enables them to be easily accessed.

Table 1. Address Banks

21

Page 22: 72267797 PIC Training Report

5. INSTRUCTIONS SET

Table 2. Instruction set

The PIC microcontroller also has a very different type of instruction set. The particular PIC microcontroller located on the trainer board we will be using is the PIC16F877A. This is in

22

Page 23: 72267797 PIC Training Report

the midrange family but its capabilities are at the top end of the midrange family. This unit only uses 35 instructions! This is the same for all microcontrollers in the midrange family. The strategy that is used in the design of this type of microcontroller is to make a few very simple instructions that execute very fast. Using this strategy a complex task can be accomplished with the combination of many very fast simple instructions in a relatively short time. Computers that use just a small number of very simple instructions that execute very fast are classified as RISC or Reduced Instruction Set Computers. Since PIC microcontrollers use only 35 very simple instructions they fit neatly into this category

23

Page 24: 72267797 PIC Training Report

6. BASIC CONNECTIONS

As seen in the figure below, in order to enable the microcontroller to operate properly it is necessary to provide:

Power Supply; Reset Signal; and Clock Signal.

Fig 5. Basic Connections

24

Page 25: 72267797 PIC Training Report

7. INTERFACINGS The following figure shows the internal components of a PIC16F877A and various types of peripherals which can be connected to it.

Fig 6. Interfacing

25

Page 26: 72267797 PIC Training Report

7.1 INTERFACING SWITCH TO PIC16F877A

Fig 7. Interfacing Switch to PIC

Fig 7. shows switch interfacing to RA0. Or any pin to be used as an inout pin. A high pin should be written to the pin if this is not done, the pin will be read low. In the above figure when the switch is not pressed the 10k resistor provides the current needed for LOGIC 1 closure of switch provides LOGIC 0 to the controller PIN.

26

Page 27: 72267797 PIC Training Report

7.2 INTERFACING LED TO PIC16F877AFigure 8. shows how to interface the LED to microcontroller. As you can see the Cathode is connected through a resistor to Ground & the Anode is connected to the Microcontroller pin. So when the Port Pin is HIGH the LED is ON & when the Port Pin is LOW the LED is turned OFF.

Fig 8. Interfacing LED to PIC

27

Page 28: 72267797 PIC Training Report

7.3 INTERFACING LCD TO PIC16F877ALiquid Crystal Display also called as LCD is very helpful in providing user interface as well as for debugging purpose. The most common type of LCD controller is HITACHI 44780 which provides a simple interface between the controller & an LCD. These LCD's are very simple to interface with the controller as well as are cost effective.The most commonly used ALPHANUMERIC displays are 1X16 (Single Line & 16 characters), 2X16 (Double Line & 16 character per line) & 4X20 (four lines & Twenty characters per line). 

Fig 9. Interfacing LCD to PICThe LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines. The number on data lines depends on the mode of operation. If operated in 8-bit mode then 8 data lines + 3 control lines i.e. total 11 lines are required. And if operated in 4-bit mode then 4 data lines + 3 control lines i.e. 7 lines are required. How do we decide which mode to use? It’s simple if you have sufficient data lines you can go for 8 bit mode & if there is a time constrain i.e. display should be faster then we have to use 8-bit mode because basically 4-bit mode takes twice as more time as compared to 8-bit mode.When RS is low (0), the data is to be treated as a command. When RS is high (1), the data being sent is considered as text data which should be displayed on the screen. When R/W is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively reading from the LCD. Most of the times there is no need to read from the LCD so this line can directly be connected to GND thus saving one controller line. The ENABLE pin is used to latch the data present on the data pins. A HIGH - LOW signal is required to latch the data. The LCD interprets and executes our command at the instant the

28

Page 29: 72267797 PIC Training Report

EN line is brought low. If you never bring EN low, your instruction will never be executed. For Contrast setting a 10K pot should be used as shown in the figure.

Table 3. Pin Configuration for LCD

Pin Symbol I/O Description

1 Vss - Ground

2 Vcc - +5V Power supply

3 VEE - Power supply to control Contrast

4      RS IRS = 0 to select command registerRS = 1 to select data register

5 R/W I R/W = 0 for write, R/W = 1 for read

6 E I/O Enable

7 DB0 I/O The 8-bit data bus

8 DB1 I/O The 8-bit data bus

9 DB2 I/O The 8-bit data bus

10 DB3 I/O The 8-bit data bus

11 DB4 I/O The 8-bit data bus

12 DB5 I/O The 8-bit data bus

13 DB6 I/O The 8-bit data bus

14 DB7 I/O The 8-bit data bus

15 LED- I Ground for LED backlight

16 LED+ I +5v for LED backlight

Display Data Ram (DDRAM) stores the display data. So when we have to display a character on LCD we basically write it into DDRAM. For a 2x16 LCD the DDRAM address for first line is from 80h to 8fh & for second line is 0c0h to 0cfh. So if we want to display 'H' on the 7th position of the first line then we will write it at location 87h.

29

Page 30: 72267797 PIC Training Report

7.4 INTERFACING 7-SEGMENT DISPLAY TO PIC16F877A7 Segment displays are basically 7 LED's as shown in Figure 1.9. It will be much easier to understand if you first read Interfacing LED's to Microcontroller. Basically there are two types of 7-Seg displays:

Common Anode where all Segments share the same Anode. [See fig 1.8(a))] Common Cathode where all the segments share the same Cathode. [See fig 1.8(b))]

Here we will be only discussing the Common Anode type. In common Anode in order to turn ON a segment the corresponding pin must be set to 0. And to turn it OFF it is set to 1. 

Fig 10. Seven Segment Display

Fig 10.1 Common Anode Fig10.2 Common Cathode

30

Page 31: 72267797 PIC Training Report

Fig 11. Interfacing 7-Seg Display to PIC

Figure 11. shows how to interface 7-seg display to a microcontroller. Now we create a lookup table containing the seven segment pattern to display the corresponding hex digits. e.g. consider we have to display '1' from the above figure  we come to know that turning ON segment B & C will show '1' on the 7-seg display so RB1 & RB2 should be LOGIC 0 whereas rest of the pins should be LOGIC 1. 

31

Page 32: 72267797 PIC Training Report

LIMITATIONS

Though PIC16F877A is very efficient microcontroller for some particular operation but still its architecture have these limitations:

Presence of only one accumulator Register-bank switching is required to access the entire RAM of many devices Operations and registers are not orthogonal; some instructions can address RAM and/or

immediate constants, while others can only use the accumulator It has no internal oscillator so you will need an external crystal of other clock source.

32

Page 33: 72267797 PIC Training Report

SUMMARY

The 16F877A is one of the most popular PIC microcontrollers and it comes in a 40 pin DIP pin-out and the PIC16F877A is rich in internal and external peripherals so it can be used for many different purposes. One of the most useful features of a PIC microcontroller is that it can be re-programmed as they use flash memory.

33

Page 34: 72267797 PIC Training Report

BIBLIOGRAPHY

Study Material provided by Teachers of CDAC

http://pdf1.alldatasheet.com/datasheetpdf/view/222581/RFSOLUTIONS/RX6000.htl

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=255

http://en.wikipedia.org/wiki/PIC_microcontroller

34


Recommended