You are on page 1of 142

2 G.

P AGRAWAL
Dedicated to Mata Saraswati
3 G.P AGRAWAL
CONTENTS
TOPIC PAGE NO
Basics of Electronics Components and its Types 08

Digital system And Number System 09

Types of Digital circuit & Clock 10

Logic Gates 11

Bread Board 13

Resistor,Colour coding,Types,potentiometer 14

LDR 19

Capacitor ,Types,Symbols 20

4
RELAYS, DIODE, Types ,Zener Diode and characteristics 25

LED,LED MATRIX & Seven segment display 31


Transistors(BJT) & Its Types 36
Loudspeaker &Microphone 46
Integrated circuits ,Testing and Its Identification 52
555 55
4029 63
7447 64
OP-AMP 66
UA741 67
7805 68
HCF 4017B 70
7404 &7408 72
7432 & 7402 73
7400 & 7486 74
SENSORS 75
ANALOG SENSORS AND DIGITAL SENSORS 77
INTRODUCTION TO MICROCONTROLLERS 81
COMPILER/ IDE & PROGRAMMER 87
CODE VISION AVR (CVAVR) 88
CVAVR BEGINNING CODING EXAMPLES 91
ATMEGA-8, ATMEGA-16 & ATMEGA-32 102

PIN DESCRIPTIONS OF ATMEGA-8 106


REGISTERS 112
DDRX 113
PORTX 115
PINX 117
LCD INTERFACING 118
SERIAL PORT OF COMPUTER 124
ADC 132
INTRODUCTION OF TM4C123G LAUNCHPAD (ARM 134
MICROPROCESSOR)
REFERENCES 141
SECTION-A

basic concepts of
ELECTRONICS

7 G.P AGRAWAL 1
BASICS

ELECTRONIC COMPONENTS

An electronic circuit ia made of a large no of components which are interconnected


to produce a desired function.The electronic components can be classified as:

1.Active component (semiconductor devices): Diodes , transistors and ICs.

2.Passive components: Resistors and potentiometer (VDR, LDR, thermister),capacitors


and inductors.
3. Mechanicle components: Switches(normal/minature , toggle,slide,push button,rotary,
SPST,SPDT,DPST,DPDT ,etc) ,wires and cables,plug
and sockets,and connectors.

4.Electro-mechanicle components: Protection devices(fuses),circuit


breakers,coil,transformers(main audio and
RF,etc),LED,LCD,FET.

8 G.P AGRAWAL
Digital System

Logic high = 1
Logic low = 0

Number System in Digital Electronics

Dec 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15

Bin 00 00 00 00 01 01 01 01 10 10 10 10 11 11 11 1111
00 01 10 11 00 01 10 11 00 01 10 11 00 01 10

Hex 0 1 2 3 4 5 6 7 8 9 A B C D E F

9 G.P AGRAWAL
Types of Digital circuit

CLOCK

10 G.P AGRAWAL
LOGIC GATES

11 G.P AGRAWAL
12
G.P AGRAWAL
PRACTICAL CIRCUIT ELEMENTS
BREAD BOARD

13 G.P AGRAWAL
RESISTOR
Resistor is introduced in an electronic circuit to oppose the flow of current.

Types of resistors:
1.Carbon composited Resistor: It consists of finely ground carbon ,region binder
and compressed shape of resistor.The end connection is obtained by
soldering tinned metal copper wire.
2.Metal Film Resistor: It is obtained by putting a film of Nickel or Chromium on high
grade ceramic rod.
3.Carbon Film Resistor: A film of resistive material is depodited on insulating core.

4.Wire wound Resistor: The resistance wire is wound over insulating base and
assembly is covered in a protective insulating material.
14 G.P AGRAWAL
15
G.P AGRAWAL
16
G.P AGRAWAL
Resistor Symbol
Fixed Resistor Potentiometer Thermistor
___/\/\/\/\/\/\____ ___/\/\/\/\/\/\____ ____/\/\/\/\/\/\___
T

Potentiometer (POT):

17
G.P AGRAWAL
18 G.P AGRAWAL
LDR(Light Dependent Resistor)

19 G.P AGRAWAL
CAPACITORS(CONDENSERS)

A capacitor consists of two conductors separated by a dielectric or insulater.The dielectric can be


paper,mica ceramic,plastic film or foil.
The value of capacitor is indicated on the body of the capacitor either in words or in colour code.
The two types of capacitors we use in circuits are ceramic and electrolytic capacitors.while ceramic
capacitors dont have a fixed polarity;electrolytic capacitors should be connected in their genuine
polarity .Ceramic capacitors are small in size and value ranging from a few pico farads to 1 micro
farads.

20 G.P AGRAWAL
21 G.P AGRAWAL
Tantalum Capacitors

22 G.P AGRAWAL
Variable Capacitors

