Professional Documents
Culture Documents
Topic 10
7-Segment LEDs
Objectives
Discuss 7-Segment LEDs
Turn on specific LED segments using code
Common-Anode, Common-Cathode
1/4/2010
7-Segment LEDs
Two categories:
Common-cathode
Common-anode
Common-Anode:
Logic 0 turns LED on
+ 5v
To Port
To Port
Common-Cathode:
Logic 1 turns LED on
1/4/2010
7-Segment LEDs
A 7-Segment LED could be attached as shown
Atmega128
PB0
PB1
PB2
PB3
b
c
d
120
a
f
g
d
e
PB5
PB7
PB4
PB6
1/4/2010
e
d
7-Segment LEDs
If 0b00111111 was output on Port B, the following
segments would be on
Atmega128
PB4
PB5
PB0
PB1
PB2
PB3
PB6
PB7
120
a
g
d
e
f
e
d
7-Segment LEDs
If 0b00111111 was output on Port B, the following
segments would be on
Atmega128
PB4
PB5
PB0
PB1
PB2
PB3
PB6
PB7
120
a
g
d
e
f
e
d
Common-Cathode
1/4/2010
Program Specifications
Write an assembly language program to:
Read two 8 bit binary numbers from Port A and Port B
Use pull-up resistors
Use Port E, pin 0 to let the AVR know the numbers are
ready to be read
A 0 on pin 0 means NOT READY, a 1 on pin 0 mean READY
Flowchart:
Start
Port Initializations
A
Read b0 Port E
b0 = 1
1/4/2010
Flowchart:
Start
Port Initializations
A
Read b0 Port E
b0 = 1
1/4/2010
Flowchart:
Start
Port Initializations
A
Read b0 Port E
b0 = 1
Separate high
& low nibbles
1/4/2010
00
FF
00
FF
00
FF
FF
00
FF
00
DDRA
PortA: use pull-ups
DDRB
PortB: use pull-ups
DDRE:
PortE: use pull-ups
DDRC
PortC: set initial values LEDs off
DDRD
PortD: set initial values LEDs off
10
Flowchart:
Start
Port Initializations
A
Read b0 Port E
b0 = 1
Port A
Port B
r17
r18
Separate high
& low nibbles
Copy r18 to r17 (to hold Low) and r18 (to hold high)
AND r17 with $0F (masks off high bits)
LSR r18 4 times (shift high bits to low bits)
1/4/2010
11
Flowchart:
Start
Port Initializations
A
Read b0 Port E
b0 = 1
Separate high
& low nibbles
1/4/2010
12
7-Segment Codes:
a
f
b
g
0 = 0b001 11111
c
e
d
a
f
b
g
1 = 0b00000110
c
e
d
a
f
b
g
2 = 0b01011011
e
d
a
f
b
g
3 = 0b01001111
e
d
1/4/2010
13
7-Segment Codes:
a
f
b
g
0 = 0b001 11111
c
e
d
a
f
b
g
1 = 0b00000110
In-Class Exercise:
e
d
a
f
b
g
2 = 0b01011011
e
d
a
f
b
g
3 = 0b01001111
e
d
1/4/2010
14
7-Segment Codes:
a
a
f
b
g
4 = 0b01100110
c
g
c
b
g
6 = 0b01111101
1/4/2010
A = 0b01110111
7 = 0b00000111
f
g
c
d
E = 0b01111001
e
d
b
g
a
b
D = 0b01011110
c
b
g
9 = 0b01101111
C = 0b00111001
c
5 = 0b01101101
b
g
a
f
f
e
8 = 0b01111111
c
B = 0b01111100
b
g
F = 0b01110001
e
d
15
Flowchart:
Start
Port Initializations
A
Read b0 Port E
b0 = 1
Separate high
& low nibbles
1/4/2010
16
Flowchart:
Start
00
FF
00
FF
00
FF
FF
00
FF
00
Port Initializations
DDRA
PortA: use pull-ups
DDRB
PortB: use pull-ups
DDRE:
PortE: use pull-ups
DDRC
PortC: set initial values LEDs off
DDRD
PortD: set initial values LEDs off
AND Numbers
Copy r18 to r17 (to hold Low) and r18 (to hold high)
AND r17 with $0F (masks off high bits)
LSR r18 4 times (shift high bits to low bits)
Read b0 Port E
N
b0 = 1
Y
Port A
Port B
1/4/2010
r17
r18
17
Two LEDs
What happens if you need to drive two 7-segment
LEDs, but dont have enough ports?
Assume you do have one more output pin available
Port C, bit 0
Assume it has been configured as an output
The following circuit would work ..
7-Segment LEDs
Your program must output the code for LED 1 on Port B and then select
LED 1 by placing a 0 on PC0
Then your program must output the code for LED 2 on Port B and then
select LED 2 by placing a 1 on PC0
You must then continue to alternately light the two LEDs
Atmega128
PB4
PB5
PB0
PB1
PB2
PB3
PB6
PC0
1/4/2010
PB7
120
a
f
g
g
d
d
e
f
e
d
e
f
e
d
LED 1
LED 2
19
The Program:
The program will be assigned as homework
The program and circuit connections will be assigned
as a lab
1/4/2010
20
Summary
In this topic we:
Discussed 7-Segment LEDs
Turned on specific LED segments using code
Common-Anode, Common-Cathode
21