100% found this document useful (4 votes)
3K views48 pages

Summer Training Report On Embedded System (Atishay Kumar)

The document describes Atishay Kumar's 6 week internship training at WebTek Technology Delhi during the 2018-2019 academic year, where he learned about embedded systems and completed projects involving an AVR microcontroller, including blinking an LED, interfacing with a 7-segment display and 16x2 LCD. Atishay declares the report is true and thanks his trainer, faculty and college for their support during the internship.

Uploaded by

Atishay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
3K views48 pages

Summer Training Report On Embedded System (Atishay Kumar)

The document describes Atishay Kumar's 6 week internship training at WebTek Technology Delhi during the 2018-2019 academic year, where he learned about embedded systems and completed projects involving an AVR microcontroller, including blinking an LED, interfacing with a 7-segment display and 16x2 LCD. Atishay declares the report is true and thanks his trainer, faculty and college for their support during the internship.

Uploaded by

Atishay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

A

Training Report

Of

Summer Training project At

On

EMBEDDED SYSTEM

Submitted

In The partial Fulfilment of

Diploma

Department of Electronics &Communication Engineering

GURU NANK DEV INSTITUTE OF TECHNOLOGY

2018-2019

Submitted to: Submitted by:


Mr. Chandrashekhar Sir Atishay Kumar
Department of Electronics & Communication 1704081011
Engineering (E.C.E) 5th sem
Guru Nanak Dev Institute of Technology
1
DECLARATION
Atishay Kumar student of Guru Nanak Dev Institute of Technology department
of Electronics & Communication Engineering (5th semester) hereby declare that
I have completed this 6 weeks internship training from WebTek Technology
Delhi during the academic year 2018-2019. The information submitted is true
and genuine to the best of my knowledge.

ATISHAY KUMAR
DIPLOMA, BATCH 2017-2018
ROLL NO:-1704081011
ELECTRONICS & COMMUNICATION ENGINNERING
GURU NANAK DEV INSTITUTE OF TECHNOLOGY
NCT OF DELHI

2
ACKNOWLEDGEMENT
I am deeply thankful to “WebTek Labs” as it has given me golden opportunity
to go through remarkable training on “Embedded System”. Here I have got
valuable and detailed knowledge on real time Projects. I owe my gratitude to
My Faculty cum Trainer “Mr. Mangat Ram ” for his unmatched support
guidance and inspiration without which I would not have learned so many new
&innovative things in such a short span of time.

I would also like to thank my Department i.e., Department of Electronics &


Communication Engineering of my college especially my H.O.D. “Mr. Mukesh
Saksena ” and all my teachers who have suggested me to join this beneficial
summer training. My special thanks goes to “ Mr. Chandrashekhar ” without
whose support I would not have prepared this Training Report on time in such
good way. I am highly obliged that I have received all of yours support in such
a good way.

Your’s Faithfully.

Atishay Kumar

3
PREFACE
Practical exposure in the field of embedded system is extremely important as it
gives a close view of the real electronic world issues. It helps to cover all parts
that remained uncovered in the classroom. It helps gain experience. Just
theoretical knowledge is not sufficient for the success of any engineer student.
So one should have practical knowledge about each theory of life.

I learnt lot of new things from this training, which could never have been learnt
from theory classes.

If any findings & recommendations go in any way to prove some new ground in
helping the commodity future sector, I shall deem my efforts have dully served
the purpose. In the forth coming pages an attempt has been made to present
report covering different aspects of my trainings.

4
TABLE OF CONTENT
S.NO. Content Page No.
1 Embedded Systems 07

2 Characteristics of embedded products 08

3 Embedded products in Today’s industry 08

4 Difference Between Microcontroller And 09


Microprocessor

5 What is a Microcontroller? 11

6 Types of Microcontroller on the basis of Service 11


Provider

7 Classification According to Instruction Set 12

8 AVR MICROCONTROLLER 13

9 Basic families of AVR Microcontroller 13

10 Introduction to Atmega16 14

11 Atmega16 Pinout 16

12 Pin Description of Atmega16 16

13 Applications 19

14 Features 20

15 Programming AVRs Using AVR Studio 4 21

16 Program for led blinking 25

17 7-segment Display 28

18 7-Segment Display Segments for all Numbers. 29

19 7-segment Display Truth Table 29