The variable capacitor has a stator and rotor and turning the the rotor from 0
degree to 180 degree varies the amount of plate surface exposed.

23
G.P AGRAWAL
Switches

24 G.P AGRAWAL
Relays

25 G.P AGRAWAL
DIODE

26 G.P AGRAWAL
27 G.P AGRAWAL
Diode as a Rectifier

ZENER DIODES

28 G.P AGRAWAL
29 G.P AGRAWAL
Characteristics of Diode

30 G.P AGRAWAL
LED

31 G.P AGRAWAL
32 G.P AGRAWAL
LED MATRIX

33 G.P AGRAWAL
SEVEN SEGMENT DISPLAY

34 G.P AGRAWAL
35 G.P AGRAWAL
Bipolar Junction Transistor(BJT)
Introduction to Transistors

36 G.P AGRAWAL
BJT STRUCTURE

37 G.P AGRAWAL
38 G.P AGRAWAL
39 G.P AGRAWAL
40 G.P AGRAWAL
41 G.P AGRAWAL
Electrons enter the emitter from the battery and
come out of the collector. A transistor can act as a
switch. A small voltage applied to the base will
switch the transistor on allowing the current to flow
in the rest of the transistor.

Transistor as switch: Most sensors,processors,microcontrollers cant source


enough power to make things happen in the real world. Transistors allow a
large amount of current to be controlled by a small change in
voltage.Ground between control circuit and transistors must be common.
42 G.P AGRAWAL
43 G.P AGRAWAL
Types of transistors

44 G.P AGRAWAL
SMALL SIGNAL TRANSISTORS

POWER TRANSISTORS

HIGH FREQUENCY TRANSISTORS

45 G.P AGRAWAL
Loudspeaker and Microphone

A loudspeaker (or speaker) is an electro-acoustic transducer that converts an electrical into


sound. The speaker moves in accordance with the variations of an electrical signal and causes
sound waves to propagate through a medium such as air or water.

Types of Loudspeaker

Woofers (low frequencies)


Below 200 Hz
Subwoofers (for very low frequencies)
Mid-range speakers (middle
frequencies)
3005000 Hz
Tweeters (high frequencies)
2,000 Hz to 20,000 Hz
Supertweeters (optimized for the highest audible
frequencies)

46 G.P AGRAWAL
47 G.P AGRAWAL
GENERAL SPECIFICATIONS
Speaker or driver type (individual units only) Full-range, woofer,
tweeter, or mid-range.
Size of individual drivers. For cone drivers, the quoted size is generally
the outside diameter of the basket.
Rated Power Nominal (or even continuous) power, and peak (or
maximum short-term) power a loudspeaker can handle (i.e., maximum
input power before destroying the loudspeaker; it is never the sound
output the loudspeaker produces). A driver may be damaged at much
less than its rated power if driven past its mechanical limits at lower
frequencies. Tweeters can also be damaged by amplifier clipping
(amplifier circuits produce large amounts of energy at high frequencies
in such cases) or by music or sine wave input at high frequencies.
Impedance typically 4 (ohms), 8 , etc.
Baffle or enclosure type (enclosed systems only) Sealed, bass
reflex, etc.
Number of drivers (complete speaker systems only) two-way, threeway,
etc.

48 G.P AGRAWAL
Microphone
Microphone is a device which converts the variations of sound pressure in a sound wave
into corresponding electrical variation in an electrical circuit.

Types of Microphones
oCondenser microphone
oDynamic microphone
oCarbon microphone
oRibbon Microphone
oPiezoelectric microphone
oFibre optic microphone

49 G.P AGRAWAL
50 G.P AGRAWAL
51 G.P AGRAWAL
52 G.P AGRAWAL
Integrated circuits consists of a circuit made up of a number of transistors, diodes, resistors,
capacitors and their interconnection on a single semiconductor chip. Common types of ics are
Linear or Analogue ics and digital ics. The example of linear circuits are simple amplifiers,
operational amplifiers and analogue communication circuits.
Digital circuits are based on logic gates and include TTL,CMOS and high speed
SMOS.

Testing of ICs

Incircuit testing of ICs is simple,measure the d.c. voltage applied at the terminals with
power sources established,apply the correct i/p and then observe the o/p.For out of circuit
testing of IC,remove ic. supply the required power and i/p signal to get desired o/p.
Digital ICs are tested with IC tester which are mu-P based and programmed.
The ic to be tested is inserted in the test socket. The display indicates the status of IC
after testing.

53 G.P AGRAWAL
Manufacturers logo Year of manufacture
Date code 79
Production batch no
32

#$% 7932

SN 74LS74 N

Suffix indicates package


