L01 Embedded 22
L01 Embedded 22
Embedded System
Lecture 1
AVR PROGRAMMING IN C
Previously
• Microcontroller: ATmega328
2
1. The AVR microcontroller AVR Features
4
1. The AVR microcontroller AVR family groups: Classic, Mega, Tiny, and special purpose.
6
Objective
Unsigned Char
Using int in place of
char can lead to the
need for more memory
space. Which is limited
in AVR
9
2. DATA TYPES AND TIME DELAYS IN C Unsigned Char
10
11
2. DATA TYPES AND TIME DELAYS IN C Signed Char
The signed char is an 8-bit data type that uses the most significant bit (D7 of D7-D0) to
represent the - or +value. (-128 to + 127)
12
• The unsigned int is a 16-bit data type that takes a value in the range of 0 to 65.535
(0000-FFFFH).
• Unsigned int is used to define 16-bit variables such as memory addresses. It is also used
to set counter values of more than 256.
• Signed int
is a 16-bit
data type
that uses
the most
significant
bit (D15 of
DI5-D0) to
represent
the - or
+value. (-
32,768 to
+32,767).
13
2. DATA TYPES AND TIME DELAYS IN C Time Delay
Using a simple for loop
Factors that can affect the accuracy of the delay:
1. The crystal frequency connected to the XTAL1-XTAL2 input. The duration of the clock
period for the instruction cycle is a function of this crystal frequency.
2. The compiler used to compile the C program (might effect or ignore the loop) .
14
15
? Review Questions
1. Give the magnitude of the unsigned char and signed char data types.
2. Give the magnitude of the unsigned int and signed int data types.
compilers.
16
3. I/O PROGRAMMING IN C
All port registers of the AVR are both byte acces- sible and bit accessible.
17
3. I/O PROGRAMMING IN C +
18
3. I/O PROGRAMMING IN C +
19
4. LOGIC OPERATIONS IN C Bit-wise operators in C
20
4. LOGIC OPERATIONS IN C +
21
4. LOGIC OPERATIONS IN C +
22
4. LOGIC OPERATIONS IN C +
23
4. LOGIC OPERATIONS IN C +
24
4. LOGIC OPERATIONS IN C +
25
4. LOGIC OPERATIONS IN C +
26
4. LOGIC OPERATIONS IN C +
27
4. LOGIC OPERATIONS IN C +
28
4. LOGIC OPERATIONS IN C +
29
4. LOGIC OPERATIONS IN C +
Disassembly of Part (a)
30
4. LOGIC OPERATIONS IN C
31
4. LOGIC OPERATIONS IN C Bit-wise shift operation and bit manipulation
32
4. LOGIC OPERATIONS IN C +
33
4. LOGIC OPERATIONS IN C +
34
4. LOGIC OPERATIONS IN C +
35
4. LOGIC OPERATIONS IN C +
Notice that to
generate
more
complicated
numbers, we
can OR two
simpler
numbers. So
we can simply
write
(1<<7)|(1<<4)
.
36
? Review Questions
37