20 7-Segment Display Interfacing with AVR 30


ATmega16
5
21 31
7-Segment Display Interfacing with AVR
ATmega16

22 Program for 7-Segment Display 32

23 About 8×8 LED Matrix 33

24 Interfacing of LED Matrix with Microcontroler 33

25 Program for patern (A) Printing on led matrix 34

26 16*2 LCD 36

27 16X2 LCD pinout diagram 36


28 Important command codes for LCD 39

29 LCD16x2 Interfacing with AVR ATmega16 40

30 Programming for LCD16x2 with AVR 41


ATmega16

31 Conclusion 47

6
1. Embedded Systems
1.1 Introduction:-
Embedded Systems are inseparable part of our life. Whether we are
at home or office or on the move, we are always surrounded by embedded
systems. Starting from home appliances like TV, washing machine and systems
like printer and elevator in workplace to the automobiles and automatic traffic
control system are all examples of embedded systems. All kinds of magazines
and journals regularly dish out details about latest technologies, new devices;
fast applications which make us believe that our basic survival is controlled by
these embedded products.

Embedded system is a combination of Hardware and Software Design to


meet a specific need with performance in given time frame.

Component in an embedded system are as:

Hardware

Input & Output

Software
7
1.2 Characteristics of embedded products:-
1. They perform a single set of functions.
2. Works in a time constrained environment.
3. Provide high performance and reliability.
4. Mostly Embedded systems have low cost because they are mass
produced in millions.

1.3 Embedded products in Today’s industry:-


1. Telecom
Mobile phone systems, modems, routers.

2. Automotive applications
Braking systems, traction systems, airbag release systems, engine-
management units, steer-by-wire systems, cruise control applications

3. Domestic appliances
Dishwashers, televisions, washing machines microwave ovens, Video
recorders, security systems, garage door controllers, calculators, digital
watches, VCRs, Digital cameras, Remote controls, Treadmills.

4. Robotic
Fire fighting robots, Automatic floor cleaner, robotic arm etc.

5. Aerospace applications
Flight control systems, engine controllers, autopilots, passenger in-flight
entertainment systems.

6. Medical equipment
An aesthesia monitoring systems, ECG monitors, Pacemakers, Drug
delivery systems, MRI scanners

7. Defense systems
Radar systems, fighter aircraft flight control systems, radio systems,
missile guidance systems

8. Office automation
Laser printers, fax machines, pagers, cash registers, gas pumps,
credit/debit card readers, thermostats, grain analyzers

8
Difference Between Microcontroller And Microprocessor

Microcontroller
It’s like a small computer on a single IC. It contains a processor core, ROM,
RAM and I/O pins dedicated to perform various tasks. Microcontrollers are
generally used in projects and applications that require direct control of user. As
it has all the components needed in its single chip, it does not need any external
circuits to do its task so microcontrollers are heavily used in embedded systems
and major microcontroller manufacturing companies are making them to be
used in embedded market. A microcontroller can be called the heart of
embedded system. Some examples of popular microcontrollers are 8051, AVR,
PIC series of microcontrollers,.

9
Microprocessor
Microprocessor has only a CPU inside them in one or few Integrated Circuits.
Like microcontrollers it does not have RAM, ROM and other peripherals. They
are dependent on external circuits of peripherals to work. But microprocessors
are not made for specific task but they are required where tasks are complex and
tricky like development of software’s, games and other applications that require
high memory and where input and output are not defined. It may be called heart
of a computer system.  Some examples of microprocessor are Pentium, I3, and
I5 etc.

10
What is a Microcontroller?
A microcontroller is a small, low-cost and self contained computer-on-a-chip
that can be used as an embedded system. A few microcontrollers may utilize
four-bit expressions and work at clock rate frequencies, which usually include:

 An 8 or 16 bit microprocessor.
 A little measure of RAM.
 Programmable ROM and flash memory.
 Parallel and serial I/O.
 Timers and signal generators.
 Analog to Digital and Digital to Analog conversion

Types of Microcontroller on the basis of Service Provider


On the basis of Service Provider or Vendor the types of microcontroller are:

1) AVR: AVR microcontroller is developed by Atmel service provider, AVR


architecture is based on the Harvard architecture. It is based on Reduced
Instruction Set Computers(RISC). AVR is not an acronym it is just a name
given to the RISC architecture based microcontroller.