Prefix indicates manufacturer , Type ,temperature
Core number range
IC type 74 LS 74
No letter=TTL
Number identifies C=CMOS
Logic family function of IC L=LOW POWER
Logic
LS=LOW POWER
54 G.P AGRAWAL subfamily
555

55 G.P AGRAWAL
Mono stable Mode(one-shot timer )

56 G.P AGRAWAL
Astable Mode(oscillator)

Note: capacitor
C2 is used to
filter the noise
and its value
can be suitably
chosen to be
0.01uF.it can
also be
neglected.

57 G.P AGRAWAL
How IC 555 timer works?

Pin-1, GROUND: It is the GROUND PIN of the IC. The negative terminal of DC power supply or
battery is connected to this pin. Here note that IC555 works always on single rail power supply
and NEVER on dual power supply, unlike operational amplifiers. Also note that this pin should be
connected directly to ground and NOT through any resistor or capacitor. If done so, the IC will
not function properly and may heat up and get damaged. This happens because all the
semiconductor blocks inside the IC will be raised by certain amount of stray voltage and will
damage the IC
Pin-2, TRIGGER: It is known as TRIGGER PIN. As the name suggests in triggers i.e. starts
the timing cycle of the IC. It is connected to the inverting input terminal of trigger comparator
inside the IC. As this pin is connected to inverting input terminal, it accepts negative voltage
pulse to trigger the timing cycle. So it triggers when the voltage at this pin LESS THAN 1/3 of
the supply voltage (Vcc). In number of applications, the IC must be triggered by a pulse. The
amplitude and minimum pulse width required for triggering depend on supply voltage of the
IC. Generally the current required for triggering is about 0.5uA for a period of 0.1uS. The
triggering voltage may be in a range from minimum 1.67V whenVcc = 5V to maximum 5V
whenVcc = 15V. The triggering circuit inside the IC is very sensitive and may be
accidently activated due to surrounding noise. To avoid this, the pin is always connected
to a pull-up resistor (10k-ohm), if this pin is used separately
58 G.P AGRAWAL
Pin-3, OUTPUT :This is the OUTPUT PIN of the IC. It can SINK or SOURCE a maximum
current of 200mA. Sinking the current means, when the output of the IC is at logic-0 state i.e.
LOW and so it can absorb current into its output. Similarly sourcing the current means, when
the output of the IC is at logic-1 i.e. HIGH and so it can give out current from its output. Due
to this property of the IC, we can use it in number of typical digital applications also. Also
note that the output voltage of the IC is slightly greater than zero, when it is in logic-0 state.
Similarly it is slightly less than supply voltage (Vcc), when output of the IC is in logic-1 state.

Pin-4, RESET :It is the RESET PIN of the IC. When it is connected to positive terminal of
battery, the IC works normally. However, when it is grounded (either directly or through a
maximum of 100k-ohm resistor), the IC stops its working completely and its timing cycle
stops i.e. the charging or discharging of the external capacitor stops, so output of the IC is
locked in logic-0 state. It is interesting to note that the reset voltage required by this pin is
typically 0.7V at a reset current of 0.1mA. However in general applications, this pin is always
connected to positive terminal so that the IC works normally.

Pin-5, C. VOLTAGE :This is known as the CONTROL VOLTAGE pin. The 2/3 of supply
voltage point on the terminal voltage divider is brought out to pin-5, known as the control
terminal of the IC. The timing cycle can be modified by applying external DC control voltage
to this pin.

59 G.P AGRAWAL
This allows manual or electronic remote controlling of the time interval of the IC. The control
terminal is frequently used when the timer is operated in MMV mode. But if you are NOT
using this pin for any such purpose, then this pin MUST BE GROUNDED THROUGH A
CAPACITOR OF 0.01uF. This prevents the time interval from being affected by RF noise from
the surrounding.

Pin-6, THRESHOLD : This is known as the THRESHOLD PIN. It finalizes the timing cycle of
the IC, when its voltage is equal to or greater than 2/3Vcc, the output is at logic-0 state.
Since this pin is connected to non-inverting terminal of threshold comparator inside the IC, it
accepts positive going pulse to end up the timing cycle, also. Note that the typical value of
threshold current is 0.1mA, just like the RESET PIN. The time width of this pulse should be
greater than or equal to 0.1uS.

Pin-7, DISCHARGE: It is known as DISCHARGE PIN. It discharges the external capacitor


into itself, but when fully charged. It is connected to the collector of an NPN transistor inside
the IC. Due to this, the discharging current going into this pin MUST NOT EXCEED 50mA,
otherwise the internal transistor may get damaged. It is interesting to note that this pin can
also be used as output pin with open collector output.

60 G.P AGRAWAL
Pin-8, +Vcc: It is known as the +ve supply terminal of the IC. The battery voltage
connected across this pin and ground pin SHOULD NOT EXCEED 18V. Generally the range
of operating voltage of the IC is 3V18V.

