Uploaded by krish.tit

Embedded Systems

advertisement
An Introduction to
Embedded System Design
DEPARTMENT OF EMBEDDED SYSTEM
• An Embedded system is a combination of computer hardware and software which is designed to
perform many operations such as to access the data, process the data, store the data and also
control the data in electronics based systems. In embedded systems, software commonly known as
firmware Basically embedded systems are task specific devices
• Embedded system is defined as a way of working, organizing, performing single or multiple tasks
according to a set of rules
• Hence it covers all the industries like
- BIOTECHNOLOGY
-TELECOME
- MILTARY
- AUTOMOBIEL
- CONSUMER ELECTRONICS
APPLICATION
AVR (ADVANCED VIRTUAL RISC)
ATMEGA 8
MICRO- CONTROLLER
INTRODUCTIO
N
• ATmega8 is a 8 - b i t
microcontroller based on the AVR RISC
architecture
• By executing
powerful instructions in a single clock cycle, the
ATmega8 achieves throughput approaching 1 MIPS per MHz
• Instruction
in program memory are executed with single level
pipelining
• This concept
cycle
enables instructions to be executed in every clock
FEATURES
• High-performance 8 bit Microcontro ller
• 32 x 8 General Purpose Working Registers
• Six ADC channels in PDIP package
• Internal Calibrated Oscillator
MEMORY
SEGMENTS
• 8K Bytes of Flash program memory
• 512 Bytes EEPROM (Electrically Erasable Programmable Read
Only Memory)
1K Byte Internal RAM (Random Access Memory)
•
• Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
• Data retention: 20 years at 85°C/100 years at 25°C
TYPES OF PACKAGES
•28-pin
PDIP (Plastic Dual In-line Package)
opaque molded plastic pressed around a tin - ,
silver-, or gold-plated lead frame that supp orts the
device die and provides connection pins.
• 32-pin
TQFP (Thin Quad film Package)
For easy soldering
PIN
DESCRIPTION
• VCC Digital supply voltage
• GND Ground
• RESET A low level on this pin
for longer than the minimum
pulse length will generate a reset, even if the clock is not
running
• AREF The analog reference pin for the A/ D Converter
• AVCC The supply voltage pin for the A/ D Converter
PORTS
• Three ports
i.e PortB, PortC, PortD -General Purpose 8 Bit
bidirectional I/O
• Three registers associated with every port
DDRx – Data Direction Register
PINx – Port input
PORTx- Port output
*Note – ‘x’ is subscript and could be either of B, C, D
PORT B(PB7..PB0)
• Port B is an 8 - b i t
bi-directional I/O port
• Can be used either
as a input port or as output port ( direction
must be specified in programming)
REGISTER DESCRIPTION OF I/O PORTS
PROGRAMMING MICROCONTROLLER
USING EMBEDDED C
• Embedded C is nothing
but a subset of C language which is
compatible with certain microcontrollers.
• Some features are added using
header files like <avr/io.h>,
<util/delay.h>.
• scanf() and printf() are removed as the inputs are scanned from
the sensors and outputs are given to the ports.
• Control
structures remain the same like if-statement, for loop,
do-while etc.
SOFTWARE’S USED:
AVR STUDIO 4.0
AVR studio is an Integrated Development Environment (IDE) by ATMEL for
developing applications based on 8-bit AVR microcontroller
PROTEUS 7 DESIGN SUITE
• this software helps programmers in hardware implementations.
• It provides a huge number of electronic components and
• REAL TIME ANOMATONS of the hardware designs.
• This is the perfect tool for engineers to test their microcontroller designs Before constructing a
physical prototype in real time
HOW TO WORK AT AVR STUDIO
Step1. Start AVR Studio on your
workstation. Select "New Project".
Type is "AVR-GCC". Project name:
"MyFirstProject". Check off the
"create folder" box. Modify the
location if desired.
Step2. Click "Next".
CONTD…
Step3. Debug platform
should be "AVR
Simulator". Device Is
"ATMEGA 8".
Step4. Click Finish.
You will now be in the
IDE.
CONTD…
CONTD…
Step5.Write the following
code into the window in the
middle of the screen (the
window for My FirstProject.c):
This is a quick and dirty way to turn both
LEDs on.
This. code tells all of Port B to become
outputs by writing 0xFF (binary 1111 1111)
to DDRB which is the data direction register
for port B.
Step 6.Compile the code with "Build - > Build" from the menu, or the F7 shortcut
for "Build". The bottom window will show the progress and results. You should see
"Build succeeded with 0 warnings.
If there is an error, check your code for typos. The error message should give
you the offending line number
A successful compile will result in a .hex file being generated. This is the
binary code in a format ready to be burned into your AVR chip by the
programmer. (Think of the .hex file as a program that the target AVR chip can
run once we put it on there, sort of like writing to a memory card.)
You should be able to locate MyFirstProject.hex in your project dir. For me, it
was in "AVR\src\MyFirstProject\default\".
CONTD….
Step 7. Now let's debug the code in the simulator to get a feel for
how it works.
Use "Build - > Build and Run" from the menu, or use the CTRL-F7
shortcut.
Note the following:
We have a yellow arrow at the current execution.
We have some debugging keys at the top (we want STOP and STEP INTO now).
We have "AVR SIMULATOR" at the bottom which is no longer greyed out.
Now click on the right pane on PORTB so we can look at it in the "I/O View". The bottom
right window will populate with DDRB, PINB, and PORTB. These represent some states of the
simulator's virtual ATTINY45 hardware.
CONTD…
Step 8. Step through the program line by line with "STEP INTO
(F11)" button.
Notice DDRB (direction of pins for PORTB: input or output) changes on
the bottom right after "DDRB = 0xff" is executed.
Step 9. Step again and notice that PORTB becomes set to 0xff (all
logical 1 output) when "PORTB = 0xff" is executed.
We are now at the end of the program. Click "STOP DEBUGGING" (the
blue square button on the menu bar ) or CTRL-SHIFT-F5 to stop the
debugger and chip simulator and return to the coding view.
G
SOME EXAMPLESUSIN EMBEDDED C
1.
Blinking of even no. lights at p ort
HARDWARE INTERFACING'S AND CODING:
Seven Segment Interfacing with Microcontroller
 LCD interfacing with Microcontroller