2) PIC: PIC microcontroller is also a Harvard architecture based controller.


PIC is an acronym stands for "Peripheral Interface Controller". This type of
microcontroller supports programming in C, Assembly and BASIC C.

3) Hitachi: Hitachi microcontroller belongs to H8 family of the controller. H8


is name used in large family of 8-bit, 16-bit and 32-bit microcontroller
developed by Renesas Technology, founded in an early 1990s within Hitachi
semiconductors.

4) Motorola: Motorola microcontroller is highly integrated microcontroller


that is used for high-performance data manipulation operation. This
microcontroller unit uses a System Integration Module (SIM), Time Processing
Unit (TPU) and Queued Serial Module(QSM).
11
Classification According to Instruction Set
CISC: CISC is a Complex Instruction Set Computer. It allows the programmer
to use one instruction in place of many simpler instructions.

RISC: The RISC is stands for Reduced Instruction set Computer, this type of
instruction sets reduces the design of microprocessor for industry standards. It
allows each instruction to operate on any register or use any addressing mode
and simultaneous access of program and data.

Example for CISC and RISC:

CISC: Mov AX, 4         RISC: Mov AX, 0

Mov BX, 2 Mov BX, 4

ADD BX, AX Mov CX, 2

Begin ADD AX, BX

Loop Begin

12
AVR MICROCONTROLLER

AVR is a family of microcontrollers developed since 1996 by Atmel, acquired


by Microchip Technology in 2016. These are modified Harvard architecture 8-
bit RISCsingle-chip microcontrollers. AVR was one of the first microcontroller
families to use on-chip flash memory for program storage, as opposed to one-
time programmable ROM, EPROM, or EEPROM used by other
microcontrollers at the time.
AVR microcontrollers find many applications as embedded systems. They are
especially common in hobbyist and educational embedded applications,
popularized by their inclusion in many of the Arduino line of open
hardware development boards.

Basic families of avr Microcontroller


AVRs are generally classified into following:

 tinyAVR – the ATtiny series


o 0.5–32 KB program memory
o 6–32-pin package
o Limited peripheral set
o

13
 megaAVR – the ATmega series
o 4–256 KB program memory
o 6-32-pin package
o Extended instruction set (multiply instructions and instructions for
handling larger program memories)
o Extensive peripheral set
o
 XMEGA – the ATxmega series
o 16–384 KB program memory
o 44–100-pin package (A4, A3, A1)
o 32-pin package: XMEGA-E (XMEGA8E5)
o Extended performance features, such as DMA, "Event System", and
cryptography support
o Extensive peripheral set with ADCs

Introduction to Atmega16

 Atmega16 is a 40-pin low power microcontroller which is developed using


CMOS technology.
 CMOS is an advanced technology which is mainly used for developing
integrated circuits. It comes with low power consumption and high noise
immunity.
 Atmega16 is an 8-bit controller based on AVR advanced RISC (Reduced
Instruction Set Computing) architecture. AVR is family of
microcontrollers developed by Atmel in 1996.
 It is a single chip computer that comes with CPU, ROM, RAM, EEPROM,
Timers, Counters, ADC and four 8-bit ports called PORTA, PORTB,
PORTC, PORTD where each port consists of 8 I/O pins.
 Atmega16 has built-in registers that are used to make a connection between
CPU and external peripherals devices. CPU has no direct connection with

14
external devices. It can take input by reading registers and give output by
writing registers.
 Atmega16 comes with two 8-bit timers and one 16-bit timer. All these timers
can be used as counters when they are optimized to count the external signal.

 Most of the necessary peripherals required to run automatic functions are


incorporated in this device like ADC (analog to digital converter), Analog
comparator, USART, SPI, which make it economical as compared to a
microprocessor that requires external peripheral to perform various functions.
 Atmega16 comes with 1KB of static RAM which is a volatile memory i.e
stores information for short period of time and highly depends on the
constant power supply. Whereas 16KB of flash memory, also known as
ROM, is also incorporated in the device which is non-volatile in nature and
can store information for long period of time and doesn’t lose any
information when the power supply is disconnected.
 Atmega16 works on a maximum frequency of 16MHz where instructions are
executed in one machine cycle.

15
Atmega16 Pinout

Following figure shows the pin diagram of this AVR microcontroller