A functional block diagram of 555 timer is given below. The


device consists of two comparators two transistors, a flip-flop and buffered outputs stage.
The reference voltages for the two comparators inside the 555 are produced across a
voltage divider consisting of three equal resistors of 5K ohms each.
Look at the above given block diagram
of the IC, to see that there are three
resistors of 5kohm each connected in
series. These three resistors produce
1/3 and 2/3 voltage levels for
controlling the action of trigger and
threshold comparators inside the IC.
Due to this arrangement of the
three resistors, the IC has a typical
code number as IC555.

61 G.P AGRAWAL
The delay period, the time that the output is high, in seconds is given by:
1.1 x C x R, where R is in Mega ohm and C is in microfarads.

To obtain large delay in some practical applications, the value of timing resistor should not exceed
20 Mega ohm. If you use an electrolytic timing capacitor, select a unit for low leakage. The time
delay may have to be adjusted by varying PT to compensate for the wide tolerance of electrolytic.

An important feature to be noted here is that 555, unlike many RC timers, provide a timed interval
that is virtually independent of supply voltage Vcc.

62 G.P AGRAWAL
4029

With the clock made,we are ready to count the no of pulses passed into the circuit. Any kind of
counting requires a memory (you have to know that you have just counted 3 to go to 4).so
4029 can be used as a memory element that remembers its immediate previous state.

63 G.P AGRAWAL
7447:BCD to 7 SEGMENT DISPLAY DECODER

64 G.P AGRAWAL
65
G.P AGRAWAL
Operational Amplifier (OP-AMP)

66 G.P AGRAWAL
OPAMP as a COMPARATOR

UA741

67 G.P AGRAWAL
7805 Voltage Regulator

68 G.P AGRAWAL
69 G.P AGRAWAL
HCF4017B

70 G.P AGRAWAL
71 G.P AGRAWAL
7404 Hex inverting Gates (NOT GATE)

7408 AND GATES

72 G.P AGRAWAL
7432 Quad 2-Input OR Gate

7402 Quad 2-Input NOR Gate

73 G.P AGRAWAL
7400 Quad 2-Input NAND Gate

7486 Quad 2-Input XOR Gate

74 G.P AGRAWAL
SENSORS

75 G.P AGRAWAL
76 G.P AGRAWAL
Analog Sensors

IR LED is used as a source of infrared rays. This radiation illuminates the


surface in front of LED. Surface reflects the infrared light.

Depending on reflectivity of the surface, amount of light reflected varies.


This reflected light is made incident on photodiode (IR Receiver). A
photodiode produces analog voltage depending on amount of light it
receives.

77 G.P AGRAWAL
LM35
LM35: LM35 is temperature sensor. It sense the surrounding
temperature and convert in to a particular voltage
(depending on surrounding temp). It is a three leg sensor.
It gives 10mV per degree centrigrate. Now, if V ref.
if temp is 31 degree centrigrate than my lm35 will give value
of 310mV and corresponding ADC value will be 63.
78 G.P AGRAWAL
Digital IR Sensor (TSOP Sensor)

79 G.P AGRAWAL
80 G.P AGRAWAL
SECTION-B

EMBEDDED SYSTEMS

81 G.P AGRAWAL
INTRODUCTION TO MICROCONTROLLER

What is a microcontroller?
A microcontroller is an integrated circuit that is programmed to do a
specific task.
Microcontrollers are really just mini -computers.

82 G.P AGRAWAL
If I give you an IC with 20 pins and tell you that you have to perform a specific task,
then you can make any pin as output or input also you can change the function by
programming that IC using your computer. It has a set of pins called as PORT and
you can program it to perform according to your choice whatever you want to see
output. You can change the configuration as many times you wants.

There are many semiconductor companies which manufactures microcontrollers.


Some of them are:

INTEL
ATMEL
MICROCHIP
MOTOROLA
TEXAS

Where do you find them?


Microcontrollers are hidden in tons of appliances,gadgets and other electronics
devices like calculaters,watches,keyboard,computers,atm machines,mobile
phones,robots,vechicles ,control systems and many more devices.

83 G.P AGRAWAL
84 G.P AGRAWAL
A Microcontroller is a computer dedicated to a single task.
Fundamental components of a microcontroller :
Central processing unit
Memory
System Clock(Oscillator)
Peripherals
Microprocessor versus Microcontroller

85
G.P AGRAWAL
How do we code microcontrollers?
According to your desired output you can write program on your computer in any
high languages like C,C++ etc.Then you have to compile the code to generate machine
code file,becoz all the machines understand only 1 & 0 logics that means ON(+5 volts)
or OFF(GND or 0 v relatively) respectively.
so,we write the program in C language which we understand and then compile
and make the machine file (.hex file) and then the code is converted in to 0,1 language i.e
machine language and then we feed this to the memory of microcontroller.