7
SEGMENT
DISPLAY
CONTD…
LCD(4-BITS) INTERFACING
L C D 1
1
V
2
S
3
S
V
4
R
D
5
S
D
6
R
V
W
E
7
D
E
8
0
9
D
1
1
0
D
1
2
1
D
1
3
2
D
1
4
3
D
1
5
4
D
6
D
7
L M 0 1 6 L
U 1
1
1
1
1
1
1
4
5
6
7
8
9
9
1 0
2 1
2 0
P
P
P
P
P
P
P
P
B
B
B
B
B
B
B
B
0 / I C P 1
1 / O C 1 A
2 / S S / O C 1 B
3 / M O S I / O C 2
4 / M I S O
5 / S C K
6 /T O S C 1 / X T A L 1
7 /T O S C 2 / X T A L 2
A R E F
A V C C
A T M E G A 8
P
P
P
P
P C 4 / A
P C 5 / A
P C
C 0 / A D
C 1 / A D
C 2 / A D
C 3 / A D
D C 4 /S
D C 5 /S
6 / R E S
C 0
C 1
C 2
C 3
D A
C L
E T
P D 0 / R X D
P D 1 / T X D
P D 2 / IN T 0
P D 3 / IN T 1
P D 4 / T 0 /X C K
P D 5 / T 1
P D 6 / A IN 0
P D 7 / A IN 1
2
2
2
2
2
2
1
3
4
5
6
7
8
2
3
4
5
6
1 1
1 2
1 3
LCD(8-BITS) INTERFACING
LC D1
U1
14
15
16
17
18
19
9
10
21
20
PB0/ICP1
PB1/OC1A
PB2/SS/OC1B
PB3/MOSI/OC2
PB4/MISO
PB5/SCK
PB6/TOSC1/XTAL1
PB7/TOSC2/XTAL2
AREF
AVCC
ATM EGA8
PC0/A DC0
PC1/A DC1
PC2/A DC2
PC3/A DC3
PC4/A DC4/SDA
PC5/A DC5/SCL
PC6/RESET
PD0/RXD
PD1/TXD
PD2/INT0
PD3/INT1
PD4/T0/XCK
PD5/T1
PD6/A IN0
PD7/A IN1
23
24
25
26
27
28
1
2
3
4
5
6
11
12
13
7
8
9
1
0
1
1
1
2
1
3
1
4
4
5
6
1
2
3
VS
S
VD
D
VE
RS
E
R
W
E
D
0
D
1
D
2
D
3
D
4
D
5
D
6
D
7
LM016L
THANK YOU…
Download