Atmega16.

 Atmega16 is preferred over other microcontrollers like Atmel 8051 because it


comes with much faster ability to execute instructions and consist of
modified RISC processor.
 It has a built-in flash which comes with features of a bootloader. It has built-
in 10-bit ADC, SPI, PWM, and EEPROM.

Pin Description of Atmega16


Atmega16 comes with 40 pins where each pin is used to perform a specific task.
There are total 32 I/O pins and four ports. Each port consists of 8 I/O pins.

 PORTA = 8 Pins ( Pin 33 – 40 )


 PORTB = 8 Pins ( Pin 1 – 8 )

16
 PORTC = 8 Pins ( Pin 22 – 29 )
 PORTD = 8 Pins ( Pin 14 – 21 )
Following are the main functions associated with pins.

PORTA. Pins from 33 to 40 fall under PORTA. It acts like analog inputs to


A/D converter. However, in the absence of A/D converter, PORTA is used as an
8-bit bidirectional I/O port. It comes with internal pull-up resistors.

PORTB. Pins from 1 to 8 belong to PORTB. These are I/O bidirectional pins.


This port also consists of internal pull-up resistors.

17
PORTC. PORTC is an I/O bidirectional port that consists of 8 pins. Pin from
22 to 29 belongs to this port.  Similar to other ports, it  comes with internal pull-
up resistors.

PORTD. Pin from 14 to 21 belongs to this port. It is a bidirectional port where


each pin can be used as input or output pin. However, there are additional

18
features associated with this port like interrupts, serial communication, timer,
and PWM.

Reset. Pin9 is an active low reset Pin. A low-level pulse for longer than
minimum pulse length will produce a reset. Short pulses are unlikely to produce
reset.

VCC. Pin10 is a power supply pin for this controller. The power supply of 5 V
is required to put this controller in a running condition.

GND. Pin11 is a ground pin.

AREF. Pin32 is an analog reference pin mainly used for A/D converter.

AVCC. Pin30 is an AVCC which is a supply voltage pin for PORTA and ADC.
It is connected to VCC through a low pass filter in the presence of ADC.
However, in the absence of ADC, AVCC is externally connected to VCC.

Pin 12 & 13. A crystal oscillator is connected with these pins. Atmega16 works
at the internal frequency of 1MHZ; the oscillator is added to generate high clock
pulses and frequency.

19
Applications
AVR controllers come with a wide range of applications where automation is
required. Following are the main applications of Atmega16.

 Medical equipment
 Home automation
 Embedded systems
 Arduino Projects
 Used in automobiles and industrial automation
 Home appliances and security systems
 Temperature and pressure control devices

Features

 Advanced RISC Architecture


o 131 Powerful Instructions – Most Single-clock Cycle
Execution
o 32 x 8 General Purpose Working Registers
o Fully Static Operation
o Up to 16 MIPS Throughput at 16 MHz
o On-chip 2-cycle Multiplier
 High Endurance Non-volatile Memory segments
o 16 Kbytes of In-System Self-Programmable Flash program
memory
o 512 Bytes EEPROM
o 1 Kbyte Internal SRAM
o Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
o Data retention: 20 years at 85°C/100 years at 25°C(1)
o Optional Boot Code Section with Independent Lock Bits
o In-System Programming by On-chip Boot Program
o True Read-While-Write Operation
o Programming Lock for Software Security

20
 Peripheral Features
o Two 8-bit Timer/Counters with Separate Prescalers and
Compare Modes
o One 16-bit Timer/Counter with Separate Prescaler, Compare
Mode, and Capture Mode
o Real Time Counter with Separate Oscillator
o Four PWM Channels
o 8-channel, 10-bit ADC
o 8 Single-ended Channels
o Byte-oriented Two-wire Serial Interface
o Programmable Serial USART
o Master/Slave SPI Serial Interface
o Programmable Watchdog Timer with Separate On-chip
Oscillator
o On-chip Analog Comparator
 I/O and Packages
o 32 Programmable I/O Lines
o 40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF
 Operating Voltages
o 7V – 5.5V for ATmega16L
o 5V – 5.5V for ATmega16
 Speed Grades
o 0 – 8 MHz for ATmega16L
o 0 – 16 MHz for ATmega16
 Power Consumption @ 1 MHz, 3V, and 25°C for ATmega16L
