0% found this document useful (0 votes)
157 views

Programming The AVR-Switches and SSD

The document describes switches, seven segment displays (SSDs), and ports used in digital systems. It provides details on how switches work when pressed or not pressed and how to detect switch presses. It explains the hardware configuration of SSDs and how to light different segments. The document reviews port registers and how to configure pins as inputs or outputs. It presents an exercise to write a program displaying the number of a pressed switch on an SSD and provides code snippets for switch scanning and SSD display subroutines.

Uploaded by

Ndumiso Mtshali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views

Programming The AVR-Switches and SSD

The document describes switches, seven segment displays (SSDs), and ports used in digital systems. It provides details on how switches work when pressed or not pressed and how to detect switch presses. It explains the hardware configuration of SSDs and how to light different segments. The document reviews port registers and how to configure pins as inputs or outputs. It presents an exercise to write a program displaying the number of a pressed switch on an SSD and provides code snippets for switch scanning and SSD display subroutines.

Uploaded by

Ndumiso Mtshali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

AVR PERIPHERAL FUNCTIONALITY

SWITCHES AND SSD


DR T WALINGO

UNIVERSITY OF KWAZULU-NATAL 1 DIGITAL SYSTEM DESIGN SERIES


INTRODUCTION

CONTENTS
A review of Switches.
A review of SSD/LEDs.
A review of Ports.
Class exercise involving Switches and SSDs.
Multiplexing of SSD.
Exercise involving multiplexing SSD.

UNIVERSITY OF KWAZULU-NATAL 2 DIGITAL SYSTEM DESIGN SERIES


SWITCH HARDWARE
Switch Not Pressed
SWn VTG

Switch Pressed
SWn 0V
Causes SWn to be pulled low

Detecting switch press


SWn logic should change
from HIGH to LOW

Pull up Resistor: Used to keep pin at a HIGH if it is input.

UNIVERSITY OF KWAZULU-NATAL 3 DIGITAL SYSTEM DESIGN SERIES


SEVEN SEGMENT DISPLAY (SSD) HARDWARE
LEDS arranged in a special way

Common cathode (grounded) lit with a HIGH


Common anode (positive rail) lit with a LOW

UNIVERSITY OF KWAZULU-NATAL 4 DIGITAL SYSTEM DESIGN SERIES


PORTS REVIEW
PINx register PORTx register
Reading the register reads the Anything written to this register
corresponding Pin x affects the pins of PORTx
Commands: IN, SBIS, SBIC, etc Commands: OUT, SBI, CBI, etc

PINxn PORTx
7 7
6 6
5 5
4 4 DDRx register : Register for
PX3 3 3 designating pin input or
2 2 output
1 1 1 output
0 0
0 - input

7 6 5 4 3 2 1 0
DDRx

UNIVERSITY OF KWAZULU-NATAL 5 DIGITAL SYSTEM DESIGN SERIES


CONFIGURATION & USING THE PORTS/PINS
Reading the PORT/Pin ;************************************

Switch configured as input. ;CONFIGURATION SECTION

Switch is read using PINxn Init: ; Initialization Label


register. ldi Temp, 0b00000000 ;Store 0 in register
PINxn is directly connected out DDRB, Temp ;Store this value DDRB
to the pin of the port. ldi Temp, 0b11111111 ;Store 255 in register
The port can be provided out PORTB, TemP ;Enable pull up
resistors ;on the port
with an internal pull-up
resistor by writing a 1 to *******************************************
the port bit at the
addresses PORTx. If a 0 is ;************************************
written the pin is in high ;USING THE PORT
impedance state.
in Temp PinB ;read all pins off PORTB
Note: only works if
configured as input. sbis PinB, 3 ;skips if PinB<3> is set
Writing to the PORT/Pin sbic PinB, 3 ;skips if PinB<3> is clear
Can similarly be explained
;***********************************
UNIVERSITY OF KWAZULU-NATAL 6 DIGITAL SYSTEM DESIGN SERIES
CLASS EXERCISE
For the figure shown, write a program that
displays the number of the switch pressed on the
SSD. Assume common cathode display.

PD.0 PB.0
SW0
a
PB.1
b
PB.2
c
PB.3
d
8515 PB.4
e
SSD1
PB.5
f
PB.6
g

SW7 PD.7

UNIVERSITY OF KWAZULU-NATAL 7 DIGITAL SYSTEM DESIGN SERIES


HARDWARE AND CONFIGURATION
Switches
Connected to PORTD
PORTD Configured as
input No PB6 PB5 PB4 PB3 PB2 PB1 PB0 Hex

