1. BY - SAYAK CHOUDHURY
BRANCH - EEE
ROLL No. 1007160
2. MAIN FEATURES
High-performance, Low-power , 8-bit Microcontroller
Advanced RISC Architecture
131 Powerful Instructions – Most Single-clock Cycle Execution
32 x 8 General Purpose Working Registers
Fully Static Operation
Nonvolatile Program and Data Memories
16K Bytes of In-System Self-Programmable Flash
Endurance: 10,000 Write/Erase Cycles
True Read-While-Write Operation
512 Bytes EEPROM
1K Byte Internal SRAM
On-chip Analog Comparator
Programming Lock for Software Security
JTAG (IEEE std. 1149.1 Compliant) Interface
Boundary-scan Capabilities According to the JTAG Standard
Extensive On-chip Debug Support
Programming of Flash, EEPROM, Fuses, and Lock Bits through the JTAG
Interface
3. MAIN FEATURES CONTD…
Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
One 16-bit Timer/Counter with Separate Prescaler & Compare Mode
Real Time Counter with Separate Oscillator
Four PWM Channels
8-channel, 10-bit ADC
2 Differential Channels with Programmable Gain at 1x, 10x, or 200x
Byte-oriented Two-wire Serial Interface
Programmable Serial USART
Master/Slave Serial Interface
Power-on Reset
Internal Calibrated RC Oscillator
External and Internal Interrupt Sources
Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby
and Extended Standby
40-pin PDIP, 44-lead TQFP, and 44-pad MLF Package
Operating Voltage 4.5 - 5.5V
Speed Grades 0 - 16 MHz
6. ATMEGA 16 DATASHEET
DATA SHEET
Now the most important part of Atmega 16
How to use Atmega 16 microcontroller in
embedded system?
What is embedded system?
Why embedded system used?
Where embedded systems are used?
8. HOW TO WRITE ON A BIT OR READ FROM
BIT
Set the bit PX0 as input or output by
DDRX|=(1<<0) to set PX0 as output and
DDRX&=~(1<<0) to set PX0 as input pin
Write something on the bit PX0 by
PORTX|=(1<<0) to write 1 on PX0
PORTX&=~(1<<0) to write 0 on PX0
Read from the bit PX0 by
Unsigned int h;
h=PINX; h&=(1<<0);
Then h will be the data present in the PX0
pin.
9. HOW TO SET AND RESET A BIT
Suppose we have to set PX0 then write
PORTX |=(1<<0) or PORTX|=_BV(PX0)
PORTX=0bddddddd1 or PORTX = 1
PORTX=0xd1 or
Now suppose we have to reset PX0 then write
PORTX &=~(1<<0) or PORTX&=~(_BV(PX0)) PORTX= 0xd0 or
PORTX=0bddddddd0 or PORTX = 0
Here ‘d ‘ denotes the don’t care
First 2 ways are convenient because the other bits are not
affected by this way
10. HOW TO TOGGLE A BIT
Now suppose we have to toggle PB0 with a delay of 500ms
Put a delay header file by
#include<util/delay.h>
PORTB =^(1<<0) ;_delay_ms(500); or
PORTB=^(_BV(PB0)) ;_delay_ms(500);or
PORTB=0xd1;_delay_ms(500);
PORTB=0xd0;_delay_ms(500);or
PORTB=0bddddddd1; _delay_ms(500);
PORTB=0bddddddd0; _delay_ms(500);or
PORTB=1; _delay_ms(500);
PORTB=0;_delay_ms(500);
Here also the first two ways are convenient because of the
same reason.
11. EEPROM
Code to write data to EEPROM
Void write(unsigned int add,unsigned char data)
{ wait();
while(EECR&(1<<EEWE));
EEAR=add;
EEDR=data;
EECR|=(1<<EEMWE);
EECR|=(1<<EEWE);
}
Code to read data from EEPROM
Unsigned char read(unsigned int add)
{ wait();
while(EECR&(1<<EEWE));
EEAR=add;
EECR|=(1<<EERE);
return EEDR;
}
12. SUT is used to control the
frequency at low frequency
CKSEL =1
to 4
CKSEL = 5 to
8
CKSEL = 0
CKSEL = A
CKSEL=9
13. MODES AND POWER MANAGEMENT
MCUCR is the register responsible for determining
the mode of operation.
14. SYSTEM CONTROL & RESET
POWER ON RESET
2.
EXTERNAL RESET
3.
BROWN OUT DETECTION Typical time out of WDT for 5V
VCC is
4.
WATCHDOG RESET
16.3ms to 2.1sec
5.
JTAG RESET
MCUCSR register defines the reset condition and
cause of reset
Watchdog timer control register(WDTCR)
1.
--------
--------
-------- WDTOE
WDE
WDP2
WDP1
WDP0
17. USART CONTD…
PROGRAMMING CONCEPT
#include <avr/io.h>
#include <inttypes.h>
void USARTInit(uint16_t ubrr_value){
UBRRL = ubrr_value;
UBRRH = (ubrr_value>>8);
UCSRC=(1<<URSEL)|(3<<UCSZ0);
UCSRB=(1<<RXEN)|(1<<TXEN);}
char USARTReadChar(){
while(!(UCSRA & (1<<RXC))){}
return UDR;}
void USARTWriteChar(char data){
while(!(UCSRA & (1<<UDRE))){}
UDR=data;}
This function is used to set
baud rate and initialize the
USART communication
This function is used to read data
from RXD pin
This function is used to write data
to TXD pin
18. USART CONTD…
void main()
{
char data;
USARTInit(103); //UBRR = 103
while(1)
{
DDRB=0xFF;
data=USARTReadChar();
PORTB=data;
};
Return 0;
}
One more thing windows hyperterminal is required, where
we have to put the communication port number and baud
rate taking the data from device manager of the PC after
connecting ATMEGA16
19. TWO WIRE INTERFACE(TWI)
This is the interconnection of one AVR
microcontroller with several AVR microcontrollers.
…….
DEVICE
1
DEVICE
2
DEVICE
3
DEVICE
4
DEVICE
n
SDA
SCL
22. JTAG CONTD…
The
JTAGEN fuse must be programmed and
the JTD bit in the MCUSR Register must be
cleared to enable the JTAG Test Access Port.
The JTAG programming capability supports:
1.
Flash programming and verifying
2. EEPROM programming and verifying
3. Fuse programming and verifying
4. Lock bit programming and verifying
Now, What is boundary scan?
Why we have to use JTAG?
What is device identification register?
23. REST OF THE TOPICS CAN BE VISUALIZED
BY PROTEUS8.0 SOFTWARE THAT’S WHY
EXPLAINED BY DEMO OF SOME PROJECTS
The topics are:
1. TIMER /COUNTER
2. PULSE WIDTH MODULATION
3. ANALOG TO DIGITAL CONVERSION
4. COMPARATOR
5. USART
6. LCD INTERFACE
7. KEYBOARD INTERFACE
8. MOTOR INTERFACE
25. SOME INTERESTING PROJECTS CONTD...
3.Temperature display using Interrupt, ADC and LCD
interface
4.USART communication using hyperterminal to see the
ASCII value of any character
26. SOME INTERESTING PROJECTS CONTD...
5.Line follower Robot using ADC, Motor interface, PWM
and timer/counter and LCD interface
6.Password protected door lock system using keyboard
interface, motor interface and LCD interface