o Active: 1.1 mA
o Idle Mode: 0.35 mA
o Power-down Mode: < 1 µA

21
Programming AVRs Using AVR Studio 4

Introduction
Atmel, AVR microcontrollers (MCUs) are very easy to use. All AVR
microcontrollers require Integrated Development Environment(IDE) such as
Atmel Studio. Using this IDE, we can create, compile and debug program on all
AVR microcontrollers.
Atmel Studio is available free of charge. To download and install latest Atmel
studio use this link.
Note: There are possibly two options for downloading and installing Atmel
Studio as online/offline. Atmel recommends for online web installer so use
online web installer if possible.
Here, we are using Atmel Studio 7 as currently latest IDE for developing
program of Atmega16 microcontroller.
Atmel Studio 7 includes the GCC C and C++ compiler, assembler and a
simulator, and interfaces seamlessly with in-system debuggers and
programmers to make code development easier.
Let’s develop simple LED Blinking program for ATmega16 using Atmel Studio
7

1. After done with downloading and installing, Open Atmel Studio 7. We can
see Start Page as shown in below figure.

22
2. Now to create new project Click on File -> New -> Project or simply
use Ctrl+Shift+N Short keys.

3. A New Project window will pop up as shown in below figure. In New


Project window, we need to select project type as listed in below
figure, Name for project (which may title of project) and Location to where we
can save project work.

Also, there is option Create directory for solution, which will create project


directory with name of project at provided location.

23
4. After click on OK, Device Selection window will pop up as shown in below
figure. In that we can directly type device name to get required device from
device list shown in below figure.
Click on device name and then click OK. Here we have selected ATmega16
microcontroller device.

5. Now wait till Atmel studio creates project and main.c file to write program
for selected device as shown in below figure.

24
6. Now write a program. Here we are writing program for LED Blinking
connected to a PORTB of ATmega16.

ATmega16 and LED connection diagram

25
Program for led blinking
/*
* ATmega16_LED_Blinking.c
* http://www.electronicwings.com
* Created: Created Date & Created Time
* Author : Author Name
*/

#define F_CPU 8000000UL /* Define CPU frequency here 8MHz */


#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
DDRB = 0xFF; /* Make all pins of PORTB as output pins */

while (1) /* Blink PORTB infinitely */


{
PORTB = 0x00;
_delay_ms(500); /* Delay of 500 milli second */
PORTB = 0xFF;
_delay_ms(500);
}
}

26
7. After writing program, save (Ctrl+S) the program and click on Build
Solution from Build menu as shown in below figure.

8. Now we can see build succeeded output in Output Window (lower left corner
of window) as shown in below figure.

9. Now we can see generated.hex file in Debug directory of the Main


project directory. Here we have created hex file at,

27
D:\AtmelProjects\ATmega16_LED_Blinking\ATmega16_LED_Blinking\
Debug\ ATmega16_LED_Blinking.hex
10. Now upload this hex file to ATmega microcontroller. AVRDUDE is
program to burn hex code in to the Atmel AVR microcontroller.
SinaProg (find in attachment given below) is AVRDUDE GUI software, which
utilizes AVRDUDE program to burn hex code in to the Atmel AVR
microcontroller using USBasp.
USBasp is USB in circuit programmer for Atmel AVR controllers.

USBasp Programmer for AVR microcontrollers


11. After uploading above program connect LED to ATmega16, it will start
blinking as shown .

28
7-segment Display
An LED or Light Emitting Diode, is a solid state optical pn-junction diode
which emits light energy in the form of photons.

29
7-Segment Display Segments for all Numbers.

Then for a 7-segment display, we can produce a truth table giving the individual
segments that need to be illuminated in order to produce the required decimal
digit from 0 through 9 as shown below.

7-segment Display Truth Table

Individual Segments Illuminated

Decimal
Digit

a b c d e f g

0 × × × × × ×

1 × ×

2 × × × × ×

3 × × × × ×

4 × × × ×

5 × × × × ×

30
6 × × × × × ×

7 × × ×

8 × × × × × × ×

9 × × × × ×

7-Segment Display Interfacing with AVR ATmega16

31
Program for 7-Segment Display
#include<avr/io.h>
#define F_CPU 16000000UL
#include<util/delay.h>
void main()
{
DDRB=0b11111111;
PORTB=0b11000000;
_delay_ms(1000);
PORTB=0b11111001;
}