SSD g f e d c b a
0 0 1 1 1 1 1 1 3F
Connected to PORTB 1 0 0 0 0 1 1 0 06

PORTB Configured as 2 1 0 1 1 0 1 1 5B
3 1 0 0 1 1 1 1 4F
0utput 4 1 1 0 0 1 1 0 66

A table for the various 5


6
1
1
1
1
0
1
1
1
1
1
0
0
1
1
6D
7D
number connections 7 0 0 0 0 1 1 1 07

will be required. 8 1 1 1 1 1 1 1 7F
9 1 1 0 1 1 1 1 6F

UNIVERSITY OF KWAZULU-NATAL 8 DIGITAL SYSTEM DESIGN SERIES


CODE SNIPET
;*********************************************** ;CONFIGURATION SECTION
;INTRODUCTORY SECTION Init:
;*********************************************** ldi Temp, low(RAMEND) ;STACK INITIALIZATION
; HEADER FILES SECTION out SPL, Temp
ldi Temp, high(RAMEND)
out SPH, temp
.nolist ;Disable List file generation
.include "8515def.inc" ;Includes the 8515 definitions file ldi Temp, 0b00000000
.list ;Reenable list file generation out DDRD, Temp ;configuring PORTD as input
ldi Temp, 0b11111111
;*********************************************** out PORTD, Temp ;Enable Pull Up resistors
;DEFINITIONS SECTION ldi Temp, 0b11111111
.def Temp = R16 ;Gives Register R16 name Temp out DDRB, Temp ;configuring PORTB as output
;********************************************** rjmp Start
; RESET AND INTERRUPT VECTORS SECTION ;*********************************************
.org 0x0000 ;Places the following code from 0x0000 ;MAIN PROGRAMS SECTION
rjmp Init Start:
.org 0x0060 ;Places the following code from 0x0060 rcall SCANSWITCHES
SSDTABLE: ;Table for the SSD code values rcall DISPLAY
.db 0X3F, 0X06, 0X5B, 0X4F, 0X66, 0X6D, 0X7D, 0X07, rjmp Start
0X7F, 0X6F ;*********************************************

UNIVERSITY OF KWAZULU-NATAL 9 DIGITAL SYSTEM DESIGN SERIES


CODE SNIPET Scan and Display Subroutines
;SCAN SUBROUTINE ;DISPLAY SUBROUTINE
SCANSWITCHES: DISPLAY:
SW0: sbis PIND, 0
;Z pointer initialization - points to the table start
ldi Temp, 0
ldi ZL, low(SSDTABLE<<1)
SW1: sbis PIND, 1
ldi ZH, high(SSDTABLE<<1)
ldi Temp, 1

SW2: sbis PIND, 2


add ZL, Temp
ldi Temp, 2 lpm ;fetch desired code, store in R0
mov Temp, R0 ;store in desired location
SW3: sbis PIND, 3

ldi Temp, 3 out PORTB, Temp ;Display the value


SW4: sbis PIND, 4
Ret
ldi Temp, 4

SW5: sbis PIND, 5

ldi Temp, 5

SW6: sbis PIND, 6

ldi Temp, 6 How would you use


SW7: sbis PIND, 7 the IN command
ldi Temp, 7

Ret

UNIVERSITY OF KWAZULU-NATAL 10 DIGITAL SYSTEM DESIGN SERIES


MULTIPLEXING SSD
Multiplexing is required for
interfacing more displays
with limited I/O ports.
The displays are lit one at a
time at a very first pace.
Each display is enabled one
at a time.
Dues to persistence of
vision we think all of them
are on at the same time.
Example displaying 123 on
three SSDs.
Number of displays if a
function of current drawn
and the multiplexing speed.

UNIVERSITY OF KWAZULU-NATAL 11 DIGITAL SYSTEM DESIGN SERIES


EXERCISE
Design a complete AVR system that counts the number of people
entering and leaving a room and displays the result on two seven
segment displays. Assume people enter through one door and
leave through another and each door is equipped with a sensor.
The number of people that can be in a room is less than 100.

Sensor 1 PB.7
E
Entry Sensor PD.2 PB.0 a E a

PB.1 b b

PB.2 c c

PB.3 d d
Sensor 2 e SSD0
PB.4 e SSD1
PD.3 8515
Exit
PB.5 f f

PB.6 g g

Figure B3.1

UNIVERSITY OF KWAZULU-NATAL 12 DIGITAL SYSTEM DESIGN SERIES

You might also like