How to feed the code in the flash of microcontroller?


After compilation .hex file will be generated and you have to feed that to the flash of
microcontroller that means communication between computer and microcontroller but
computer has many communication ports like Serial Port, USB Port, Parallel Port .
Suppose we take serial port which defines voltage level as 0 &1.Serial Ports protocol
is called as UART (Universal Asynchronous Receiver & Transmitter);its voltage levels
are +12v for 0 logic and -12v for logic 1.
Now the voltage levels of our microcontrollers are based on CMOS (Complementary
metal oxide semiconductors) technology which has 0v for 0 logic and +5v for 1 logic.

86 G.P AGRAWAL
So, to exchange information between microcontroller and computers Serial Port ,we
have a circuit like mediator called PROGRAMMER which converts CMOS
(microcontroller) to UART (serial port) and vice versa. Now we can connect computer to
the microcontroller and feed the machine file to the flash memory of microcontroller.

Compiler/IDE(Integrated Development Environment)

Atmel Microcontrollers are very famous as they are very easy to use.There are many
development tools are available for them. First of all we need an easy IDE for developing
code.So we use CVAVR(code vision AVR). It has limitation of code size.

Programmer

Programmer basically consists of two parts:


1. Software part(to open .hex file on your laptop)
2. Hardware (to connect microcontroller)

87 G.P AGRAWAL
For the installation of Microcontroller (ATMEL),we need following softwares & hardwares:
Softwares:
1. Usbtiny
2. com0com
3. AvrStudio
4. CodeVisionAVR
5. usbtinyisp w64 driver
6. USB to Serial
7.Deso 13b application(to give test mode in window7)
8.Protieus(for simulation of circuit)
Hardwares:
1. USB-Boarduino Board
2. USBTiny ISP AVR Programmer

CodeVisionAVR
An IDE has following functions:
Preprocessing
Compilation
Assembly
Linking
Object Translation
88 G.P AGRAWAL Text Editor
If we just use compiler and linker independently we still need to get a text editor. So combining
everything will actually mess things up. So the best way is to get Software which has it all. Thats
called an Integrated Development Environment, in short IDE.
We will use CVAVR as the best IDE for getting started with AVR programming .It has a very good
code wizard which generates codes automatically. You need not mess with assembly words.

Select the chip and its frequency (at which it is running) for which you are going to write
program. PORT is usually a collection of 8 pins.

Now you will select pins which you want to configure as output or input. It basically writes DDR
and PORT registers through this setting. Registers are basically RAM locations which configure
various peripherals of microcontroller and by changing value of these registers we can change the
function it is performing. All the details are provided in its Datasheet.

For Atmega-8 which has 3 Ports(B,C,D). You can also set initial values of the pins you want to
assign or if you are using a pin as input then whether you want to make it as PULL-UP or
tristated.
Similarly using this code wizard you can very easily configure all the peripherals on the Atmega.
Now for generating code just go to FILE->GENERATE->,SAVE and then EXIT(code wizard).
Now give file name and location for saving three files.Two file will be project file and one will be .C
file (program file). Give same name to all files to avoid confusion. These files will be generated in
89
C:\CVAVR\bin.
G.P AGRAWAL
The generated program will open in the text editor.it will have some declarations like PORT,
DDR and many more . These are all registers which configures various configuration of Atmega
and by changing these value we can make different functions.We put our part of code in the
infinite while loop provided by the code wizard.

In this code wizard all registers will be configured automatically and now we have to generate
the hex file ,so first compile the program. Either press F9 or go to Project->Compile.

It will show compilation error if any.if program is free we can proceed to making of hex file. So
either press shift+F9 or go to Project->Make or simply you can BUILD the project. Now the
machine file will become ready and it will be in the same folder where we saved those three files.

Let us take an example to write a program of Blinking Led by using Atmega8l


microcontroller
I will show only screen-shots of CVAVR.
Let us see what happens step by step:---

90 G.P AGRAWAL
91 G.P AGRAWAL
92 G.P AGRAWAL
93 G.P AGRAWAL
94 G.P AGRAWAL
95 G.P AGRAWAL
96 G.P AGRAWAL
97 G.P AGRAWAL
98 G.P AGRAWAL
99 G.P AGRAWAL
100 G.P AGRAWAL
Now your program is ready .you
have created all three files. So now
you have to feed .HEX file in the
flash memory of Microcontroller.

Feed the code using


programmer circuit and softwares
like USB -tiny500 and AVR Studio.

After successful feeding of code


into the microcontroller you will
become able to see results for
which you have written this code.

For simulation of your code of


microcontrollers you may use the
software PROTIUS because it is
student friendly software which
contains many virtual devices. It
can be used for simulation
purpose.

101 G.P AGRAWAL