After 1 Second

32
About 8×8 LED Matrix
With low-voltage scanning, 8×8 LED Matrix LED display have advantages
such as power saving, long service life, low cost, high brightness, a wide angle
of view, long visual range, waterproofness,

and so on. They can meet the needs of different applications and thus have a
broad development prospect.

8×8 matrix consists of 64 dots or pixels. There is a LED for each pixel and these
LEDs are connected to total of 16 pins.
Generally, there are two types of dot matrix – common cathode and common
anode. They look almost the same in appearance. But usually there will be
labels for easy recognition. The one with a label ending with AX is a common
cathode dot matrix and that with BXis a common anode one. See the figure
below for how they look like. So the pins are distributed at the two ends of the
matrix. Pins at one end (usually the label side) are 1-8 from left to right, when at
the opposite they are 9-16 from right to left.

Interfacing of LED Matrix with Microcontroler

33
Program for patern (A) Printing on led matrix

#include<avr/io.h>
#define F_CPU 16000000UL
#include<util/delay.h>
void main()
{
while(1)
{
DDRA=DDRB=0XFF;
PORTA=0X01;
PORTB=0xe7;
_delay_ms(1);
PORTA=0X02;
PORTB=0xc3;
_delay_ms(1);
PORTA=0X04;
PORTB=0x99;
_delay_ms(1);
PORTA=0X08;
PORTB=0x3c;
_delay_ms(1);
PORTA=0X10;
PORTB=0X3c;
_delay_ms(1);
PORTA=0X20;
PORTB=0x3c;
_delay_ms(1);
PORTA=0X40;
PORTB=0x3c;
_delay_ms(1);
PORTA=0X80;
PORTB=0x3c;
_delay_ms(1);
PORTA=0X80;
PORTB=0x3c;
}
}

34
35
16*2 LCD
We come across LCD displays everywhere around us. Computers, calculators,
television sets, mobile phones, digital watches use some kind of display to
display the time. An LCD is an electronic display module which uses liquid
crystal to produce a visible image. The 16×2 LCD display is a very basic
module commonly used in DIYs and circuits. The 16×2 translates o a display 16
characters per line in 2 such lines. In this LCD each character is displayed in a
5×7 pixel matrix.

16X2 LCD pinout diagram

36
Pin
 Name
No.  Function

1 Ground (0V) Ground

2 Supply voltage; 5V (4.7V – 5.3V)  Vcc

Contrast adjustment; the best way is to use a variable resistor such as a


potentiometer. The output of the potentiometer is connected to this pin.
3  Vo / VEE
Rotate the potentiometer knob forward and backwards to adjust the LCD
contrast.

RS (Register
4 Selects command register when low, and data register when high
Select )

5 Low to write to the register; High to read from the register Read/write

Sends data to data pins when a high to low pulse is given; Extra voltage push
is required to execute the instruction and EN(enable) signal is used for this
6 purpose. Usually, we make it en=0 and when we want to execute the Enable
instruction we make it high en=1 for some milliseconds. After this we again
make it ground that is, en=0.

7 8-bit data pins DB0

8 DB1

9 DB2

10 DB3

11 DB4

12 DB5

37
13 DB6

14 DB7

15 Backlight VCC (5V) Led+

16 Backlight Ground (0V) Led-

RS (Register select)

A 16X2 LCD has two registers, namely, command and data. The register select
is used to switch from one register to other. RS=0 for command register,
whereas RS=1 for data register.

Command Register: The command register stores the command instructions


given to the LCD. A command is an instruction given to LCD to do a
predefined task like initializing it, clearing its screen, setting the cursor position,
controlling display etc. Processing for commands happens in the command
register.

Data Register:  The data register stores the data to be displayed on the LCD.
The data is the ASCII value of the character to be displayed on the LCD. When
we send data to LCD it goes to the data register and is processed there. When
RS=1, data register is selected.

38
Important command codes for LCD

Sr.No. Hex Code Command to LCD instruction Register

1 01 Clear display screen

2 02 Return home

3 04 Decrement cursor (shift cursor to left)

4 06 Increment cursor (shift cursor to right)

5 05 Shift display right

6 07 Shift display left

7 08 Display off, cursor off

8 0A Display off, cursor on

9 0C Display on, cursor off

