You are on page 1of 67

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/271587841

Design & Simulation of Moving Message Display using Microcontroller

Technical Report · March 2010


DOI: 10.13140/2.1.3486.2400

CITATIONS READS

0 17,197

5 authors, including:

Utsho A Arefín Tanvir Ahmed


Northern University Bangladesh World University of Bangladesh
53 PUBLICATIONS   25 CITATIONS    52 PUBLICATIONS   277 CITATIONS   

SEE PROFILE SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Effects of sea water on the copressive strength of concrete View project

PRECEIVED BUSINESS RISK, INTERNAL CONTROL AND RISK MANAGEMENT ON ORGANIZATIONAL PERFORMANCE View project

All content following this page was uploaded by Utsho A Arefín on 31 January 2015.

The user has requested enhancement of the downloaded file.


DESIGN & SIMULATION OF MOVING
MESSAGE DISPLAY USING
MICROCONTROLLER

Submitted by

Tanvir Ahmed (Roll # 21, Registration # 204121)


Md. Akhtaruzzaman (Roll # 17, Registration # 204117)
Md. Kamruzzaman (Roll # 22, Registration # 204122)
Md. Mokhlasur Rahman (Roll # 25, Registration # 204125)

Department of Electrical, Electronics & Telecommunication Engineering


Dhaka International University
66 Green Road, Dhaka – 1205, Bangladesh
DESIGN & SIMULATION OF MOVING
MESSAGE DISPLAY USING
MICROCONTROLLER
This project is submitted to the Department of Electrical, Electronics and
Telecommunication Engineering of Dhaka International University, for partial fulfillment
of the requirements for the degree of B.Sc. in Electrical, Electronics and
Telecommunication Engineering.

Submitted by

Tanvir Ahmed (Roll # 21, Registration # 204121)


Md. Akhtaruzzaman (Roll # 17, Registration # 204117)
Md. Kamruzzaman (Roll # 22, Registration # 204122)
Md. Mokhlasur Rahman (Roll # 25, Registration # 204125)

Supervised by

Ashraful Arefin
Lecturer
Department of Electrical, Electronics & Telecommunication Engineering
Dhaka International University

March 2010

Department of Electrical, Electronics & Telecommunication Engineering


Dhaka International University
66 Green Road, Dhaka – 1205, Bangladesh
DECLARATION

We inform you that we have successfully completed our project “Design & Simulation of
Moving Message Display using Microcontroller.” This application note explains the
method to use ATMega8 microcontroller’s of General-Purpose Input/Output (GPIO)
features to control the display of characters on an 8×8 LED matrix. This document is
causes the software interfaces between the 8×8 LED matrixes and ATMega8 and provides
ready-made display patterns for all the printable ASCII characters, in the form of a two-
dimensional array. We are trying to shows that only design and simulation part of the dot
matrix moving message display, In future, if manage this essential hardware accessories
in this university then students are encourage to helpful completed this project with
hardware part.

i
CERTIFICATION

The thesis titled

DESIGN & SIMULATION OF MOVING MESSAGE DISPLAY


USING MICROCONTROLLER

Submitted by Tanvir Ahmed (Roll # 21, Registration # 204121), Md. Akhtaruzzaman


(Roll # 17, Registration # 204117), Md. Kamruzzaman (Roll # 22, Registration #
204122), Md. Mokhlasur Rahman (Roll # 25, Registration # 204125), a student of B.Sc.
in Engineering (Electrical, Electronics and Telecommunication Engineering) has been
accepted as satisfactory in partial fulfillment for the degree of Bachelor of Science in
Electrical, Electronics & Telecommunication Engineering on March 2010.

BOARD OF EXAMINERS

1. Dean,
Faculty of Science and Engineering

2. Chairman

3. Supervisor

4. External

ii
ACKNOWLEDGEMENT

First and foremost, we are indebted to Allah the Almighty, the merciful without whose
patronage and blessing this project would have not been successfully completed. He gave
us zeal, confidence, power of determination and courage and vanquished all the stumbling
hardness that we faced on the way.

We owe a debt of gratitude to project supervisor Mr. Ashraful Arefin, Lecturer, EETE,
Dhaka International University, for his patronizing guidance and encouragement,
insightful advice and endless patience throughout the progress of the work without which
this project would not have been successful.

We express our heartfelt thanks and gratitude to Professor Dr. Sana Ullah, Dean,
Faculty of Science and Engineering, Dhaka International University, whose special
interest and over patronization for establishing our project. We would also like to thank
Mr. Saiful Islam, Chairman, Department of EETE, Dhaka International University, for
the kind help that he extended to us. We would also like to other respected faculty
members of EETE Department, especially thanks to Mr. Sakil Ahmed Khan, Lecturer,
EETE, DIU for helping us from time to time.

Last of all our heartfelt thanks go to our friends and classmates who provided us support,
valuable information and different suggestions that helped for successful completion of
the project.

Tanvir Ahmed
March 2010, Md. Akhtaruzzaman
Dhaka Md. Kamruzzaman
Md. Mokhlasur Rahman

iii
ABSTRACT

The objective of our project is to design and simulate a 3-character dot-matrix moving
message display using microcontroller, where the characters shift from left to write
continuously.

In this project we have used ATMega8 microcontroller. ATMega8 is a family of 8-bit


microcontrollers. It has a maximum rated processor frequency of 16MHz. The ATMega8
lends itself extremely well to prototyping due to its simple requirement of a 4.5V-5.5V
power source. For shifting the characters from left to right, we have used a 74HC595 shift
register. It is a 8-bit serial in, serial or parallel output. It has a shift out frequency of
around 100MHz and storage register of 3-stage output and finally we have used 8×8 dot-
matrix display.

The simulation can be performed by only ISIS simulator. In this case we have used
Proteus Design Suite 7. At first a code was developed in C. then it was implemented in
the simulator. And we got our desired result there.

Our design was ready for practical implementation. But because of the lack of proper
hardware support we were unable to implement the design.

iv
CONTENTS

Chapter 1 Introduction 1-4


1.1 Introduction to Microcontroller 1
1.2 Microcontroller Advantages 1
1.3 Microcontroller Disadvantages 2
1.4 Microcontroller Architecture Example 2
1.5 Introduction to Dot Matrix Display 3
1.6 Programming Language Considerations 3
1.7 Objective of the project work 4

Chapter 2 Microcontroller 5-10


2.1 Behind the scenes an entire computer on a single chip 5
2.2 Interrupts 7
2.3 Volumes 7
2.4 Microcontroller Varieties 9
2.5 Embedded Design 9
2.6 Real-Time Computing 10

Chapter 3 Dot Matrix Display & Shift Register 11-35


3.1 Dot Matrix Display 11
3.1.1 Usual Character Resolutions 12
3.1.2 Dot Matrix Interfacing 12
3.1.3 Various Sizes of Dot Matrix 15
3.1.4 How to Drive a LED Display Matrix 18
3.1.5 LED Display Matrix 8×8 LEDs 19
3.1.6 Multiplexing 19
3.1.7 Dot Matrix LED Display : TC15-11SRWA 20
3.1.8 Helper Chip 21
3.1.9 10 Microcontroller Output Pins 21
3.1.10 Row Current Sink 22
3.1.11 Character Set 22
3.1.12 Dot Matrix LED Display Software 23
3.1.13 Dot Matrix LED Display Code Description 23
3.1.14 Software Implementation 24
3.1.14.1 Data Structure for Display Patterns 24
3.1.14.2 Displaying Characters 24
3.1.14.3 Test Procedures 26

v
3.1.14.4 Test Results 26
3.2 Shift Register 26
3.2.1 Destructive Readout 27
3.2.1.1 Serial in serial out 27
3.2.1.2 Serial in parallel out 28
3.2.1.3 Parallel in serial out 28
3.2.2 Uses 29
3.2.3 Data Movement Systems 30
3.2.4 Shift Register Operation 32
3.2.5 ATMega8's I/O Ports 33
3.2.6 Features of 8 by 8 Dot Matrix LED 35
3.2.7 Specification Overview 35

Chapter 4 ISIS Model, Design and Simulation 36-49


4.1 ISIS Modeling Software 36
4.2 History 36
4.3 Present 37
4.4 Current Release of ISIS 37
4.5 Lists of the projects 38
4.6 Getting Started with the AVR 38
4.7 Serial Peripheral Interface for ATMega8 45
Design of the Circuits & Varieties Statements of Moving 8×8 Dot Matrix
4.8 46
Display
4.9 Simulation Results 47

Chapter 5 Conclusion 50

Appendix A - Programming 51
Appendix B - LED dot matrix display driver 57
References 58

vi
LIST OF FIGURES

1.1 An embedded control system 2


2.1 An entire computer on a single chip 6
2.2 PIC micro chips are the world's smallest microcontrollers 6
2.3 The integrated circuit from an Intel 8742 7
2.4 A PIC 18F8720 microcontroller in an 80-pin TQFP package 8
3.1 Model of dot matrix interfacing 12
3.2 5×7 dot matrix interfacing 13
3.3 Block diagram of dot matrix display 13
3.4 Circuit diagram of dot matrix common cathode display 14
3.5 Driving LED display matrix 18
A dot matrix led display is simply a grid of LEDs arranged
3.6 19
for use by multiplexing
3.7 TC15-11SRWA dot matrix LED display 20
3.8 10 Microcontroller Output Pins 21
3.9 4-Bit SIPO Shift Register 28
3.10 4-Bit PISO Shift Register 28
3.11 Write/Shift Sequence 29
3.12 Data movement diagrams 30
3.13 Four-bit serial in-serial out shift register 31
3.14 Waveform diagram 31
3.15 Four-bit serial bidirectional shift register 33
4.1 Block diagram of serial peripheral interface for ATMega8 45
4.2 Initial Statement of moving 8×8 dot matrix display 46
4.3 1st Statement of simulation result 47
4.4 2nd Statement of simulation result 48
4.5 3rd Statement of simulation result 49
5.1 LED dot matrix display driver 57

vii
Chapter 1

I N T R O D U C T IO N

1.1 Introduction to Microcontroller

A microcontroller (also MCU or µC) is a computer-on-a-chip. A microcontroller (also


microcontroller unit, MCU or µC) is a small computer on a single integrated circuit
consisting of a relatively simple CPU combined with support functions such as a
crystal oscillator, timers, watchdog timer, serial and analog I/O etc. It is a type of
microprocessor emphasizing self-sufficiency and cost-effectiveness, in contrast to a
general-purpose microprocessor (the kind used in a PC). In addition to all arithmetic
and logic elements of a general purpose microprocessor, the microcontroller usually
also integrates additional elements such as read-only and read-write memory and
input/output interfaces. Microcontrollers are used in automatically controlled products
and devices, such as automobile engine control systems, remote controls, office
machines, appliances, power tools and toys. Microcontrollers are complete computer
systems on a chip, typically combining an arithmetic logic unit (ALU), memory,
timer/counters, serial port, input/output ports (I/O) and a clock oscillator.

1.2 Microcontroller Advantages

• Highly integrated and powerful – thousands of transistors on a single chip.


• Can be used to replace a handful of discrete logic chips.
• Relatively easy to learn and implement.

1
• Easier to integrate into a design than discrete logic chips.
• Very low hardware cost possible
• Many types and manufacturers available.
• Architectures and programming languages vary somewhat, but not completely,
so what we learn about one microcontroller (µC) is good knowledge to apply
to another one.
• Many different IC packages available (DIP8, SOIC-16 etc.)

1.3 Microcontroller Disadvantages


• Microcontrollers are IC chips and need to be put on to a custom-designed PC
board. This takes time and money, which may not suit all applications.
Contrast this with an industrial automation PLC, which is a computer-in-a-box
that contains simple screw terminals to connect power, communication and
I/O.
• Programming microcontrollers requires a certain amount of skill and training.
• The programming and debugging software can be quite costly.

1.4 Microcontroller Architecture Example


An example of a simple microcontroller is shown in figure 1.1 here embedded control
in a system:
Embedded Control System
Free scale RS08KA2 Microcontroller Chip

Timers Memory
& Areas
Counters

Interrupt Core Analog


Control Microprocessor Comparator
Subsystem

Input/Output (I/O) Section

Fig 1.1 : An embedded control system


To other electronic devices
(Push buttons, LEDs, speakers etc.)

Fig 1.1 : An embedded control system

2
1.5 Introduction to Dot Matrix Display

LED dot matrix display with light-emitting diodes as pixels, it uses high-brightness
LED chip array assemblies were then made through the epoxy resin and mold
package. With high brightness, low power consumption, pin count, large viewing
angle, long life, moisture resistance, hot and cold, corrosion resistance and so on.

LED dot matrix display with high brightness, light uniformity, reliability, simple
wiring, convenient assembly, etc., can pose a variety of screen sizes, therefore, it is
widely used in intelligent LED1display, 1 intelligent, 1instrumentation, 1 and 1
electro mechanical integration equipment, display screen and achieved good results.
With the micro-electronics technology, computer technology and information
processing technology development, LED dot matrix display is, as a new media tools,
a growing number of areas of play. Such as advertising, finance, transportation, arts,
business, sports, industry, teaching, military, government etc., involving almost all
aspects of their daily lives. As large as tens of square outdoor advertising screen,
small enough to lift the system using a display screen or traffic instructions and many
enterprises and government departments use an electronic blackboard, securities,
banking and other departments also have information on number of mixed-screen,
bringing a wide range of the social and economic benefits.

1.6 Programming Language Considerations

The C language is currently the most popular programming language for embedded
control using microcontrollers. This language offers a good balance of being
relatively easy to learn yet able to perform powerful low-level functions such as bit-
level I/O.

Freescale offers the CodeWarrior C compiler free of charge for use with the RS08 and
a number of other Freescale microcontrollers and microprocessors. Very few other
manufacturers offer a free C compiler, with many costing several hundred dollars or
more per license. Note that Freescale charges a fee for the C compiler required for
higher end microcontrollers. Zilog is another microcontroller manufacturer that offers

3
a free C compiler, so they may be worth considering for cost conscious applications.
One advantage of the Freescale CodeWarrior IDE compared to Zilog’s IDE is that
Freescale includes a very nice hardware configuration GUI.

1.7 Objective of the project work

With the advancement of time people are being dependent on different types of
electronic devices. Electronic display is a very demanding device now a days. The
main objective of this project was to design such a display capable of displaying three
characters at a time. In the same time, it was in the concentration to make the display
more efficient by having the option of changing the characters as wished so that any
message can be displayed, as well as the movement of the characters were included.
The design was made in a software called ‘Proteous Design Suit 7’. In this design,
ATMega8 microcontroller was used to do the task.

4
Chapter 2

M IC R O C O N T R O L L E R

2.1 Behind the scenes an entire computer on a single chip

When we opened the door, the microcontroller sensed the door switch, turned on the
light and disabled the magnetron. The microcontroller continually scans the keyboard.
When we pushed the "Popcorn" button, the microcontroller confirmed that the door
was closed and began to count timing pulses, started the motor for the turntable, set
the power level of the magnetron, and controlled the display. When the timer reached
zero the microcontroller shut down the magnetron, stopped the turntable and signaled
user.

This is a simple example of a microcontroller application. Microcontrollers are


available with extra features such as analog-to-digital converters (ADCs), pulse-width
modulation (PWM), watchdog timers, and controller area network (CAN) and
security functions.

A single chip that contains the processor (the CPU), non-volatile memory for the
program (ROM or flash), volatile memory for input and output (RAM), a clock and an
I/O control unit which has showing in figure 2.1. Also called a "computer on a chip,"
billions of microcontroller units (MCUs) are embedded each year in a myriad of
products from toys to appliances to automobiles. For example, a single vehicle can
use 70 or more microcontrollers.

5
Fig 2.1 : This diagram shows the components of a Motorola 6801. Introduced in 1978, it was one of
the first semiconductor products to claim the "computer on a chip" moniker.

Fig 2.2 : These PIC micro chips are the world's smallest microcontrollers. Used in a myriad of
applications, such chips can sell for as little as 50 cents in quantities of 10,000 (2007 dollars).

6
Fig 2.3 : The integrated circuit from an Intel 8742, an 8-bit microcontroller that includes a CPU
running at 12 MHz, 128 bytes of RAM, 2048 bytes of EPROM, and I/O in the same chip.

2.2 Interrupts

Microcontrollers must provide real time (predictable, though not necessarily fast)
response to events in the embedded system they are controlling. When certain events
occur, an interrupt system can signal the processor to suspend processing the current
instruction sequence and to begin an interrupt service routine (ISR, or "interrupt
handler"). The ISR will perform any processing required based on the source of the
interrupt before returning to the original instruction sequence. Possible interrupt
sources are device dependent and often include events such as an internal timer
overflow, completing an analog to digital conversion, a logic level change on an input
such as from a button being pressed and data received on a communication link.
Where power consumption is important as in battery operated devices, interrupts may
also wake a microcontroller from a low power sleep state where the processor is
halted until required to do something by a peripheral event.

2.3 Volumes

About 55% of all CPUs sold in the world are 8-bit microcontrollers and
microprocessors. According to Semi co, over four billion 8-bit microcontrollers were
sold in 2006. Figure 2.4 are showing that an example of a PIC microcontroller in an
80 pin TQFP package.

7
A typical home in a developed country is likely to have only four general-purpose
microprocessors but around three dozen microcontrollers. A typical mid-range
automobile has as many as 30 or more microcontrollers. They can also be found in
many electrical devices such as washing machines, microwave ovens and telephones.

Fig 2.4 : A PIC 18F8720 microcontroller in an 80-pin TQFP package.

Manufacturers have often produced special versions of their microcontrollers in order


to help the hardware and software development of the target system. Originally these
included EPROM versions that have a "window" on the top of the device through
which program memory can be erased by ultraviolet light, ready for reprogramming
after a programming ("burn") and test cycle. Since 1998 EPROM versions are rare
and have been replaced by EEPROM and flash which are easier to use (can be erased
electronically) and cheaper to manufacture.

Other versions may be available where the ROM is accessed as an external device
rather than as internal memory, however these are becoming increasingly rare due to
the widespread availability of cheap microcontroller programmers.

The use of field-programmable devices on a microcontroller may allow field update


of the firmware or permit late factory revisions to products that have been assembled
but not yet shipped. Programmable memory also reduces the lead time required for
deployment of a new product.

8
Where hundreds of thousands of identical devices are required, using parts
programmed at the time of manufacture can be an economical option. These 'mask
programmed' parts have the program laid down in the same way as the logic of the
chip, at the same time.

2.4 Microcontroller Varieties

Maxim/Dallas Semiconductor offers four categories of microcontrollers: secure


networking, mixed signal and 8051 drop-in compatible which are showing in the
table.

Microcontroller Type Description

High-speed 8051-compatible microcontrollers designed to


Secure Microcontrollers resist all levels of threat, including observation, analysis,
and physical attack.

Network compatible 8051 microcontrollers with CAN,


Networking
Ethernet, RS-232 serial, I2C, 1-Wire® net, and TINI™
Microcontrollers
(Tiny InterNet Interface).

Mixed-Signal High-speed 8051-compatible microcontrollers with ADC


Microcontrollers and PWM outputs.

8051 Drop-in Compatible High-speed 8051 pin and instruction-set compatible


Microcontrollers microcontrollers.

2.5 Embedded Design

A microcontroller can be considered a self-contained system with a processor,


memory and peripherals and can be used with an embedded system. (Only the
software needs be added.) The majority of computer systems in use today are
embedded in other machinery, such as automobiles, telephones, appliances, and
peripherals for computer systems. These are called embedded systems. While some
embedded systems are very sophisticated, many have minimal requirements for

9
memory and program length, with no operating system and low software complexity.
Typical input and output devices include switches, relays, solenoids, LEDs, small or
custom LCD displays, radio frequency devices and sensors for data such as
temperature, humidity, light level etc. Embedded systems usually have no keyboard,
screen, disks, printers or other recognizable I/O devices of a personal computer and
may lack human interaction devices of any kind.

2.6 Real-Time Computing

The term real-time derives from its use in early simulation. While current usage
implies that a computation that is 'fast enough' is real-time, originally it referred to a
simulation that proceeded at a rate that matched that of the real process it was
simulating. Analog computers, especially, were often capable of simulating much
faster than real-time, a situation that could be just as dangerous as a slow simulation if
it were not also recognized and accounted for.

In computer science, real-time computing (RTC) or "reactive computing", is the study


of hardware and software systems that are subject to a "real-time constraint"—i.e.,
operational deadlines from event to system response. By contrast, a non-real-time
system is one for which there is no deadline, even if fast response or high performance
is desired or preferred. The needs of real-time software are often addressed in the
context of real-time operating systems and synchronous programming languages,
which provide frameworks on which to build real-time application software.

A real time system may be one where its application can be considered (within
context) to be mission critical. The anti-lock brakes on a car are a simple example of a
real-time computing system — the real-time constraint in this system is the short time
in which the brakes must be released to prevent the wheel from locking. Real-time
computations can be said to have failed if they are not completed before their
deadline, where their deadline is relative to an event. A real-time deadline must be
met, regardless of system load.

10
Chapter 3

DOT-MATRIX DISPLAY
& S H IF T R E G IS T E R

3.1 Dot Matrix Display

A dot matrix display is a display device used to display information on machines,


clocks, railway departure indicators and many and other devices requiring a simple
display device of limited resolution. The display consists of a matrix of lights or
mechanical indicators arranged in a rectangular configuration (other shapes are also
possible, although not common) such that by switching on or off selected lights, text
or graphics can be displayed. A dot matrix controller converts instructions from a
processor into signals which turns on or off lights in the matrix so that the required
display is produced.

Common sizes of dot matrix displays:


128×16 (Two lined)
128×32 (Four lined)
192×64 (Eight lined)

11
3.1.1 Usual Character Resolutions

A common size for a character is 5×7 pixels, either separated with blank lines with no
dots (in most text-only displays), or with lines of blank pixels (making the real size
6×8). This is seen on most graphic calculators, such as CASIO calculators or TI-82
and superior.

A smaller size is 3×5 (or 4×6 when separated with blank pixels). This is seen on the
TI-80 calculator as a "pure", fixed-size 3×5 font or on most 7×5 calculators as a
proportional (1×5 to 5×5) font. The disadvantage of the 7×5 matrix and smaller is that
lower case characters with descanters are not practical. A matrix of 11×9 is often used
to give far superior resolution.

Dot matrix displays of sufficient resolution can be programmed to emulate the


customary seven-segment numeral patterns.

3.1.2 Dot Matrix Interfacing

The heart of scrolling display is dot matrix led display unit. One or more dot matrix
display is multiplexed to form a display panel. A set of hex values define a character
which are send to the dot matrix display. Figure 3.1 are showing that normal dot
matrix interfacing model. To minimize the pin usage led matrix is formed having
certain number of rows and columns. The concept is to refresh each display unit with
a frequency at which human eye cannot perceive changes.

Fig 3.1 : Model of dot matrix interfacing

12
Dot matrix displays are available with common cathodes as the columns and common
anodes as the columns. The leds may be single color, bi-color or RGB.

Fig 3.2 : 5×7 dot matrix interfacing

Figure 3.2 we are interfacing 5×7 dot matrix displays with common cathode columns
and having bright red leds. The cathodes are shorted along the column and anodes
shorted along the row. 5×7 dot matrix display needs 7 Row drivers and 5 Column
drivers.

3.1.2.1 Block Diagram of Dot Matrix Display

Fig 3.3 : Block diagram of dot matrix display

13
Due to the limitation of source and sink current of AT89C51 we have used SK100
pnp transistors along with 200-ohm current limiting resistors as row drivers. We have
used ULN2003A to increase the sinking capacity of the AT89C51 as column drivers
which has showing in figure 3.3.

3.1.2.2 Circuit Diagram of Dot Matrix Common Cathode Display

Fig 3.4 : Circuit diagram of dot matrix common cathode display

The transistors are turned on by the TTL voltages applied by the Port 2 of AT89C51
to their bases through 1-kilo ohm resistors. To make any led segment glow just make
the respective row and column bits on. We send the hex value of character to be
displayed in first column to Port2 and send columns selection byte to Port1. Then we
send another hex value to row and select the respective column which is shown in
figure 3.4, this process is done very fast and it seems that the whole character is
displayed at the same time.

14
3.1.3 Various Sizes of Dot Matrix

Dot Matrix LED - 5×7 Amber Cathode Row


5×7 common cathode (row) amber dot matrix
display. Using super bright InGaAlP amber led
(590nm) chip, ideal for graphics panels requiring
long distance viewing. Black color background.
Cathode Row, Anode Column configuration. Size:
2.09". Luminous Intensity: 40,000 ucd per dot @
10mA.

Dot Matrix LED - 5×7 Red Cathode Row


Common cathode (row) red led dot matrix display.
Using super bright InGaAlP red (630nm) led chip,
ideal for graphics panels requiring long distance
viewing. Black color background. Cathode Row,
Anode Column configuration. Size: 2.09". Luminous
Intensity: 45,000 ucd per dot.

Dot Matrix LED - 5×7 Blue LED Cathode Row


Sun light viewable blue led display, common
cathode (row) 5×7 led dot matrix display. Low
power consumption with high ambient intensities;
perfect for both indoor and outdoor displays. Black
color background. Size: 2.09". Dice Material: InGaN
Blue (465nm). Lumious Intensity per Dot: 50 mcd-
100 mcd. Common cathode row orientation.

15
White Dot Matrix - 5×7 Cathode Row Display
White dot matrix modules ideal for graphics panels,
suitable for low power or high ambient intensities,
long distance view ability. Luminous Intensity: 45
mcd per dot. Black color background. Size: 2.09".
Dice Material: InGan White (5500K). Cathode Row
& Anode Column configuration.

White Dot Matrix - 5×8 Cathode Row Display


White dot matrix modules ideal for graphics panels,
suitable for low power or high ambient intensities,
long distance viewability. Luminous Intensity: 45
mcd per dot. Black color background. Size: 1.2".
Dice Material: InGan white (5500K). Cathode Row
& Anode Column configuration.

Dot Matrix LED - 5×7 Bicolor Red & Green


Bicolor Red & Green dot matrix modules ideal for
graphics panels, suitable for low power or high
ambient intensities, long distance view ability. Black
color background. Size: 2.09". Dice Material:
AlGaAs Red (660nm). Luminous Intensity: 26,000
ucd. Dice Material: GaP Green (570nm). Luminous
Intensity: 22,000 ucd. Common cathode orientation.
Custom configuration available.

16
5×7 Dot Matrix LED - Super Amber Anode Row
Super bright amber dot matrix modules ideal for
graphics panels, suitable for long distance viewing.
Uses latest InGaAlP Amber (590nm) chip
technology with luminous intensity of 25,000 ucd
per dot. Black color background. Size: 2.09".
Common anode row orientation.

Dot Matrix LED - 5×7 Blue LED Anode Row


Sun light viewable blue dot matrix display. Low
power consumption with high ambient intensities;
perfect for both indoor and outdoor displays. Black
color background. Size: 2.09". Dice Material: InGaN
Blue (465nm). Lumious Intensity per Dot: 50 mcd-
100 mcd. Common anode orientation. Custom
configuration available.

Dot Matrix LED - 5×7 Red LED Anode Row


Super bright red dot matrix modules ideal for
graphics panels, suitable for low power or high
ambient intensities, long distance view ability.
Luminous Intensity: 45,000 ucd per dot. Size: 2.09".
Black color background. Anode row, cathode
column PIN configuration. Dice Material: InGaAlP
Red (630nm).

17
3.1.4 How to Drive a LED Display Matrix

Driving a 64 LED display matrix is quite simple and just requires ONE TRICK.

Fig 3.5 : Driving LED display matrix

Figure 3.5 we can find out how to drive a led matrix with 64 LEDs (8 rows by 8
columns - 8×8 display) or less e.g. 35 LEDs (7 rows by 5 columns - 5×7 dot matrix).
It uses persistence of vision to let we drive the 64 led matrixes with only 10
microcontroller outputs. Normally we would need 64 outputs for 64 LEDs but by
using multiplexing and a helper chip we can get away with 10. LED Display
multiplexing simply means turning on one led for a short period of time and doing
this repeatedly for each LED which process is done by the figure 3.6

Note: The unit used in this project is simply an array of 64 LEDs.

The LEDs are no different to any other LEDs but it saves a huge amount of soldering
as all the wiring.

18
3.1.5 LED Display Matrix 8x8 LEDs

Fig 3.6 : A dot matrix led display is simply a grid of LEDs arranged for use by multiplexing

3.1.6 Multiplexing

If we tried to drive 64 individual LEDs we would need 64 individual output pins


(each led connected to an output pin on one side and ground on the other).

Obviously that is a tall order so the way round it is to use persistence of vision which
is a way of describing how our eye works.

Our eye reacts slowly to changes in light intensity so that if a light is turned on and off
quickly enough then it does not notice that the light is off. Basically our eye
remembers a light pulse for a short time.

The approximate time is 20ms so if the light is turned on at a frequency >50Hz


(1/20ms) then our eye will not notice any flicker at all.

19
Multiplexing uses this fact to reduce the number of pins needed to drive an LED
display. We can do this by splitting the 64 led displays into 8 rows and 8 columns
which lets we drive it using 8 row outputs and 8 column outputs. In fact the 8×8 led
matrix block used here has all the leds arranged in this way already.

3.1.7 Dot Matrix LED Display: TC15-11SRWA

Fig 3.7 : TC15-11SRWA dot matrix LED display

Note: The orientation of the led block must be pin 1 at the top left to view characters
the right way up.

Each row is driven in turn and as long as all of the rows are driven within a time
period of 20ms it will appear as though the LEDs are on continuously. To turn a
specific led 'ON', data is output to the column drivers when a row is driven that events
are showing in figure 3.7.

20
3.1.8 Helper Chip

To save more pins it is common to use a helper chip and in this project it is a Johnson
counter (a 4017). This generates a walking one every time that it's clocked. Since we
only want one row on at a time it is the ideal chip for this application.

Note: In this project when the 4017 has been reset it outputs logic high at Q0 - which
is not connected - so during reset the 4017 does nothing. This allows us to use the
column driver port for something else if we want to when we are not driving the
LEDs.

To drive the 4017 all we need is two pins one for reset and one for clock.

3.1.9 10 Microcontroller Output Pins

We don't have to use a 4017. If we have enough pins we could drive the led display
directly e.g. using a 16F877A. It all depends on our circuit and what resources we
need to use. Figure 3.8 are showing in clearly.

Fig 3.8 : 10 Microcontroller Output Pins

21
3.1.10 Row Current Sink

To get more current through the LEDs we need to use a transistor at each row driver
as the maximum current we can sink or source is low.

The row driver sinks all the current from each active row LED. To let the current flow
we need to use a transistor at each row as the maximum current we can sink or source
is very low for an HC4017 (1ma).

We used a ULN2803 (an array of 8 grounded NPN transistors) - which is massive


over design in terms of its collector current capability (500mA) but provides a
convenient (and cheap) package which is useful for prototyping.

Note: We can use individual NPN transistors if we want to - normal standard


transistors are OK as the maximum current is about 60mA through a column.

3.1.11 Character Set

The most difficult thing about using the dot matrix LED display is defining the
characters. Basically for ASCII characters we need an array of 128 blocks each
having 8 column data numbers.

The usual way is to get out a piece of graph paper and define our characters by
drawing blocks where a pixel is on. Then we translate each line into hex (binary to
hex is very easy) and then transfer this information to our program source code.

We have defined characters 0-9 which are cycled continuously.

22
3.1.12 Dot Matrix LED Display Software

Project files for the dot matrix led display


• Compiler project files
16F88-dot-matrix-8×8.ppc
• C Source files.
16F88-dot-matrix-8×8.c
• Header files.
types.h
bit.h
charset8×8.h
• Output files
16F88-dot-matrix-8×8.hex

3.1.13 Dot Matrix LED Display Code Description

16F88-dot-matrix-8×8.c

This contains all the code except:


• 8x8 character definitions in charset8×8.h
• Bit manipulation routines found in bit.h
• Type definitions in types.h

The code is simple and easy to follow - all the action happens in main().

It enters a continuous a continuous loop blinking a led on port A and driving the
columns of the 8×8 led display and driving the 4017 (for rows). At each blink the next
character is selected from the character set.

The code repeatedly executes for loop and it must go faster than 20ms for 8 columns -
so the code has to go faster than 20ms/8 = 2.5ms - which it does. So there is no visible
flicker.

23
At each row (selected at the each iteration of for loop) the next column data is output
so that the entire character is displayed.

3.1.14 Software Implementation

This section describes how the arrangement outlined in the previous section is used to
display strings.

3.1.14.1 Data Structure for Display Patterns

Each unit matrix that displays a single character is composed of seven rows and five
columns. The data that displays a single row is held in one byte of data. Thus, each
character is represented by seven bytes of data—one byte each to hold the data for a
particular row. The total number of characters supported is 95, ranging from ASCII
code 0×20 to 0×7E. The memory space required to store character data is, in effect,
95 characters × 7 bytes, or 665 bytes. Information is arranged in a two-dimensional,
95×7 array that comprises the data structure for the display patterns. The three most
significant bits (msb) in each of these bytes do not contribute to the display and are
arbitrarily set to zero while forming the data byte.

3.1.14.2 Displaying Characters

The software implementation for the 5×7 LED display is divided into foreground and
background tasks. The main routine works as a foreground task and is responsible for
the initialization of the GPIO ports. It copies the string to be displayed into a user-
specified memory location and appends the string with:

• Leading space
• Trailing space
• NULL character

These spaces visually mark the start and end of a string, which allows a string to be
easily read by the human eye when text is scrolling. The main routine also tracks

24
character display data and keeps that data ready for display at the latch inputs The
array data starts from ASCII character 0×20 (the space key), therefore 0×20 is
subtracted from the character ASCII code. The resulting number provides an array
index between 0–94 that point to the first row for the character. According to its row
position on the unit matrix, the corresponding row data for the character is fetched
and output to the port. Although this data is available, it is not displayed immediately;
rather, it waits until the data is attached by the background task.

When a string is longer than the number of LED units available—it is necessary to
scroll the characters to display the entire string. A two-step approach is necessary to
scroll a string of characters, as the following sequence shows:

1. A section of the string containing the same number of characters as the number of
units is windowed or selected for display.

2. This window is moved by one character to exclude the extreme left character and
include the next character to be displayed at the extreme right position. As a result,
the display scrolls from left to right, effectively creating a perception that the string is
moving. Blinking a message can be performed by alternately switching the display on
and off at suitable intervals. The software implementation supports both the scrolling
and blinking mechanisms, as well as combination of the two.

The main routine (with other user application code) is interrupted at 1ms intervals by
an interrupt service routine (ISR) that acts as a background task. It obtains the present
unit and row position from the main routine. From the update flag set by the main
routine, the ISR also detects when data is ready. The ISR is responsible for latching
the data kept ready by the main routine on appropriate latches. It also resets the update
flag to force the main routine to keep fresh data ready for latching. The sequence of
tasks to be performed by the main routine are provided below:

1. Initialize the GPIO and Timer0.


2. Place the string to be displayed into the active string array.
3. Check the update flag to decide if a data update is required. If not, return to step 9.

25
4. Check for the most recent unit and row position displayed.
5. If the displayed unit is the extreme right unit, point to the next row in the extreme
left unit, or else point to the same row in the next unit.
6. Get the data byte for the next unit/row position.
7. Output data on Port E (column latch input).
8. Enable the selected row through Port G (row latch input).
9. Return to step 3.

3.1.14.3 Test Procedures

The procedure to test the LED matrix software:

1. On reset, the string is rolled on to the display matrices.


2. Different scrolling and blinking options are set and fresh code is downloaded to
flash memory to check each possible mode of operation.
3. Scroll rate and blink rate were varied by adjusting the definitions of the
SCROLL_DELAY, BLINK_PERIOD, and BLINK_ON_TIME variables. The effects
are observed on the display.

3.1.14.4 Test Results

The display functioned as intended based on the settings downloaded. These settings
can be changed through user software during run time. The settings as provided in the
code produce a blink rate of approximately one blink per second and a scroll rate of
approximately three characters per second.

3.2 Shift Register

In digital circuits, a shift register is a cascade of flip flops, sharing the same clock,
which has the output of any one but the last flip-flop connected to the "data" input of
the next one in the chain, resulting in a circuit that shifts by one position the one-
dimensional "bit array" stored in it, shifting in the data present at its input and shifting
out the last bit in the array, when enabled to do so by a transition of the clock input.

26
More generally, a shift register may be multidimensional; such that its "data in" input
and stage outputs are themselves bit arrays, this is implemented simply by running
several shift registers of the same bit-length in parallel.

Shift registers can have both parallel and serial inputs and outputs. These are often
configured as serial-in, parallel-out (SIPO) or as parallel-in, serial-out (PISO).
There are also types that have both serial and parallel input and types with serial and
parallel output. There are also bi-directional shift registers which allow shifting in
both directions: L→R or R→L. The serial input and last output of a shift register can
also be connected together to create a circular shift register.

3.2.1 Destructive Readout

3.2.1.1 Serial-in, serial-out

These are the simplest kind of shift registers. The data string is presented at 'Data In',
and is shifted right one stage each time 'Data Advance' is brought high. At each
advance, the bit on the far left (i.e. 'Data In') is shifted into the first flip-flop's output.
The bit on the far right (i.e. 'Data Out') is shifted out and lost.

The data are stored after each flip-flop on the 'Q' output, so there 0 0 0 0
are four storage 'slots' available in this arrangement; hence it is a
1 0 0 0
4-Bit Register. To give an idea of the shifting pattern, imagine
0 1 0 0
that the register holds 0000 (so all storage slots are empty). As
'Data In' presents 1,0,1,1,0,0,0,0 (in that order, with a pulse at 1 0 1 0
'Data Advance' each time. This is called clocking or stroking) to 1 1 0 1
the register, this is the result. The left hand column corresponds
0 1 1 0
to the left-most flip-flop's output pin and so on.
0 0 1 1
So the serial output of the entire register is 10110000 (). As we
0 0 0 1
can see if we were to continue to input data, we would get
0 0 0 0
exactly what was put in, but offset by four 'Data Advance'
cycles. This arrangement is the hardware equivalent of a queue. Also, at any time, the
whole register can be set to zero by bringing the reset (R) pins high.

27
This arrangement performs destructive readout - each datum is lost once it been
shifted out of the right-most bit which is showing in upper chart.

3.2.1.2 Serial-in, parallel-out

This configuration allows conversion from serial to parallel format. Data is input
serially that process is showing in figure 3.9. Once the data has been input, it may be
either read off at each output simultaneously, or it can be shifted out and replaced.

Fig 3.9 : 4-Bit SIPO Shift Register

3.2.1.3 Parallel-in, serial-out

This configuration has the data input on lines D1 through D4 in parallel format. To
write the data to the register, the Write/Shift control line must be held LOW. To shift
the data, the W/S control line is brought HIGH and the registers are clocked. The
arrangement now acts as a PISO shift register, with D1 as the Data Input. However, as
long as the number of clock cycles is not more than the length of the data-string, the
Data Output, Q, will be the parallel data read off in order which events are showing in
figure 3.10

Fig 3.10 : 4-Bit PISO Shift Register

28
The animation below shows in the figure 3.11 write/shift sequence, including the
internal state of the shift register.

Fig 3.11 : Write/Shift sequence

3.2.2 Uses

One of the most common uses of a shift register is to convert between serial and
parallel interfaces. This is useful as many circuits work on groups of bits in parallel,
but serial interfaces are simpler to construct. Shift registers can be used as simple
delay circuits. Several bi-directional shift registers could also be connected in parallel
for a hardware implementation of a stack. Shift registers can be used also as pulse
extenders. Compared to monostable and multivibrators the timing has no dependency
on component values, however requires external clock and the timing accuracy is
limited by a granularity of this clock. Example - Ronja Twister, where five 74164
shift registers create the core of the timing logic this way (schematic).

In early computers, shift registers were used to handle data processing: two numbers
to be added were stored in two shift registers and clocked out into an arithmetic and
logic unit (ALU) with the result being fed back to the input of one of the shift
registers (the Accumulator) which was one bit longer since binary addition can only
result in an answer that is the same size or one bit longer. Many computer languages
include instructions to 'shift right' and 'shift left' the data in a register, effectively
dividing by two or multiplying by two for each place shifted. Very large serial-in
serial-out shift registers (thousands of bits in size) were used in a similar manner to
the earlier delay line memory in some devices built in the early 1970s. Register that is

29
capable of shifting data one bit at a time is called a shift register. The logical
configuration of a serial shift register consists of a chain of flip-flops connected in
cascade, with the output of one flip-flop being connected to the input of its neighbor.
The operation of the shift register is synchronous; thus each flip-flop is connected to a
common clock. Using D flip-flops forms the simplest type of shift-registers.

3.2.3 Data Movement Systems

The basic data movements possible within a four-bit shift register is shown in Figure
3.12

Fig 3.12 : Data movement diagrams

Next figure that is 3.13 shows the circuit diagram for a four-bit serial in-serial out
shift register implemented using D flip-flops. Assuming that the register is initially
clear, shown the waveform diagram 3.14 when ‘1000’ is shifted through the register.

30
Fig 3.13 : Four-bit serial in-serial out shift register

Fig 3.14 : Waveform Diagram

31
Let us now take a closer look at the effect of shifting the binary digit ‘1’ through the
register over time. Again, we assume that the register is initially reset and the bit
enters the left-most stage.

At time t=0

0 0 0 0 (0) 10

At time t=1

1 0 0 0 (8) 10

At time t=2

0 1 0 0 (4) 10

At time t=3

0 0 1 0 (2) 10

At time t=4

0 0 0 1 (1) 10

At each time step from t=1 onwards, the right shift results in a state change which
indicates a division by two operation. Similarly, if we operate in reverse chronological
order (i.e. from t=4 to t=1), the left shift will result in a multiplication be two.

3.2.4 Shift Register Operation

A HIGH on the control input allows data bits inside the register to be shifted to
the right and a LOW allows for the data to be shifted to the left. Notice that when the

input is HIGH, G1 through G4 are enabled and the state Q output from each flip-

32
flop is passed on to the D input of the following flip-flip. Consequently, on each clock

pulse the data is shifted one place to the right. Similarly, when that the is LOW,
G5 through G8 are enabled, and the state Q output from each flip-flop is passed on to
the D input of the preceding flip-flip. Now, on each clock pulse the data is shifted one
place to the left.

A bidirectional shift register, which is capable of shifting bits to the left (L) or right
(R), will then be capable of performing modulo-2 division and multiplication
operations. Figure 3.15 illustrates the logic circuit for the four-bit bidirectional shift
register.

Fig 3.15 : Four-bit serial bidirectional shift register

3.2.5 ATMega8's I/O Ports

As we have read the C or assembly code, we must remember that it just writes some
values to ATMega8's PORTC.

ATMega8 has three multi-bit multipurpose I/O ports: PORTB with 8 bits, PORTC
with 7 bits and PORTD with 8 bits. Each of these bits is mapped to one pin at

33
microcontroller, but most pins have multiple functions. For example, 4 pins from
PORTB are also used for the Serial Peripheral Interface (3 of them are used to
program the microcontroller using serial programming); 6 bits from PORTC are also
used for Analog-to-Digital Converter (while 2 of them can also be used for the Two-
wire Serial Interface).

While we can choose to use any one of the available functions of each pin, there is
one special pin that we think should not be messed with the RESET pin. While we
can use it as PC6 (bit 6 of PORTC), doing so will require disabling the reset line,
which means that we won't be able to use serial programming anymore, which means
that ISP (In-System Programming) won't be possible, which means that our simple
and cheap AVR ISP programmer we built on part 2 won't work, which means that
parallel programming must be used instead, which requires much more wires and
components, which adds a lot of complexity... Well, all of this just because we wanted
to have 1 more I/O bit.

We have decided to use the 4 least significant bits from PORTC to connect the LEDs,
but any set of free pins could have been used instead (of course, with appropriate
changes to the firmware source code).

The circuit itself is dead simple. We have just connected one LED and one resistor to
each output pin used. In addition to that, we have connected our ISP connector to the
RESET, SCK, MISO and MOSI ports. Finally, just connect all GND together and
connect the VCC to the microcontroller. There are two things that should be noted,
though:

First one is that our ISP programmer is un-powered (i.e. it doesn't draw current from
the PC's parallel port, but only transmit signals). This means we need to get 5V VCC
from somewhere else. In our case, we have used an USB port to do so.

The second thing is that we are using 4 resistors, one for each LED. It is also possible
to use only one resistor for all LEDs, but this means that when multiple LEDs are on,
they will appear dimmer than when separately lit.

34
3.2.6 Features of 8 by 8 Dot Matrix LED

• serial bus interface

• single 5 volt supply

• 16 level digital dimming

• individual dot control

• interlocks mechanically

The B32CDM is an 8 by 8 (row by column) dot matrixes red LED display combined
with a multiplexed drive, integrated circuit with a cascadable serial interface. The
serial interface is compatible with SPI, QSPI and MICROWIRE. User selectable
jumpers allow the data-in/data-out functions to be swapped from left to right. The
displays are designed so that they can be mounted in a horizontal chain and can also
be expanded in a vertical plane allowing versatile displays to be built. The 8 by 8
matrix gives enhanced characters over a 7 by 5 matrix and the excellent optical
performance allows high visibility and viewing angle. The command set includes 16
level digital dimming, test modes, null command (for cascading) and a shutdown
mode that reduces current consumption to 150uA. A single +5 volt supply is required.
Applications include message displays, large area display assemblies and graphics
panels. LED sizes include (active display area) 32mm by 32mm, 38mm by 38mm and
64mm by 64mm. alphanumeric character generation using the BIFQ2.

3.2.7 Specification Overview


Supply voltage 5V
Supply current (64 dots on) 330mA
Shutdown current 150uA
Segment current 15mA
Display scan rate min 500Hz max 1300Hz
Dot Luminous Intensity HE red 4.0mcd
Input clock frequency 10MHz max
Operating temperature -10°C to +70°C
B32CDM8-R 32mm 8 by 8 Red matrix

35
Chapter 4

I S I S M O D E L , D E S IG N
& SIMULATION

4.1 ISIS Modeling Software

ISIS is a software package which is used for river modeling. Developed by Halcrow
Group Limited, it is used throughout the world as an analysis tool for flood risk
mapping, flood forecasting and other aspects of flood risk management analysis. It is
used by the Environment Agency, Office of Public Works, Scottish Environment
Protection Agency, Mekong River Commission and the Ministry of Water Resources
and Irrigation in Egypt as well as many of the UK’s major river engineering
consultants including Jacobs, Hyder Consulting, Atkins, Ove Arup & Partners,
Haskoning, Black & Veatch, Capita Symonds and JBA Consulting.

4.2 History

ISIS was first developed in the 1970s as Halcrow’s ONDA and HR Wallingford’s
FLUCOMP, LORIS and RIBAMAN software. There are a number of different types
of software built into the ISIS code, but ONDA played a key role in its creation,
which is why many of its functionalities remain today. ONDA modeled open channel
flows and was capable of simulating both branched and looped systems. It was a
modular program which could represent a variety of control structures, including
weirs, sluices and culverts and floodplains.

36
4.3 Present

Halcrow and Wallingford Software, the sister company of HR Wallingford worked in


partnership for over 10 years in the development, sale and support of ISIS. In January
2008 this partnership came to an end and Halcrow continued to develop ISIS alone
and introduced a new licensing structure and price. The new licensing structure
includes a free version of the software. It has the same functionality as ISIS
Professional, but is limited to 200 nodes and 10mb of ISIS Mapper input files. It can
be used for smaller river modeling projects such as flood risk assessments, flood
mapping and design projects.

The ISIS suite has been developed by the further integration of WBM’s TUFLOW
software and the introduction of ISIS Mapper, a GIS-based model building and
visualization tool for viewing 3D surface data. Available add-ons include Sediment
Transport and Water Quality.

ISIS 2D is the latest addition to the ISIS by Halcrow suite of products. ISIS 2D is a
fully hydrodynamic computational engine and is designed to work either standalone
or within the ISIS suite. It has been developed to complement the capabilities of
WBM's 2D modeling software; TUFLOW.

4.4 Current Release of ISIS

• v3.0 (released February 2008) - the first ISIS release by Halcrow since the end
of the business partnership with Wallingford Software. The release saw many
major enhancements, most notably the inclusion of ISIS Mapper as a model
building, flood mapping and visualization tool, the release of a fully
functioning Free version of the software (limited to 200 nodes) and the
introduction of three new hydraulic units (Flat-V weir, Total Energy Junction,
Blockage unit).
• v3.1 (released December 2008) - delivers faster run times and other
improvements and new features - including grid manipulation, conveyance
plotting, OpenMI compliance and better visualization of diagnostic and
structure information.

37
• v3.2 (released June 2009) - ISIS Free now has all of the same features of ISIS
Professional (1D) and ISIS 2D but is limited to 250 1D nodes, 2,500 2D cells
and a 10mb restriction on ISIS Mapper input files.
• v3.3 (released November 2009) - New usability and productivity tools,
including model health checker and results harvester. Provides enhanced
usability for ISIS Mapper, including improved zoom/pan facilities and speed
improvements for ISIS 2D.

4.5 Lists of the Projects

74HC595 Shift Register


ATMega8 Microcontroller
8×8 Dot Matrix Display

4.6 Getting Started with the AVR

4.6.1 About AVR

The AVR is a family of 8-bit microcontrollers. In this course, we will be using the
Atmel ATMega8 AVR processor. This processor features 8KB of FLASH, 1KB
SRAM and a variety of built-in peripherals. It supports a proprietary 8-bit AVR ISA
for which there is GCC support. The ATMega8 has a maximum rated processor
frequency of 16MHz and is little endian. The ATMega8 lends itself extremely well to
prototyping due to its DIP form factor (in the version we use) and its simple
requirement of a 4.5V-5.5V power source. The AVR allows us to rapidly develop
code for a very low-power, low-cost microprocessor with the advantages of GCC
compiler support. The ATMega8 has a decent amount of computational power and
has excellent flexibility in the use of its IO pins. The AVR family of processors has a
very large following on the Internet allowing for rapid advice on development issues.

4.6.2 Programming the AVR

The AVR processor family and in particular the ATMega8 processor in its DIP
format, are very easy to program through its In System Programming (ISP) interface.

38
All programming is done via the ATAVRISP which connects easily to a COM port on
the PC and to a 10 pin header on AVR. As a result, programming on the ATMega8
processor is fast and easy. Before any programming can take place, we must power
the AVR and connect the UART lines on the ATMega8 to the computer. This is not
as simple as it seems, however. RS232 signals go between +12V and –12V and are
inverted (-12V is a logical 1). Applying this kind of voltage to the AVR is very
dangerous. Dealing with this problem requires the use of a very common chip: the
MAX232. The MAX232 uses capacitor pumps to perform the necessary level shifting
and provide two receive and two transmit channels per chip.

The AVR is programmed via an interface between a computer’s serial ports that goes
to pins on the AVR. In this section, we will set up this interface. The ATAVRISP’s
(the programming interface) serial connector must be connected to the PC and we
must setup an interface between the 10 pin connector on the ATAVRISP and the
ATMega8.

To ease this setup, we will establish a convention in which the bottom row of the 10
pin connector is defined as the row closest to the long part of the ribbon cable.

Use the following table to make connections between the AVR processor and the 10
pin header.

AVR Processor Pin Programmer 10 Pin Header


17 (MOSI) 1
GND (any source will do) 2
1 (RESET) 3
19 (SCK) 4
18 (MISO) 5

One thing to note is that we must attach a 10KΩ resistor (brown – black – orange) to a
5V power source and pin 1 on the AVR processor. This pull-up resistor is necessary
on RESET since the programmer is not strong enough to pull down anything beefier
and the AVR does not have a pull up resistor on this pin internally.

39
Also, pin 10 on the 10 pin connector must be connected to a 5V power source. Be
sure to do this step as it is VERY IMPORTANT.

To begin programming, the processor must have RESET and SCK pins set to 0. Then,
specific Programming Enable serial instructions must be sent to the MOSI pin.
However, this does not have to be done by the user as the ATAVRISP takes care of
all of this functionality.

Now that we have setup the programming interface, it is relatively easy to compile
and download a program.

Find the TerminalDemo program located at C:\545\demo\code\avr\ and type


make. This will create a few files (whose creation and meaning will be discussed
later in this document). Of most interest to us is the TerminalDemo.hex file. This
file contains all the information necessary to run the program. To download this
program to the AVR, type in

STK500.EXE -dATmega8 -e -ifTerminalDemo.hex -pf -vf

Since we are just testing to ensure that the programmer is properly setup, no actual
output will be seen. However, if we receive an error message, ensure that the green
light on the ATAVRISP is on and stable. If this is ok, check the orientation of our
cable.

4.6.3 Interfacing with the AVR

Basic GPIO use


Most of IO pins on the ATMega8 can be configured to act as GPIOs or to serve an
alternate function. Most pins have two alternate functions and the available functions
vary by pin. The value of the GPIOs is stored in memory as a few 8-bit integers with
each bit corresponding to the appropriate pin. Information about specific pins can be
extracted through bit-hacking (e.g. to find the value of Port C pin 4 we might write
something like ((PORTC>>4) &1). A large variety of macro’s and access to pin

40
configuration information is located in iom8.h. It is highly recommended that we look
through and understand the contents of this file.

UART Setup
This section describes how to set up the MAX232 chip and connect it to the AVR to
enable UART transmissions between the AVR and the PC.

Let’s setup the power lines to the chip first. After placing it onto the breadboard, place
a 5V wire to pin 16 and place GND to pin 15 of the MAX232.

Next, obtain 4 1µF capacitors. Connect the negative end of one of the capacitor (the
one with the stripe) to pin 3 and the positive end to pin 1. With another capacitor,
connect the negative end to pin 5 and positive end to pin 4. Connect the 3rd capacitors
negative end to a 5V column and the positive end to pin 2. Connect the last capacitors
negative end to pin 6 and the positive end to a ground column. These connections are
summarized in the table below.

Capacitor Negative End Positive End


1µF Pin 3 – MAX232 Pin 1 – MAX232
1µF Pin 5 – MAX232 Pin 4 – MAX232
1µF 5V Pin 2 – MAX232
1µF Pin 6 – MAX232 GND

Now it’s time to connect the MAX232 to the AVR UART pin headers. Place a 5x2
pin header onto the board. Be carefully not to place it in columns powered by another
device. Make the following connections.

10 pin Header Connection MAX232 Connection


Pin 1 GND
Pin 3 Pin 13 (R1IN)
Pin 4 Pin 14 (T1OUT)

Lastly, we must connect the MAX232 to the AVR. This involves two simple
connections.

41
MAX232 Connection AVR Connection
Pin 12 (R1OUT) Pin 2 (RXD)
Pin 11 (T1IN) Pin 3 (TXD)

4.6.4 The Many Steps of Compilation

This section is borrowed entirely from Sean Pieper’s excellent guide of the
TinyARM) GCC’s default behavior masks many details of the compilation process
from the average user. As a result, most programmers remain unfamiliar with the
behavior of the linker which is crucial for cross-compilation. To go from source to
binaries, there are a variety of steps involved.

These can be summarized as:


Preprocessing
Compilation
Assembly
Linking
Object Translation

Preprocessing, compilation and assembly flow as expected. As is normal, for speed,


we may want to create individual object files for each input file. When we get to the
linking stage, however, things become exciting.

To start with, when we’re programming the ATMega8, we’re operating without any
of the benefits of an OS. This means that we need to take care of a variety of low-
level tasks that, as a programmer, we aren’t typically concerned with. We provide
with a small assembly routine that will perform the most basic initialization, but if we
need to install interrupt handlers, we will be forced to modify this code to set the
appropriate jump points and distinguish between different interrupt sources.

For those of we who are unfamiliar with the functions performed by the linker (ld), it
resolves labels across a number of input files and then maps them to various segments
of memory. There are segments for code, read-only variables, initialized global
variables, uninitialized global variables and a variety of stacks. To some extent, these

42
mappings are controlled by the memory layout of the ATMega8 i.e. code, read-only
variables and the initial values of initialized global need to live in the part or memory
reserved for FLASH whereas space is reserved for initialized global to be copied into,
for uninitalized variables and for stacks in the RAM.

Finally, once the linking has been performed, we need to convert the output .elf file
to a .hex file that can be loaded directly into the processor’s flash. This operation is
performed by the objcopy utility.

Because of the numerous steps involved, it is strongly recommended that we take one
of the provided Make files and modify that to fit our needs. If we are experienced in
the dark arts of creating Makefiles, there is a lot of room for improvement in the
provided file and the course staff would greatly appreciate any useful tweaks to an
admittedly ugly, albeit functional, Makefile.

4.6.5 AVR Processor Ports

The AVR offers two methods to communicate with its GPIO’s. One method offers a
separate IO address space that can only be addressed with specific IO instructions (in,
out, etc.). The other method, which we may be more familiar with, is memory-
mapped IO which maps the entire IO address space onto the regular physical address
space of the AVR, allowing port’s to be read from and written to using simple C-style
pointers. Both formats are described here and both formats are supported by the
version of GCC we are using for this course.

Before setting up input and output commands, we must include the io.h file in our
programs. This file simply includes the real IO header file for the system we are
using. In our case, since we are using the ATMega8, io.h includes the file iom8.h.
Review this file so we know its contents.

With every available port comes 3 8-bit memory-mapped IO registers. These registers
serve the following purpose:

43
Register Purpose
PINx Actual physical connection to pin. Use this register for reading
DDRx Establish the direction of data. 1 for output, 0 for input

PORTx If DDR is set to 1, this is the output data. If DDR is set to 0, this indicates float or
pull-up

The interaction between various settings of PORTx and DDRx are shown below:

DDR bit = 1 DDR bit = 0


Port bit = 1 Output High Input Pull-Up
Port bit = 0 Output Low Input Floating

4.6.6 Connecting the SRAM

First, place the SRAM chip above or below the AVR microcontroller (for ease of
wiring). Refer to the SRAM datasheet as an aid for the rest of this section.

The table below shows the recommended connections to connect the SRAM to AVR.
Note, that we are only using the first 9 address bits which limits our SRAM to be 4Kb
due to restricted pin bandwidth on the AVR. Also, we dual use the AVR programmer
lines for the same reasons.

AVR Connection SRAM Connection


5V (Vcc) on breadboard Vcc
Ground on breadboard Vss
PD5 WE
PD6 OE
PD7 CE
PC0-PC5 A0-A5
PD2-PD4 A6-A8
Ground on breadboard A9-A14
PB0-PB7 IO0-IO8

44
4.6.7 Other Capabilities of the ATMega8

The ATMega8 has so many alternate functions available that it would be an


amazingly time consuming task to create support for all of them. The chip has several
PWM outputs, two internal timers, capture compare ports and a real-time clock. The
best way to learn about these features is to read the manual. The documentation for
this chip is particularly thorough and well written and includes many example code
blocks to quickly integrate and test functionality within our programs.

4.7 Serial Peripheral Interface for ATMega8

The Serial Peripheral Interface Bus or SPI or “spy” bus is a synchronous serial data
link standard named by Motorola that operates in full duplex mode. Figure 4.1 is
shown the block diagram serial peripheral interfacing. Devices communicate in
master/slave mode where the master device initiates the data frame. Multiple slave
devices are allowed with individual slave select (chip select) lines. Sometimes SPI is
called a “four wire” serial bus, contrasting with three, two and one wire serial busses.

Fig 4.1: Block diagram serial peripheral interface for ATMega8

Fig 4.1 : Block diagram of serial peripheral interfacing

45
4.8 Design of the Circuits & Varieties Statements of Moving 8×8
Dot Matrix Display

Fig 4.2 : Initial Statement

46
4.9 Simulation Results

Fig 4.3 : 1st Statement

47
Fig 4.4 : 2nd Statement

48
Fig 4.5 : 3rd Statement

49
Chapter
5
CONCLUSION

This application note explains how to control the display of characters on an 8×8 LED
moving message display using the GPIO ports of the ATMega8. A four-unit 8×8
matrix display is controlled by two GPIO ports (16 GPIO pins). The APIs provided in
this application note facilitate easy implementation for displaying characters on an
8×8 LED matrix. The scroll and blink display modes are supported. The display
scrolling speed and the blink rate can be easily changed. The software is written to
decouple these functions, thus enabling combinations of these modes as per our
requirements. All of the printable ASCII characters (ASCII code 0×20 to 0×7E) are
supported. The procedure outlined for displaying printable ASCII characters can also
be used for displaying nonstandard characters and symbols.

50
APPENDIX A

/*************************************************************************************************
// File Name : avrspi.c
// Version : 1.0
// Description : SPI I/O Using 74HC595 8-bit shift registers
// with output latch
// Author : Tanvir, Akhter, Kamrul, Mokhlesh
// Target : AVRJazz Mega8 Board
// Compiler : AVR-GCC 4.3.0; avr-libc 1.6.2 (WinAVR 20070610)
// IDE : Atmel AVR Studio 4.13
// Programmer : AVRJazz Mega8 STK500 v2.0 Bootloader
// : AVR Visual Studio 4.13, STK500 programmer
// Last Updated : 24 Feb 2010
*************************************************************************************************/
#include <avr/io.h>
#include <util/delay.h>

#define SPI_PORT PORTB


#define SPI_DDR DDRB
#define SPI_CS PB2
#define F_CPU 8000000UL
unsigned char p=0;

unsigned char SPI_WriteRead(unsigned char dataout)


{
unsigned char datain;

// Start transmission (MOSI)


SPDR = dataout;
// SPDR=0xFF;

// Wait for transmission complete


while(!(SPSR & (1<<SPIF)));

// Get return Value;


datain = SPDR;

p=p+1;
if (p==3)
{
p=0;

// Latch the Output using rising pulse to the RCK Pin


SPI_PORT |= (1<<SPI_CS);

_delay_us(1); // Hold pulse for 1 micro second


SPI_PORT &= ~(1<<SPI_CS);

51
}

// Disable Latch

// Return Serial In Value (MISO)

return datain;
}

int main(void)
{
//unsigned char cnt;
//unsigned char
data11=0xFF,data12=0x87,data13=0xF7,data21=0xCF,data22=0xBB,data23=0
xEB,data31=0xB7,data32=0xBB,data33=0xDD;
//unsigned char
data41=0x7F,data42=0xBB,data43=0x80,data51=0x7F,data52=0x87,data53=0
xBE,data61=0x7F,data62=0xBB,data63=0xBE;
//unsigned char
data71=0xB7,data72=0xBB,data73=0xBE,data81=0xCF,data82=0x87,data83=0
xFF;//,data61=0x7F,data62=0xBB,data63=BE;
unsigned char colmn,loop;
unsigned char m[8][3]={0xFF, 0x87,0xF7,
0xCF, 0xBB,0xEB,
0xB7, 0xBB,0xDD,
0x7F, 0xBB,0x80,
0x7F, 0x87,0xBE,
0x7F, 0xBB,0xBE,
0xB7, 0xBB,0xBE,
0xCF, 0x87,0xFF};

DDRD=0xFF;
PORTD=0x00;
//PORTD=m[0][2];
//unsigned char d=m[0][2];

// PORTD=d>>1;

// Initial the AVR ATMega168 SPI Peripheral

// Set MOSI and SCK as output, others as input


SPI_DDR = (1<<PB3)|(1<<PB5)|(1<<PB2);

// Latch Disable (RCK Low)


SPI_PORT &= ~(1<<SPI_CS);

52
// Enable SPI, Master, set clock rate fck/2 (maximum)
SPCR = (1<<SPE)|(1<<MSTR);
SPSR = (1<<SPI2X);

// Reset the 74HC595 register

for(loop=1; loop<25;loop++)
{

for (unsigned char r=0; r<8;r++)


{
if (r==0)
{
colmn=0x80;
}
PORTD=colmn;
colmn=colmn>>1;

for (unsigned char c=0; c<3;c++)


{
SPI_WriteRead(m[r][c]);

}
_delay_us(900);

if(loop==24)
{
loop=1;
for (unsigned char r=0; r<8;r++)
{
for (unsigned char c=0; c<3;c++)
{
if (c==0)
{
unsigned char y,z;
z=m[r][2];
z=z<<7;
y=m[r][c];
y=y>>1;
m[r][c]=y|z;
}
if (c==1)
{

53
unsigned char y,z;
z=m[r][1];
z=z>>1;
y=m[r][0];
y=y<<7;
m[r][c]=y|z;
}
if (c==2)
{
unsigned char y,z;
z=m[r][2];
z=z>>1;
y=m[r][1];
y=y<<7;
m[r][c]=y|z;
}
SPI_WriteRead(m[r][c]);
}

/*

PORTD=0x80;
SPI_WriteRead(data11);

SPI_WriteRead(data12);
SPI_WriteRead(data13);
// SPI_WriteRead(0xF787FF);

_delay_ms(10);

PORTD=0x40;
SPI_WriteRead(data21);
SPI_WriteRead(data22);

54
SPI_WriteRead(data23);
// SPI_WriteRead(0xEBBBCF);

_delay_ms(10);

PORTD=0x20;
SPI_WriteRead(data31);
SPI_WriteRead(data32);
SPI_WriteRead(data33);
//SPI_WriteRead(0xDDBBB7);

_delay_ms(10);

PORTD=0x10;
SPI_WriteRead(data41);
SPI_WriteRead(data42);
SPI_WriteRead(data43);
// SPI_WriteRead(0x80BB7F);
_delay_ms(10);

PORTD=0x08;
SPI_WriteRead(data51);
SPI_WriteRead(data52);
SPI_WriteRead(data53);
// SPI_WriteRead(0xBE877F);
_delay_ms(10);

PORTD=0x04;
SPI_WriteRead(data61);
SPI_WriteRead(data62);
SPI_WriteRead(data63);
//SPI_WriteRead(0xBEBB7F);
_delay_ms(10);

PORTD=0x02;
SPI_WriteRead(data71);
SPI_WriteRead(data72);
SPI_WriteRead(data73);
//SPI_WriteRead(0XBEBBB7);
_delay_ms(10);

PORTD=0x01;
SPI_WriteRead(data81);
SPI_WriteRead(data82);
SPI_WriteRead(data83);

55
// SPI_WriteRead(0xFF87CF);
_delay_ms(10);

// data1=data1>>1;
// data2=data2>>1;

//_delay_ms(100);
/* if (i==24)
{
i=1;
data11=data11>>1;
data12=data12>>1;
data13=data13>>1;
data21=data21>>1;
data22=data22>>1;
data23=data23>>1;
data31=data31>>1;
data32=data32>>1;
data33=data33>>1;
data41=data41>>1;
data42=data42>>1;
data43=data43>>1;
data51=data51>>1;
data52=data52>>1;
data53=data53>>1;
data61=data61>>1;
data62=data62>>1;
data63=data63>>1;
data71=data71>>1;
data72=data72>>1;
data73=data73>>1;
data81=data81>>1;
data82=data82>>1;
data83=data83>>1;
}

return 0;
}

*/

56
REFERENCES

The ATMega8 Data Sheet:


http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf

The AVR ISA Reference Manual:


http://www.atmel.com/dyn/resources/prod_documents/doc0856.pdf

The MAX232 Data Sheet:


http://pdfserv.maxim-ic.com/en/ds/MAX202E-MAX241E.pdf
www.microchip.com

Review of bits, bytes, etc.: http://www.learn-c.com/data_lines.html


Tutorial on C programming with microcontrollers:
http://www.learn-c.com/alltoget.html

Online C language reference: http://ccs.ucsd.edu/c/

C Programming:
http://www.imada.sdu.dk/~svalle/courses/dm14-2005/mirror/c/ccourse.html

Developing Embedded Software in C:


http://users.ece.utexas.edu/~valvano/embed/toc1.htm

General support for entire Freescale product line:


http://www.freescale.com/support
http://www.alldatasheet.com
http://www.microcontroller.com
http://www.microdigitaled.com
http://www.kitsrus.com

James Clar, “3d display cube – white”,


http://www.jamesclar.com/product/2005/3dcubewhite

57

View publication stats