Introduction to Atmega 8 Microcontrollers

Features

High-performance, Low-power AtmelAVR 8-bit Microcontroller


Advanced RISC Architecture
130 Powerful Instructions Most Single-clock Cycle Execution
32 8 General Purpose Working Registers
Fully Static Operation
Up to 16MIPS Throughput at 16MHz
On-chip 2-cycle Multiplier
High Endurance Non-volatile Memory segments
8Kbytes of In-System Self-programmable Flash program memory
512Bytes EEPROM
1Kbyte Internal SRAM
Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
Data retention: 20 years at 85C/100 years at 25C(1)
Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
Programming Lock for Software Security
102 G.P AGRAWAL
Peripheral Features
Two 8-bit Timer/Counters with Separate Prescaler, one Compare Mode
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
Real Time Counter with Separate Oscillator
Three PWM Channels
8-channel ADC in TQFP and QFN/MLF package
Eight Channels 10-bit Accuracy
6-channel ADC in PDIP package
Six Channels 10-bit Accuracy
Byte-oriented Two-wire Serial Interface
Programmable Serial USART
Master/Slave SPI Serial Interface
Programmable Watchdog Timer with Separate On-chip Oscillator
On-chip Analog Comparator
Special Microcontroller Features
Power-on Reset and Programmable Brown-out Detection
Internal Calibrated RC Oscillator
External and Internal Interrupt Sources
Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, and
Standby
103 G.P AGRAWAL
I/O and Packages
23 Programmable I/O Lines
28-lead PDIP, 32-lead TQFP, and 32-pad QFN/MLF
Operating Voltages
2.7V - 5.5V (ATmega8L)
4.5V - 5.5V (ATmega8)
Speed Grades
0 - 8MHz (ATmega8L)
0 - 16MHz (ATmega8)
Power Consumption at 4Mhz, 3V, 25C
Active: 3.6mA
Idle Mode: 1.0mA
Power-down Mode: 0.5A

The AtmelAVR ATmega8 is a low-power CMOS 8-bit microcontroller based on the


AVR RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega8
achieves throughputs approaching 1MIPS per MHz, allowing the system designer to optimize power
consumption versus processing speed.
For more information study Datasheet of Atmega 8.

104 G.P AGRAWAL


105 G.P AGRAWAL
ATMEGA-16
Features

106 G.P AGRAWAL


PIN Configuration

107 G.P AGRAWAL


ATMEGA-32

8-bit
Microcontroller
with 32KBytes
In-System
Programmable
Flash

108 G.P AGRAWAL


Pin Description of Atmega8

VCC: Digital supply voltage


GND: Ground
Port B (PB7..PB0)
XTAL1/XTAL2/TOSC1/
TOSC2:
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each
bit). The Port B output buffers have symmetrical drive characteristics with both high
sink and source capability. As inputs, Port B pins that are externally pulled low will source current
if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition
becomes active, even if the clock is not running.
Depending on the clock selection fuse settings, PB6 can be used as input to the inverting
Oscillator amplifier and input to the internal clock operating circuit.
Depending on the clock selection fuse settings, PB7 can be used as output from the inverting
Oscillator amplifier.
If the Internal Calibrated RC Oscillator is used as chip clock source, PB7..6 is used as TOSC2..1
input for the Asynchronous Timer/Counter2 if the AS2 bit in ASSR is set.

109 G.P AGRAWAL


Port C (PC5..PC0): Port C is an 7-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port C output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port C pins that are externally pulled low will
source current if the pull-up
resistors are activated. The Port C pins are tri-stated when a reset condition becomes active,
even if the clock is not running.

PC6/RESET: If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note that the
electrical characteristics of PC6 differ from those of the other pins of Port C.
If the RSTDISBL Fuse is unprogrammed, PC6 is used as a Reset input. A low level on this pin
for longer than the minimum pulse length will generate a Reset, even if the clock is not running.

Port D (PD7..PD0): Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and
source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port D pins are tri-stated when a reset condition becomes active,
even if the clock is not running.

110 G.P AGRAWAL


RESET : Reset input. A low level on this pin for longer than the minimum pulse length will
generate a reset, even if the clock is not running.

AVCC : AVCC is the supply voltage pin for the A/D Converter, Port C (3..0), and ADC (7..6). It
should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should
be connected to VCC through a low-pass filter. Note that Port C (5..4) use digital supply voltage,
VCC.

AREF : AREF is the analog reference pin for the A/D Converter.

111 G.P AGRAWAL


Registers
All the configurations in microcontroller is set through 8 bit (1 byte) locations in RAM
(RAM is a bank of memory bytes) of the microcontroller called as Registers. All the
functions are mapped to its locations in RAM and the value we set at that location
that is at that Register configures the functioning of microcontroller. As Register size
of this microcontroller is 8 bit, it called as 8 bit microcontroller.