10 0E Display on, cursor blinking

11 0F Display on, cursor blinking

12 10 Shift cursor position to left

13 14 Shift cursor position to right

14 18 Shift the entire display to the left

15 1C Shift the entire display to the right

16 80 Force cursor to beginning ( 1st line)

17 C0 Force cursor to beginning ( 2nd line)

18 38 2 lines and 5×7 matrix


39
LCD16x2 Interfacing with AVR ATmega16
LCD 16x2 is a 16 pin devices which has 8 data pins (D0-D7) and 3 control pins
(RS, RW, EN). The remaining 5 pins are for supply and backlight for the LCD.
The control pins help us configure the LCD in command mode or data mode.
They also help configure read mode or write mode and also when to read or
write.
LCD 16x2 can be used in 4-bit mode or 8-bit mode depending on requirement
of application. In order to use it we need to send certain commands to the LCD
in command mode and once the LCD is configured according to our need, we
can send the required data in data mode.
For more information about LCD 16x2 and how to use it, refer the topic LCD
16x2 display module in the sensors and modules section.

40
Programming for LCD16x2 with AVR ATmega16
Initialize LCD16x2: It is very easy to initialize a LCD16x2

1. Power ON the LCD


2. Wait for 15 ms (‘Power ON’ initialization time for LCD16x2)
3. Send 0x38 command to initialize 2 line, 5x8 matrix, 8-bit mode
LCD16x2
4. Send any ‘Display ON’ command (0x0E, 0x0C) to LCD16x2
5. Send 0x06 command (increment cursor) to LCD16x2

void LCD_Init (void) /* LCD Initialize function */


{
41
LCD_Command_Dir = 0xFF; /* Make LCD command port direction as
o/p */
LCD_Data_Dir = 0xFF; /* Make LCD data port direction as o/p */

_delay_ms(20); /* LCD Power ON delay always >15ms */


LCD_Command (0x38); /* Initialization of 16X2 LCD in 8bit mode */
LCD_Command (0x0C); /* Display ON Cursor OFF */
LCD_Command (0x06); /* Auto Increment cursor */
LCD_Command (0x01); /* clear display */
LCD_Command (0x80); /* cursor at home position */
}
Now that we have initialized LCD, it is ready to accept data for displaying.
 Command Write function

1. Send the command value to the LCD16x2 data port.


2. Make RS pin low, RS = 0 (command reg.)
3. Make RW pin low, RW = 0 (write operation)
4. Give high to low pulse at the Enable (E) pin of minimum delay 450 ns.

When we give an enable pulse, the LCD latches the data present at D0 to D7,
and execute as command since RS is command reg.

void LCD_Command(unsigned char cmnd)


{
LCD_Data_Port= cmnd;
LCD_Command_Port &= ~(1<<RS); /* RS=0 command reg. */
LCD_Command_Port &= ~(1<<RW); /* RW=0 Write operation */
LCD_Command_Port |= (1<<EN);/* Enable pulse */
_delay_us(1);
LCD_Command_Port &= ~(1<<EN);

42
_delay_ms(3);
}

 Data write function

1. Send command to the data port.  


2. Make the RS pin High, RS = 1 (Data reg.)
3. Make the RW pin Low, RW = 0 (Write operation)
4. Give high to low pulse at the Enable (E) pin

When we give an enable pulse the LCD latches the data present (on the pins D0
to D7) and displays it on a 5x8 matrix, as RS is a data register.

void LCD_Char (unsigned char char_data) /* LCD data write function */


{
LCD_Data_Port = char_data;
LCD_Command_Port |= (1<<RS); /* RS=1 Data reg. */
LCD_Command_Port &= ~(1<<RW); /* RW=0 write operation */
LCD_Command_Port |= (1<<EN);/* Enable Pulse */
_delay_us(1);
LCD_Command_Port &= ~(1<<EN);
_delay_ms(1);
}

 
Display String function
         This function takes a string (an array of characters) and sends one
character at a time to the LCD data function till the end of the string. A ‘for
loop’ is used for sending a character in each iteration. A NULL character
indicates end of the string.

void LCD_String (char *str)


{
int i;
for(i=0;str[i]!=0;i++) /* send each char of string till the NULL */
{
LCD_Char (str[i]); /* call LCD data write */

43
}
}

 
Note:

