1
PROGRAMMABLE
CIRCUITS AND
MICROCONTROLLERS
These are lecture notes to accompany the books:
Mohammad Ali Mazidi, The 8051 Microcontroller and embedded
•
systems.2006
Milan Verle, PIC Microcontrollers - Programming in C, 2009
•
Course Outline
2
Introduction to Digital systems.
PIC Microcontrollers architecture.
Programming Microcontrollers C-Language
The 8051 Microcontrollers
8051 Assembly Language programming
Overview on Arduino development
environment and programming language.
What is a Microcontroller?
3
Microcontroller Applications
4
Microcontroller Applications
5
Introduction to Digital
6
To understand the software and hardware of a
microcontroller based systems, one first must
have knowledge is some basic concepts under
computer design.
Fundamentals of numbering and coding systems.
Introduction to logic gates.
Numbering and coding systems
7
The numbering system we use (human)
everyday is decimal. Computers use BINARY
system.
Decimal Base 10. (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Binary Base two. (0, 1)
Converting form Binary to Decimal
8
To convert form binary to decimal, it is important
to understand the weight concept of each digit.
Weight of number (740683)10
3 x 100 =3
8 x 101 =80
6 x 102 =600
0 x 103 =0
4 x 104 =40000
7 x 105 =700000
Converting form Binary to Decimal
9
Ex 1:
Convert (11001)2 to Decimal:
Weight: 16 8 4 2 1
Digits: 1 1 0 0 1
Sum: 16+ 8+ 0+ 0+ 1=2510
Converting form Binary to Decimal
10
Ex2:
Convert (110110.01)2 to Decimal
1 x 2-2 =0.25
0 x 2-1 =0
0 x 20 =0
1 x 21 =2
1 x 22 =4
0 x 23 =0
1 x 24 =16
1 x 25 =32
Sum= (54.25)10
Converting form Decimal to Binary
11
Ex 3:
Convert (25)10 to Binary.
Quotient Reminder
25/2 = 12 1 (LSB)
12/2= 6 0
6/2= 3 0
3/2= 1 1
½= 0 1 (MSB)
Therefore (25)10 is (11001)2
Hexadecimal System
12
Base 16, the hexadecimal system is used in a
convenient representation of binary numbers.
It is much easier for us to represent a binary
number 111100110101 as its hexadecimal
number F25H.
The Hexadecimal (Base 16) : 0-9, A, B, C, D,
E and F.
Decimal – Binary - Hexadecimal13
13
Converting between Binary and Hex
14
Ex4: Represent (100111110101)2
Solution:
1- Group each 4 bits: 1001 1111 0101
2- Replace each 4 bits with its hex equivalent:
1001 9, 1111F, 01015
Therefore (100111110101)2 =9F5H
Convert Hex to Binary
15
Ex5: Convert 3A9H to Binary
3 0011, A 1010, 91001
So (3A)16 = (001110101001)2
Converting from decimal to hex
16
Two ways:
1- Convert to binary then to hex
Convert directly to hex, by repeated division by
16 and keep tracking the reminder.
Converting from decimal to hex
17
Ex 6: Convert 4510 To Hex
First convert to binary (sum of weight method):
32 16 8 4 2 1
1 0 1 1 0 1
32+8+4+1= 4510 = 1011012
4510 = (0010 1101)2 = 2D16
Convert from hex to decimal
18
Convert by summing all weights or convert to
binary then decimal.
Counting in bases 10,2 and 16
19
Counting in bases 10,2 and 16
20
Addition of binary
21
Add the following numbers:
Binary Decimal
1101 13
1001 + 9 +
10110 22
Addition of hex numbers
22
Ex:7 Perform Hex addition : 23D9+94BE
23D9 LSD: 9+14=231017H
94BE + 1+13+11=251019H
B897 1+3+4=810 8H
MSD: 2+9=1110BH
ASCII Code
23
American Standard Code for Information
Interchange.