I/O PORTS

Input Output functions are set by Three Registers for each PORT :-

1. DDRX ----> Sets whether a pin is Input or Output of PORTX.


2.PORTX ---> Sets the Output Value of PORTX.
3.PINX -----> Reads the Value of PORTX.

112 G.P AGRAWAL


DDRX (DATA DIRECTION REGISTERS)

To set a pin to act as output or input , we use DDRX register . Every bit corresponds to one pin of
PORTX.
For example take DDRD register:
Bit 7 6 5 4 3 2 1 0

PIN PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0

Now to make a pin act as I/O we set its corresponding bit in its DDR register.
To make Input set bit 0
To make Output set bit 1

If I write DDRD = 0xFF (0x for Hexadecimal number system) that is setting all the bits of
DDRD to be 1, will make all the pins of PORTD as Output.
Similarly by writing DDRD = 0x00 that is setting all the bits of DDRD to be 0, will make all
the pins of PORTD as Input.

113 G.P AGRAWAL


Now lets take another example. Consider I want to set the pins of PORTB as shown in
table:

PORTB PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0

FUNCTION O/P O/P I/P O/P I/P I/P I/P O/P

DDRB 1 1 0 1 0 0 0 1

For this configuration we have to set DDRB as 11010001 which in hexadecimal is D1. So we
will write DDRB=0xD1

DDRX -----> to set PORTX as input/output with a byte.


DDRX.y ---> to set yth pin of PORTX as input/output with a bit (works only with CVAVR).

114 G.P AGRAWAL


PORTX (PORTX DATA REGISTERS)

OUTPUT PIN
If a pin is set to be output, then by setting bit 1 we make output High and by setting bit
0 we make output Low .
Lets take an example. Consider I have set DDRB=0xFF, that is all the pins to be
Output. Now I want to set Outputs as shown in table,

PORTB PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0

VALUE H H L L L H H L

PORTB 1 1 0 0 0 1 1 0

For this configuration we have to set PORTB as 11000110 which in


hexadecimal is C6. So we will write PORTB=0xC6;

115 G.P AGRAWAL


INPUT PIN
If a pin is set to be input, then by setting its corresponding bit in PORTX register will
make it as follows,

Set bit 0 ---> Tri-Stated


Set bit 1 ---> Pull Up

Tristated means the input will hang (no specific value) if no input voltage is specified on
that pin.
Pull Up means input will go to +5V if no input voltage is given on that pin. It is basically
connecting PIN to +5V through a 10K Ohm resistance.

PORTX ----> to set value of PORTX with a byte.


PORTX.y --> to set value of yth pin of PORTX with a bit (works only with CVAVR).

116 G.P AGRAWAL


PINX (DATA READ REGISTERS)

This register is used to read the value of a PORT. If a pin is set as input then
corresponding bit on PIN register is,

0 for Low Input that is V < 2.5V


1 for High Input that is V > 2.5V (Ideally, but actually 0.8 V - 2.8 V is error zone !)

For an example consider I have connected a sensor on PC4 and configured it as an


input pin through DDR register. Now I want to read the value of PC4 whether it is Low
or High. So I will just check 4th bit of PINC register.
We can only read bits of the PINX register; can never write on that as it is meant for
reading the value of PORT.

PINX ----> Read complete value of PORTX as a byte.


PINX.y --> Read yth pin of PORTX as a bit (works only with CVAVR).

117 G.P AGRAWAL


LCD INTERFACING
we are going to interface an LCD to our microcontroller so that we can display messages,
outputs, etc. We will use the 16x2 LCD, which means it has two rows of 16 characters each.
Hence in total we can display 32 characters.

CIRCUIT CONNECTION

There are 16 pins in an LCD;


See reverse side of the LCD
for the PIN configuration.
The connections have to be
made as shown below:

118 G.P AGRAWAL


119 G.P AGRAWAL
Setting up in Microcontroller
When we connect an LCD to Atmega8, one full PORT is allowed to it, denoted by PORT-X in the
figure. select the PORT at which you want to connect the LCD. We will select PORTB. Also select
the number of characters per line in your LCD. This is 16 in our case. Code Wizard now shows you
the complete list of connections .

120 G.P AGRAWAL


Pin 3 (VEE) is for the LCD contrast, ground it through a <1k resistance/ potentiometer for
optimum contrast. Pin 15 & 16 (LEDA and LEDK) are for LCD backlight, give them
permanent +5V and GND respectively as we need to glow it continuously.

Printing Function

lcd_clear() : Clears the lcd. You should Call this function before the while(1)
loop, otherwise you will not be able to see anything.