1. LCD Power-on delay: After the LCD16x2 powers ON, we cannot send
commands immediately to it since it needs self-initialization time of 15-
ms. Therefore, while programming, we need to take care of providing
sufficient power ON delay (> 15 ms), and then send command to the
LCD.
2. After proving commands, LCD16x2 takes time (in microseconds) to
execute it. But for 0x01 command (i.e. clear display), it takes 1.64-ms to
execute. Therefore, after sending 0x01 command sufficient delay (>
1.63milliseconds) needs to be provided.

LCD16x2 Program
#define F_CPU 8000000UL /* Define CPU Frequency e.g.
here 8MHz */
#include <avr/io.h> /* Include AVR std. library file */
#include <util/delay.h> /* Include inbuilt defined Delay header
file */
#define lcd PORTD /* Define LCD connected to port D */

void LCD_Command(unsigned char cmnd)


{

44
LCD_Data_Port= cmnd;
LCD_Command_Port &= ~(1<<RS); /* RS=0 command reg. */
LCD_Command_Port &= ~(1<<RW); /* RW=0 Write operation */
LCD_Command_Port |= (1<<EN);/* Enable pulse */
_delay_us(1);
LCD_Command_Port &= ~(1<<EN);
_delay_ms(3);
}

void LCD_Char (unsigned char char_data) /* LCD data write function */


{
LCD_Data_Port= char_data;
LCD_Command_Port |= (1<<RS); /* RS=1 Data reg. */
LCD_Command_Port &= ~(1<<RW); /* RW=0 write operation */
LCD_Command_Port |= (1<<EN);/* Enable Pulse */
_delay_us(1);
LCD_Command_Port &= ~(1<<EN);
_delay_ms(1);
}

void LCD_Init (void) /* LCD Initialize function */


{
LCD_Command_Dir = 0xFF; /* Make LCD command port
direction as o/p */
LCD_Data_Dir = 0xFF; /* Make LCD data port direction as o/p */
_delay_ms(20); /* LCD Power ON delay always >15ms */

LCD_Command (0x38); /* Initialization of 16X2 LCD in 8bit


mode */
LCD_Command (0x0C); /* Display ON Cursor OFF */
LCD_Command (0x06); /* Auto Increment cursor */
LCD_Command (0x01); /* Clear display */
LCD_Command (0x80); /* Cursor at home position */
45
}

void LCD_String (char *str) /* Send string to LCD function */


{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL
*/
{
LCD_Char (str[i]);
}
}

void LCD_String_xy (char row, char pos, char *str)/* Send string to LCD with xy
position */
{
if (row == 0 && pos<16)
LCD_Command((pos & 0x0F)|0x80); /* Command of first row and
required position<16 */
else if (row == 1 && pos<16)
LCD_Command((pos & 0x0F)|0xC0); /* Command of first row and
required position<16 */
LCD_String(str); /* Call LCD string function */
}

void LCD_Clear()
{
LCD_Command (0x01); /* clear display */
LCD_Command (0x80); /* cursor at home position */
}

int main()
{
LCD_Init(); /* Initialize LCD */

46
LCD_String("ElectronicWINGS");/* write string on 1st line of LCD*/
LCD_Command(0xC0); /* Go to 2nd line*/
LCD_String("Hello World"); /* Write string on 2nd line*/
return 0;
}

OUTPUT

CONCLUSION
Introduction:
This part of the report describe the overall result and conclusion made during
the training report.

Lessons learned:
1 Basic of Embedded System

2 Medium Level circuit designing involving microcontroller

3 Fault Diagonasis in circuit

4 PCB designing and embedded C programing

47
5 Introduction of various electronics component

Key Learning:
1 Enhancement in technical knowledge

2 Work experience with professional

3 Industrial Exposure

Knowledge Gained:
The training at WEBTEK Academy, Rajori Garden ,Delhi provided me an
insight on embedded system technology and recent trend in industry. This
training also helped me in my overall personality development by interaction
with many trainnes and the staff members. It provided me Industrial Exposure,
and the working experience with real life professionals which will certainly help
me in my career ahead.

Suitability of Organisation:
The organisation is suitable for any product based on an embedded system. The
whole staff is very cooperative. This organisation provides a healthy
environment for trinees that help them to develop a sense of professionalism in
realtion to job skills and performance.

48

You might also like