1. Apeejay Stya University
Department of Electronics and Communication Engineering
Course: Embedded System and Design ETEC-210
Project REPORT
Submitted by:
BANZADIO SALAZAKU asu2013010100016
2. Acknowledgment
I am truly thankfulto all the faculties who imparted the lectures on various
subjects/topics and took us to the plant in a guided study visitalong with detailed
explaining about the plant and machinery. An Electronics studentmainly focuses
on practical applications of concepts learned projects like this one provideus with
an ideal opportunity to do the same.
Last but not least, a big thanks to all our family members and friends, for timely
cooperation and supportextended to us all the way.
3. INDEX
S. No. content
1. Overview of Embedded Systems
2. Introduction to Atmega16 microcontroller
3. Analog to Digital converter
4. Timers in Atmega16
6. LCD Interfacing
7 Program
4. Introduction:-
Embedded system is a scaled down computersystem which is designed to
perform a specific taskor operation. The whole system is embedded into
an appliance. This reduces human effortto a great extent. A single chip
contains both hardware and software.
Some important things to note about embedded systems:
1. Once an embedded hardware is programmed fora certain task, it is
used foreverfor the same task. Changing the firmware afterwards is not
possible.
2. Such systems are limited in computational resources like memory, CPU
processing speed,I/O facilities but are still capable of performing the task
given to them very efficiently.
3. Embeddedsystems can also be having a reduced functionality version
of operating system called RTOS (Real Time Operating System) for highly
specialized applications.
4. Interacts with physical elements in our environment, viz. controlling and
driving a motor, sensing temperature, etc.
5. EMBEDDED SYSTEM IN DAILY LIFE
Digital Clock Traffic Light
DVD Player Smart Phones
2. MICROCONTROLLER
A Microcontroller is a programmabledigital processor with necessary peripherals.
Both microcontrollers and microprocessors arecomplexsequential digital circuits
meant to carry outjob according to the program/ instructions.
ATMEGA16 MICROCONTROLLER:
We will be working on Atmega16 microcontroller,which is a 40-pin IC and
belongs to the MegaAVR category of AVR family.
Some of the features of Atmega16 are:
16KB of Flash memory
1KB of SRAM
512 Bytes of EEPROM
Available in 40-Pin DIP
8- Channel 10-bit ADC
Two 8-bit Timers/Counters
One 16-bit Timer/Counter
4 PWM Channels
Serial USART
6. Digital to Analog Comparator
PIN DIAGRAM
I/O PORTS
InputOutputfunctions are set by Three Registers for each PORT.
• DDRX ‐‐‐‐>Sets whether a pin is Inputor Outputof PORTX.
• PORTX ‐‐‐> Sets the OutputValue of PORTX.
• PINX ‐‐‐‐‐>Reads the Value of PORTX.
(WhereX= A, B, C or D)
DDRX (Data DirectionRegister)
Now to make a pin act as I/O we set its corresponding bitin its DDRregister.
• To make Inputset bit 0
• To make Outputset bit 1
PORTX(PORTXData Register)
If a pin is set to be output, then by setting bit 1 wemake output High that
is +5V and by setting bit 0, make output Low that is 0V.
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.
PORTX ‐‐‐‐> to set value of PORTX with a byte.
7. PORTX.y ‐‐>to set value of yth pin of PORTX with a bit (works only with
CVAVR).
PINX (Data ReadRegister) This register is used to read the value of a PORT. If a
pin is set as input then corresponding biton PINregister is,
• 0 for Low Inputthat is V < 2.5V
• 1 for High Inputthat is V > 2.5V (Ideally, butactually 0.8 V ‐ 2.8 V is error zone!)
• PINX ‐‐‐‐>Read complete value of PORTX as a byte.
• PINX.y ‐‐>Read yth pin of PORTX as a bit (works only with CVAVR).
SOFTWARE
The softwarewhich supportthis hardwareand can communicate with micro
controller using this circuit is-
• AVRStudio 4
3. Analog to Digital Converters
Microcontroller understands only digital language.
To convert the analog output from the sensors to digital we
need ADC.
In AVR family of microcontroller we have inbuilt ADC on
PORTA. Each pin in PORTA has an ADC circuit connected
behind it. Thus we have 8 channels of ADC.
The resolution of ADC output is 10 bit i.e. the output from the
ADC is any number between 0 to 1023
ADC registers:
The inbuilt ADC of AVR microcontroller have three register
which are used for configuring the ADC. They are:
8. ADMUX: it is used for selecting the ADC pin to be used for
connecting the Analog sensors.Itis also used forsetting the
reference value of the ADC.
ADSCRA:itis used forcontrolling the ADC e.g.when should
it start the conversion? Should it repeat the conversion?
Should interrupt be generated after the conversion is
complete? Etc.
ADCH & ADCL: these are used for storing the ADC output
values. Both the registers are 8 bit wide and we require 10
bits for storing the ADC value. Thus the two registers are
used. The way of storing the ADC value is configured using
ADSCRA.
ADMUX
ADLAR:-This bit is setting the manner, the ADC result will be
stored in ADC data register.
ADLAR = 0
9. ADCH& ADCL
ADCSR
4. Timers in ATMega16
In Atmega16, we have three timers:TIMER0 TIMER1 and
TIMER2
Out of these, TIMER0 and TIMER2 are 8 bit timer, while
TIMER1 is a 16 bit timer.
10. All the timers have three unique registers and two common
registers.
TIMER1 has a special register, called ICR(Input Capture
Register).It has two channels(channel A and channel B).
TIMER2 has a specialregister known as ASSR, which is used
two generate PWM using asynchronous clock.
Timer Registers
• Each timer has three registers. They are:
TCCR(Timer Counter Control Register)
TCNT(Timer Counter),
OCR (Output Compare Register).
• Thus, three registers for TIMER0 are TCCR0, TCNT0 and
OCR0.
• Similarly for TIMER1 and TIMER2, we have TCCR1, TCNT1,
OCR1 and TCCR2, TCNT2 and OCR2.
• The three timers have two common registers. They are:
TIMSK (Timer Interrupt Mask)
TIFR (Timer Interrupt Flag Register
11. Register Function Description
• TCCR (Timer Counter Control Register): It is used for
configuring the timer i.e. modes and pre scale factor.
• TCNT: It stores the present value of the timer. It is used for
monitoring the status of the timer. After each incrementing in
the timer value, this register compares its value with the OCR
register value.
• OCR(Output Compare Register): It is used for setting the
required duty
Cycle
6. LCD INTERFACING
• LCD’s are all around us so liquid crystal displays are very useful in
these days.
• It is a kind of display that is made up of a special matter state formed
using liquid and crystal both , it’s a forth state of matter
• The most popular one is 16x2 LCD module.It has 2 rows & 16
columns. The intelligent displays are two types:
Text Display
Graphics Display
12. PIN DESCRIPTION
Figure 4.1: pin configuration for 16 X 2 LCD
8 data pins D7:D0
Bi-directional data/command pins. Alphanumeric characters are sent in
ASCII format.
RS: Register Select
RS = 0 -> Command Registeris selected
RS = 1 -> Data Registeris selected
R/W: Read or Write
0 -> Write, 1 -> Read
E: Enable (Latch data)
Used to latch the data present on the data pins.
A high-to-low edge is needed to latch the data.
VEE: contrastcontrol.
VDD & VSS: Power supply
VDD= +5V
VSS=G
13.
14. Program
Program /*-***********************************************************/
//----------------------9 Project9: Stop Watch-----------------------------
///////////lcd at port b,keypaid at porta(0-3) and portd(0-3)//////////////////-
*****************************************************************************
#include<avr/io.h>
#define F_CPU8000000UL
#include<util/delay.h>
#define lcd PORTB
#define rs 0
#define rw 1
#define en 2
void lcd_init();
void lcd_command(unsigned char);
void lcd_data(unsigned char);
void lcd_string(unsigned char *str);
void lcd_number(unsigned int);
int main()
{
unsigned char d,i;
unsigned char hr,min,sec,dec_sec;
DDRB = 0XFF;
DDRA = 0X00;
DDRD = 0XFF;
PORTA = 0XFF;