lcd_gotoxy(x,y)
Place the cursor at coordinates (x,y) and start writing from there. The first
coordinate is (0,0). Hence, x ranges from 0 to 15 and y from 0 to 1 in our LCD. Suppose
you want to display something starting from the 5th character in second line, then the
function would be
lcd_gotoxy(5,1);
lcd_putchar(char c)
To display a single character. E.g.,
lcd_putchar(H);
121 G.P AGRAWAL
lcd_putsf(constant string)
To display a constant string. Eg,
lcd_putsf(My name is GP Agrawal);

lcd_puts(char arr)
To display a variable string, which is nothing but an array of characters (data type char) in
C language . e.g., You have an array char a[10] which keeps on changing. Then to display
it, the function would be called as
lcd_puts(a);

Now we have seen that only characters or strings (constant or variable) can be displayed
on the LCD. But if we have to display values of numeric variables, then it is not possible
directly. so we convert that numeric value to a string and then display it. For e.g., if we
have a variable of type integer, say int i, and we need to display the value of i .For this, we
use the C functions itoa() and ftoa(), but remember to include the header file stdlib.h to use
these C functions.

122 G.P AGRAWAL


itoa(int val, char arr[ ])
It stores the value of integer val in the character array arr .
E.g., we have already defined int i and char a[20], then
itoa(i,a);
lcd_puts(a);

ftoa(float val, char decimal_places, char arr[ ])


It stores the value of floating variable f in the character array arr with the
number of decimal places as specified by second parameter.
E.g., we have already defined float f and char a[20], then
ftoa(f,5,a); // till 5 decimal places
lcd_puts(c);

123 G.P AGRAWAL


SERIAL PORT OF COMPUTER

We will be using Serial Port for communication between the uC and the computer. A
serial port has 9 pins as shown. If you have a laptop, then most probably there wont be
a serial port. Then you can use a USB to serial Converter.
If you have to transmit one byte of data, the serial port will transmit 8 bits as one bit at a
time. The advantage is that a serial port needs only one wire to transmit the 8 bits.

124 G.P AGRAWAL


125 G.P AGRAWAL
Pin 3 is the Transmit (TX) pin, pin 2 is the Receive (RX) pin and pin 5 is Ground pin. Other
pins are used for controlling data communication in case of a modem. For the purpose of
data transmission, only the pins 3 and 5 are required.

The standard used for serial communication is RS-232 (Recommended Standard 232). The
RS-232 standard defines the voltage levels that correspond to logical one and logical zero
levels. Valid signals are plus or minus 3 to 15 volts. The range near zero volts is not a valid
RS-232 level; logic one is defined as a negative voltage, the signal condition is called
marking, and has the functional significance of OFF. Logic zero is positive; the signal
condition is spacing, and has the function ON.

Now we know that this is not the voltage level at which our microcontroller works. Hence, we
need a device which can convert this voltage level to that of CMOS, i.e., logic 1 = +5V and
logic 0 = 0V. This task is carried out by an IC MAX 232, which is always used with four 10uF
capacitors.

126 G.P AGRAWAL


127 G.P AGRAWAL
128 G.P AGRAWAL
129 G.P AGRAWAL
130 G.P AGRAWAL
131 G.P AGRAWAL
ADC:ANALOG TO DIGITAL CONVERTER

What we have seen till now that the input given to uC was digital, i.e., either +5 V (logic 1) or
0V (logic 0). But what if we have an analog input, i.e., value varies over a range, say 0V to
+5V? Then we require Analog to Digital Converter (ADC) to convert this analog voltage to
discrete values.

ADC pin is available in Atmega8. we can apply analog voltage and get corresponding digital
values. We use only 8 bit out of it (0 to 255) as too much precision is not required.
Reference voltage is the voltage to which the ADC assigns the maximum value (255 in case of
8 bit ). Hence, the ADC of Atmega8 divides the input analog voltage range (0V to Reference
Voltage) into 256 equal parts since8 bit ADC is used. For example, if the reference voltage is
5V and we use 8bit ADC, 0V has digital equivalent 0, +5V is digitally 255 and 2.5V is
approximately equal to 128.

132 G.P AGRAWAL


133 G.P AGRAWAL
TM4C123G LAUNCHPAD

134 G.P AGRAWAL


135 G.P AGRAWAL
136 G.P AGRAWAL
137 G.P AGRAWAL
138 G.P AGRAWAL
139 G.P AGRAWAL
We shall learn about ARM Microprocessor in volume 2.

140 G.P AGRAWAL


Atmega 8 Datasheet
www.wikipedia.org
www.best-microcontroller-projects.com
www.google.com
U.A. Bakshi,A.P.Godse(2009).Basic electronics Engineering.
A.K. Sharma(2001),semiconductor Electronics
Datasheets of ICS ,sensors and ARM microprocessor
Ankita and Ridhish (Electronics club ,IITB)

141 G.P AGRAWAL

You might also like