You are on page 1of 56

SIM UNIVERSITY

SCHOOL OF SCIENCE AND TECHNOLOGY

APPLICATION OF MICROCONTROLLER IN
LED MATRIX DISPLAY

STUDENT

: CHEW HANWEI
(PI NO. E0806350)
SUPERVISOR
: DR. FUNG CHI FUNG
PROJECT CODE : JAN2011/ENG/045

A project report submitted to SIM University


in partial fulfilment of the requirements for the degree of
Bachelor of Engineering
November 2011

TABLE OF CONTENTS
Page
ABSTRACT

iv

ACKNOWLEDGEMENT

LISTS OF FIGURES

vi

CHAPTER ONE

INTRODUCTION

1.1

Project Objective

1.2

Overall Objective

1.3

Proposed Approach and Method

1.4

Project Management

CHAPTER TWO
LITERATURE REVIEW

12
12

2.1

Introduction of LED

12

2.2

Applications of LED Matrix Display

13

2.3

Techniques of Driving LED Matrix Display

15

CHAPTER THREE
HARDWARE SYSTEM IMPLEMENTATION

17
17

3.1

System Overall Structure Design

17

3.2

Atmel AT89S52 Control System

19

3.3

DS1307 Real-time Clock

20

3.4

LED Matrix Display Design

21

3.5

Circuit Design for 5V Power Source

22

3.6

AT89S52 In System Programming (ISP)

23

CHAPTER FOUR
SOFTWARE SYSTEM IMPLEMENTATION

25
25

4.1

Software Design Structure

25

4.2

Codes for Dot Matrix Display Characters

26

4.3

DS1307 Interface With AT89S52

27

4.4

Interrupt Service Routine for Time Adjustment

29

4.5

Software Development Process

30

CHAPTER FIVE
PROJECT INTEGRATION AND ANALYSIS

33
33

5.1

PCB Design and Component Assembly

33

5.2

Programming the AT89S52

36

ENG499 CAPSTONE PROJECT REPORT

ii

5.3

Prototype Under Test

CHAPTER SIX
CONCLUSIONS AND FUTURE WORK

38
40
40

6.1

Conclusions

40

6.2

Recommendations

41

REFLECTION

42

REFERENCES

43

Appendixes

44

Appendix A Program Source Code

44

Appendix A1: Serial Initialization

44

Appendix A2: DS1307 driver

44

Appendix A3: AT89S52 Main

48

Appendix B: Schematic Diagrams

54

Appendix B1: Schematic for LED Matrix Display

54

Appendix B2: Schematic for ISP Program

54

Appendix B3: Schematic for 5V Supply

55

Appendix C: Dot Matrix Characters

ENG499 CAPSTONE PROJECT REPORT

56

iii

ABSTRACT

LED matrix display has become an important symbol of the city lighting, modernization
and information society with continuous improvement and beautification of people's living
environment.

This project introduces display design process about hardware and software based on Atmel
AT89S52 single chip microcontroller. The system mainly involves the AT89S52
microcontroller, a LED matrix display and a real time clock (DS1307).

We use a simple external circuit to control the display screen, whose size is 8-pixel by 32pixel. The display screen can display the size of four 5-pixel by 7-pixel dot matrix
characters by dynamically displaying a 4-digits real time clock. This display screen has
advantages of compact in size, fewer hardware components and simpler circuit structure.

Based on the prototyping platform, an algorithm for translating register values from real
time clock to appropriate displayed patterns is implemented. Through production of
hardware and testing of software, we achieved the desired effect of a LED digital clock
display.

ENG499 CAPSTONE PROJECT REPORT

iv

ACKNOWLEDGEMENT

I would like to present my appreciation to the following individuals for their untiring support
and encouragement for the whole duration of my final year project. Without their help, this
project would not be able to complete so smoothly and attain success.

Firstly, I would like to thank my project supervisor, Dr. Fung Chi Fung for his guidance and
patience. I am grateful for his valuable feedback and suggestions that enable the project to
progress smoothly as planned.

Secondly, I would like to thank the management and my colleagues of Panasonic


Semiconductor Singapore. With their kind understanding, I am able to concentrate and focus
during my course of studies.

Last but not least, I would like to thank my family and friends for being so supportive and
kept me going to finally complete this project and achieve success.

ENG499 CAPSTONE PROJECT REPORT

LISTS OF FIGURES
Figure 1.1: Project Gantt Chart
Figure 2.1: Structure of a LED
Figure 2.2: 8*8 LED matrix
Figure 2.3: Bus Stopping
Figure 2.4: ERP gantry
Figure 2.5: Common-Anode LED matrix
Figure 2.6: Example of a 5x7 font characters within 8x8 LED matrixes
Figure 3.1: ATMEL AT89S52 Microcontroller
Figure 3.2: Overview System Design
Figure 3.3: Clock Circuit for AT89S52
Figure 3.4: Reset Circuit for AT89S52
Figure 3.5: AT89S52 External Interrupts
Figure 3.6: DS1307 Real Time Clock
Figure 3.7: Four 8x8 LED Matrix Panels
Figure 3.8: UDN2981 LED Driver
Figure 3.9: Two 74HC154 for Columns Date
Figure 3.10: 5V Power Supply
Figure 3.11: AT89S52 ISP Timing Diagram
Figure 3.12: AT89S52 ISP Circuit
Figure 3.13: ISP Download Cable
Figure 4.1: Program Flowchart
Figure 4.2: Code for Dot Matrix Character
Figure 4.3: DS1307 I2C Timing Diagram
Figure 5.1: Components Layout for Prototype
Figure 5.2: Wiring for Prototype
Figure 5.3: 5V Fixed Voltage Regulator
Figure 5.4: Two 74HC154 for Columns Data
Figure 5.5: DS1307 and 3V Backup Battery
Figure 5.6: ISP Circuit
Figure 5.7: AT89S52 Control System
Figure 5.8: Atmel ISP Flash Programmer
Figure 5.9: Prototype Powered Up
Figure 5.10: Initialization of LED Matrix Display
Figure 5.11: Push Switches for Hour and Minutes Adjustment
Figure 5.12: Digital Clock Display 21:50

ENG499 CAPSTONE PROJECT REPORT

11
12
13
13
14
15
16
17
18
19
19
20
20
21
21
22
22
23
24
24
25
26
27
33
33
34
34
35
35
36
37
38
38
39
39

vi

CHAPTER ONE
INTRODUCTION
1.1

Project Objective

This project aims at studying the hardware structure of LED matrix display system
based on microcontroller control. As a case study, we will focus on prototyping a
LED matrix display panel for displaying real time clock information. It involves
interfacing a microcontroller to a group of array LED modules and a real-time clock.
Based on the prototyping platform, an algorithm for translating register values from
real-time clock to appropriate displayed patterns is needed to be implemented.
Possible extension of interfacing the prototyping system to PC via a communication
port could be considered.

The objectives highlighted for this project are as follows:

1.2

To implement a LED matrix display panel.

To interface a microcontroller to the LED matrix display.

To program the microcontroller using C complier.

To display real-time clock on the LED matrix display.

Overall Objective

Nowadays, LED matrix displays are used to display information on machines, lifts,
public transports like buses, MRT and many other devices requiring a simple display
device of limited resolution. The display consists of an array of LEDs arranged in a
rectangular configuration such that by selective switching of LEDs, text or graphics
are then displayed.

ENG499 CAPSTONE PROJECT REPORT

Through studying the existing techniques of driving LED matrix display, this project
aims to simplify the hard wiring of the circuit yet not compromising the flexibility
of the controller, and most importantly acquiring the skill for implementing a small
scale LED matrix display.

1.3

Proposed Approach and Method

In this project, an LED matrix will be implemented. This LED matrix display will
be interfaced by programming an 8051 microcontroller and driving the LED matrix.

The project scope will be divided into different phases in order to achieve the
project objectives.
Phase 1 Background Information research
Phase 2 Preparation of initial report TMA01
Phase 3 Research on applications, commonly used techniques for driving LED
display

panels,

LED

matrix

display,

8051

Microcontroller,

inter-device

communication protocols
Phase 4 Implementation of prototype consisting of LED display panel and
microcontroller
Phase 5 Program microcontroller to display real-time clock on LED matrix display
Phase 6 Project review
Phase 7 Preparation of final report
Phase 8 Preparation of oral presentation

In adopting the above approach, the project could be expected to develop in a more
structured and systematic way and this will ensure that the project will be able to
progress smoothly.

Phases 4 and 5 are marked as the major milestone of this project.

In phase 4, the prototype must be implemented with care to deliver the functionality
of the LED matrix display. Time will be allocated wisely in case of troubleshooting
error arises.
ENG499 CAPSTONE PROJECT REPORT

In phase 5, programming will be carried out for the 8051 microcontroller. Basic
control of the LED matrix display should be carrying out to ensure functionality of
the circuit. Finally, a real-time clock will be display on the LED matrix display.

1.4

Project Management

The tasks for each project phase are listed for reference. The following are the
detail tasks descriptions required for each project phase.

Phase 1 (Literature Review):

Understanding project definitions

Research on project background

Phase 2 (Preparation of Project Proposal):

Setting the objective for the project

Planning the schedule for the projects progress

Capstone Project Proposal submission to MyUniSIM

Phase 3 (Research on LED matrix display, 8051 Microcontroller):

Understanding the arrangement of LEDs in matrix display

Research on applications of LED matrix display in everyday life

Understand the existing techniques use to drive LED matrix display

Phase 4 (Implementation of prototype consisting of LED display panel,


microcontroller):

Come up plan for the prototype design

Implement the prototype consisting of the necessary components

Phase 5 (Program microcontroller to display real-time clock on LED matrix


display):

Program the Microcontroller to drive the LED matrix display

Display real time clock on the LED matrix display

ENG499 CAPSTONE PROJECT REPORT

Phase 6 (Project Review):

Going through the things learnt from this project

Discuss on area for improvement

Phase 7 (Preparation of final report):

Finalizing the contents for Project Report

Capstone Project Report submission to SRL

Phase 8 (Preparation of oral presentation):

Preparation of the Poster for oral presentation

Oral Presentation for Project

In this project, a Gantt chart is utilised as the main tool for project management.
Gantt charts illustrate the start and finish dates for the tasks of a project in bar chart
format. The Gantt chart is created to monitor project progress with reference to the
planned schedule. It provides a general guideline on the dateline for each individual
task. The amount of time allocated depends on the scope of implementation. More
time are allocated to tasks that require in-depth study and labour intensive.

ENG499 CAPSTONE PROJECT REPORT

10

Figure 1.1: Project Gantt Chart

ENG499 CAPSTONE PROJECT REPORT

11

8. Preparation of Poster and Oral Presentation

7. Preparation of Final Report

6. Project Review

5.1 Microcontroller programming using C complier

5. Program microcontroller to display real-time clock on


LED matrix display

4.2 Implement prototype

4.1 Finalize on prototype design

4. Implementation of prototype consisting of LED display


modules and microcontroller

3.2 8051 Microcontroller

3.1 LED matrix display

3. Research on LED matrix display, 8051 Microcontroller and


finalizes plan on prototyping design

2. Project Initial Report

1.2 Research on Project Background

1.1 Understanding Project definition

1. Literature Review

Week
Project Tasks
Plan
Actual

Feb-11
2 3 4
5

Mar-11
6 7 8

Gantt Chart clearly shows


delay in Task4.
Addition time was spent on
prototype troubleshooting,

Apr-11
May-11
Jun-11
Jul-11
Aug-11
Sep-11
Oct-11
Nov-11
Dec-11
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

Revision Week

Examination Week

CHAPTER TWO
LITERATURE REVIEW

2.1

Introduction of LED

A light-emitting diode (LED) is a semiconductor light source which we see in our


daily lives. LEDs are used in many electronic devices such as lamps, traffic lights
and display with limited resolution. When a LED is turned on, electrons recombine
with the holes (positive carriers), these moving electrons thus release energy. The
released energy is emitted in a form of light photons, creating the visible light that
we can see. The energy level will determine the light frequency and hence the
colour of the light.

Figure 2.1: Structure of a LED

LED has several advantages over the conventional incandescent bulb. Due to the
fact that they do not have a filament that will burnt out, they last much longer. LED
also generates little heat as most of the energy is going directly to generating light
resulting higher energy efficiency.

ENG499 CAPSTONE PROJECT REPORT

12

2.2

Applications of LED Matrix Display

Figure 2.2: 8*8 LED matrix

When an array of LEDs is arranged in a rectangular configuration, a display panel is


formed. Text or graphic can be displayed on the LED matrix display. With the
mechanical robustness and long lifetime, LED matrix display is becoming widely
adopted in a wide range of practical applications.

Figure 2.3: Bus Stopping


A commonly seen example in our daily life is the Bus Stopping display. When
commuter presses the button, the display will lit up and alert others that bus will be
stopping at the next stop.

ENG499 CAPSTONE PROJECT REPORT

13

Figure 2.4: ERP gantry

Another example shown in Figure 2.4 is the ERP gantry. By using a large LED
matrix display, it clearly shows the time display and charges for passing the gantry
within the stated timeframe.

ENG499 CAPSTONE PROJECT REPORT

14

2.3

Techniques of Driving LED Matrix Display

LEDs are arranged in a rectangular array which allows the use of multiplexing.
By repeatedly turning on and off a LED at a sufficiently high speed, human eyes
will not be able to detect that the LED is off as the eyes remember the light source
for approximation of 40ms which is equivalent to 25Hz. This is known as the
persistence of vision theory. And hence multiplexing reduces the number of driving
signals required to control a LED matrix display.

There are typically 2 types of LED matrix connections, common anode and
common cathode. The LEDs are arranged in such a way that either all the cathodes
or anodes are connected together.

Figure 2.5: Common-Anode LED matrix

In Figure 2.5 shows a circuit diagram of a common-anode matrix. From the circuit,
the LEDs anode is connected together in each row. With an 8x8 LED module, the
panel totals up to 64 LEDs. Only 16 pins are needed to be wired-up in order to
achieve full control of all the 64 LEDs. As the scale of the panel being expanded,
an additional 8 control pins are required for every 8x8 LED module being included.

A possible alternative solution is to use LED drivers that are commercially available
in the market. One example is the MAX6952 from MAXIM. A single MAX6952 is
ENG499 CAPSTONE PROJECT REPORT

15

capable of driving an LED matrix up to 14 cathodes by 10 anodes. 104 ASCII fonts


are built-in on chip. This allows textual information to be displayed at reduced
complexity in control software.

Figure 2.6: Example of a 5x7 font characters within 8x8 LED matrixes

Due to the built-in font set, the programming involved in controlling alphanumeric
display, as shown in Figure 2.6, becomes very easy. Nevertheless, this approach
unavoidably limits the capability of controlling each LED individually and thereby
reducing the flexibility of the display pattern.

In this project, a microcontroller is employed to interface the LED matrix display.

ENG499 CAPSTONE PROJECT REPORT

16

CHAPTER THREE
HARDWARE SYSTEM IMPLEMENTATION
3.1

System Overall Structure Design

Microcontroller models were selected according to the target, function, reliability,


cost, accuracy and speed of the control system. According to the actual situation of
the subject, the choice of microcontroller is largely based on two primary concerns:
easy-to-use and low-cost.

Due to the popularity in using 8051 amongst local higher institutions in Singapore,
readily accessible related resources are widely available. The 89S series, introduced
by Atmel in 2003, features in flexibility in programming, high performance and low
cost and low power.

Figure 3.1: ATMEL AT89S52 Microcontroller

AT89S52 is an 8-bit microcontroller with 8Kbytes of in-system programmable


Flash memory. The device is manufactured using Atmels high-density non-volatile
memory technology. It is fully compatible with the industry-standard 8051
instruction set. The on-chip Flash allows the program memory to be reprogrammed
either by in-system; chip on board firmware downloading or by a conventional nonvolatile memory programmer. For the aforementioned reasons, AT89S52 is chosen
as the controller of the entire system for the present application.

ENG499 CAPSTONE PROJECT REPORT

17

DS1307 Real
Time Clock

AT89S52

Row Scanning
Circuit

LED Matrix
Display

Column Scanning
Circuit

Figure 3.2: Overview System Design

By combining a versatile 8-bit CPU with in-system programmability on a


monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides
a highly-flexible and cost-effective solution to many embedded control applications.
The system is implemented by a circuitry which consists of AT89S52 chip, DS1307
real time clock, column scanning circuit, row scanning circuit and the four 8 x 8
LED dot matrix panels.

The display unit is composed of the four 8 x 8 LED dot matrix modules, a
UDN2981 and two 74HC154. Row data signal is driven by the UDN2981; the
UDN2981 data are from the P2 port of the microcontroller AT89S52.
The column scanning signal of each character was driven by the two 74HC154,
using a 74LS138 as an address decoding logic for chip selection. The input signal of
the 74HC154 and 74LS138 was given by the P0.0~P0.3 and P1.2~1.3 of the
AT89S52 respectively.

ENG499 CAPSTONE PROJECT REPORT

18

3.2

Atmel AT89S52 Control System

To realize the functionality of the AT89S52 chip, it is made up a few must have
circuitry. They consist of the clock circuit, reset circuit and the interrupt circuit.

Figure 3.3: Clock Circuit for AT89S52

The clock circuit of AT89S52 composes of pin 18, 19 (XTALI and XTAL2),
connected to a 12MHz crystal X1, capacitor C1 and C2, and uses on-chip oscillator
mode.

Figure 3.4: Reset Circuit for AT89S52

Reset circuit uses a simple power-on reset circuit, and mainly consist of resistor R1,
capacitor C3, connected to the AT89S52's reset input pin.

ENG499 CAPSTONE PROJECT REPORT

19

Figure 3.5: AT89S52 External Interrupts


Push button switches are connected to the AT89S52s external interrupt pin. With
the switches connected to ground, the interrupts are programmed to be triggered
during the signal falling edge. These switches will be programmed to facilitate the
settings of clocks hour and minute.

3.3

DS1307 Real-time Clock

The DS1307 serial real-time clock (RTC) is a low-power; full binary-coded decimal
(BCD) clock/calendar. Address and data are transferred serially through an I2C,
bidirectional bus. The SDA and SCL pin are connected to P1.1 and P1.0 of the
AT89S52 respectively. The clock/calendar provides a full set of real-time
information about seconds, minutes, hours, day, date, month, and year.

Figure 3.6: DS1307 Real Time Clock

The clock operates in either 24-hour or 12-hour format with an AM/PM indicator.
The DS1307 has a built-in power-sense circuit that detects power failures and
automatically switches to the backup 3V supply. Time-keeping operation continues
while the part operates from the backup supply.
ENG499 CAPSTONE PROJECT REPORT

20

3.4

LED Matrix Display Design


The display screen is made up of four 8 x 8 led matrix modules, resulting an 8 x 32
pixels display in 2-dimension. The size of each character is 5 x 7 in our design. With
the display holding up to four characters one at a time, it allows a four digit hour
and minute clock to be displayed simultaneously.

Figure 3.7: Four 8x8 LED Matrix Panels

The eight rows of the four LED matrix modules are connected to the Port2 of the
microcontroller via a UDN2981 current driver. Port2 supplies the row data signal of
the required character to be displayed.

Figure 3.8: UDN2981 LED Driver

The 32 columns of LEDs are connected to the outputs of the two 74HC154 chips.
The 74LS138 is used to decode the address for the selection between the two
74HC154 chips. Its inputs are given from the microcontroller port pins P1.2~1.3 and
its outputs are connected to the enable pins of the two 74HC154 chips. When either
one of the 74HC154 chips is asserted, it then gets the input from microcontroller
port pins P0.0~P0.3 thus enabling a single column to be turned on with reference to
the row signal data coming from Port2 of the microcontroller.

ENG499 CAPSTONE PROJECT REPORT

21

Figure 3.9: Two 74HC154 for Columns Date

3.5

Circuit Design for 5V Power Source


In this project, the circuit is powered by a 5 volt supply. To obtain a regulated 5 volt
supply, a 7805 fixed voltage regulator, powered by a common 9 volt adapter is used.

Figure 3.10: 5V Power Supply

ENG499 CAPSTONE PROJECT REPORT

22

7805 is equipped with built-in protection circuitry against overheating and shortcircuits, making it quite robust. This protection feature provides protection not only
for the component itself, but also for the rest of the circuits.

3.6

AT89S52 In System Programming (ISP)

According to the specification of the AT89S52, ISP is performed using 4 lines.


Physically data are transferred through 2 lines only, as in the case of I2C interface.
Data is shifted in serially on bit-by-bit basis though the MOSI line, with a clock
cycle between each bit and the next on the SCK line. MISO line is used for reading
as well as code verification; it is only used to output the code from the FLASH
memory of the microcontroller.

Figure 3.11: AT89S52 ISP Timing Diagram

The RST pin, which is used to reset the device, is also used to enable the 3 pins
(MOSI,MISO and SCK) to be used for ISP simply by setting RST to HIGH (5V),
otherwise if RST is low (0V), the program will start running and those three pins,
are used normally as P1.5, P1.6 and P1.7

ENG499 CAPSTONE PROJECT REPORT

23

Figure 3.12: AT89S52 ISP Circuit

The 10-pin connector is then connected to the computer parallel port as shown.

Figure 3.13: ISP Download Cable

ENG499 CAPSTONE PROJECT REPORT

24

CHAPTER FOUR
SOFTWARE SYSTEM IMPLEMENTATION
4.1

Software Design Structure

Due to the maturity in compiler support, C language is commonly used often a


preferred choice of language to program microcontroller. Programming a
microcontroller using C often results in considerable saving in programming effort
and much reduced development cycle in design.

Start

Initialize Serial

Setup Interrupts

Read DS1307
Infinite Loop
Display Time

Figure 4.1: Program Flowchart

The entire software design mainly composes of display routine and real time clock
control routine. The characters to be displayed on the LED matrix modules and
other data for transmission control and display functions were achieved by dynamic
scanning. Real-time communication between DS1307 and the microcontroller
ensures the information being displayed is always up-to-date.

ENG499 CAPSTONE PROJECT REPORT

25

4.2

Codes for Dot Matrix Display Characters

In the present design, the characters code is obtained by column scanning method.
Each character is composed of 5 x 7 pixels.
R1
R2
R3
R4
R5
R6
R7
R8

C1 C2 C3 C4 C5

Figure 4.2: Code for Dot Matrix Character


In the first column for character 0, R2~R7 are asserted while the rest are deasserted. That is, in binary 00111110, and converts to hexadecimal as 3Eh. With the
codes for each column, the program turns on the respective LEDs column by
column with a refresh rate faster than 25Hz.

As human vision only remembers a light source for approximately 40ms, the
program scans all columns within the time frame. This theory is also known as
persistence of vision.

It can be seen from this principle, no matter what font or image display, we can use
this method to analyze the scan code and display on the LED matrix display.
unsigned char code number[15][5] =
0x3E, 0x51, 0x49, 0x45, 0x3E, //
0x44, 0x42, 0x7F, 0x40, 0x40, //
0x42, 0x61, 0x51, 0x49, 0x46, //
0x22, 0x41, 0x49, 0x49, 0x36, //
0x18, 0x14, 0x12, 0x7F, 0x10, //
0x27, 0x45, 0x45, 0x45, 0x39, //
0x3E, 0x49, 0x49, 0x49, 0x32, //
0x01, 0x71, 0x09, 0x05, 0x03, //
0x36, 0x49, 0x49, 0x49, 0x36, //
0x26, 0x49, 0x49, 0x49, 0x3E, //

{
0
1
2
3
4
5
6
7
8
9

With reference to the application of a real time clock in this project, a lookup table
of the codes for characters 0 to 9 is created. This will allow the program to get the
necessary code when updating the clock display.
ENG499 CAPSTONE PROJECT REPORT

26

4.3

DS1307 Interface With AT89S52

The AT89S52 microcontroller and DS1307 are linked via a serial communication
interface. In order to implement the serial communication functions between the two
devices, we need to initialise the serial port.
//--------------------------------------// Initialize serial port
//--------------------------------------void InitSerial(void)
{
SCON = 0x52;
// setup serial port control
TMOD = 0x20;
// hardware (9600 BAUD @11.05592MHZ)
TH1 = 0xFD;
// TH1
TR1 = 1;
// Timer 1 on
}

After which the SDA and SCL pin of the DS1307 are connected to pins of the
AT89S52 as defined in the program.
sbit SDA
sbit SCL

= P1^1;
= P1^0;

// connect to SDA pin (Data)


// connect to SCL pin (Clock)

To start and stop the data transfer, the state of SDA line need to switch from high to
low and low to high respectively, while keeping the SCL line high.

Figure 4.3: DS1307 I2C Timing Diagram

Referring to the timing diagram in Figure 4.3, data transfer is initiated after a Start
condition. The information is transferred bytewise and each receiver acknowledges
with a ninth bit. To end the transfer of data, the program needs to terminate the I2C
communication with a Stop condition. The functions for the Start and Stop of the
I2C communications are as follows.

ENG499 CAPSTONE PROJECT REPORT

27

//------------------------------// start I2C


//------------------------------void Start(void)
{
SDA = 1;
SCL = 1;
_nop_();_nop_();
SDA = 0;
_nop_();_nop_();
SCL = 0;
_nop_();_nop_();
}
//------------------------------// stop I2C
//------------------------------void Stop(void)
{
SDA = 0;
_nop_();_nop_();
SCL = 1;
_nop_();_nop_();
SDA = 1;
}

During the period of data transfer, the AT89S52 will read the real time clock
information or write data for the adjustment of time when necessary.
//------------------------------// Read RTC (all real time)
//------------------------------void ReadRTC(unsigned char * buff)
{

Start();
WriteI2C(0xD0);
WriteI2C(0x00);
Start();
WriteI2C(0xD1);
*(buff+0)=ReadI2C(ACK); //
*(buff+1)=ReadI2C(ACK); //
*(buff+2)=ReadI2C(ACK); //
*(buff+3)=ReadI2C(ACK); //
*(buff+4)=ReadI2C(ACK); //
*(buff+5)=ReadI2C(ACK); //
*(buff+6)=ReadI2C(NO_ACK);
Stop();

Second
Minute
hour
Day
date
month
// year

}
//------------------------------// Write RTC
//------------------------------void WriteRTC(unsigned char *buff)
{

ENG499 CAPSTONE PROJECT REPORT

28

Start();
WriteI2C(0xD0);
WriteI2C(0x00);
WriteI2C(*(buff+0));
WriteI2C(*(buff+1));
WriteI2C(*(buff+2));
WriteI2C(*(buff+3));
WriteI2C(*(buff+4));
WriteI2C(*(buff+5));
WriteI2C(*(buff+6));
Stop();
}

4.4

Interrupt Service Routine for Time Adjustment

For the adjustment of the time information in the DS1307, two external interrupts of
the AT89S52 are connected to ground through push switches. With reference to the
hard wiring of the switch connections, the interrupts are set to be triggered at falling
edge.
setup_interrupts () // Function to setup the External interrupt
{
EA = 1; // global interrupts enable
EX0 = 1; // enable external interrupt 0
EX1 = 1; // enable external interrupt 1
IT0 = 1; // make ext. interrupt 0 edge triggered
IT1 = 1; // make ext. interrupt 1 edge trigerred
}

With the setting up of the external interrupt, the program enters the interrupt service
routine when either switch is pressed. When interrupt 0 is triggered, the program
increments the hour and write the updated time into the DS1307.
void EXO_int0 (void) interrupt 0 // Interrupt Routine for Hour Increment
{
ReadRTC(&RTC_ARR[0]);
if(RTC_ARR[2] > 0x22)
{
RTC_ARR[2] = 0x00;
WriteRTC(&RTC_ARR[0]);
}
else if((RTC_ARR[2] & 0x0f) > 0x08)
{
RTC_ARR[2] = (RTC_ARR[2] + 0x10) & 0xf0;
WriteRTC(&RTC_ARR[0]);
}
else
{
RTC_ARR[2] = RTC_ARR[2] + 0x01;
WriteRTC(&RTC_ARR[0]);
}
delayms(10);
}
ENG499 CAPSTONE PROJECT REPORT

29

The function basically increases the ones digit of the hour. When the hour reaches 9
or 19 (in 24-hour format), it sets the ones digit to 0 and carry over the 1 to the tens
digit. Until the hour reaches 23 (in 24-hour format), double digits are reset.

The program performs in a similar manner for the settings of minutes when interrupt
2 is triggered.
void EX1_int2 (void) interrupt 2 // Interrupt Routine for Minute Increment
{
ReadRTC(&RTC_ARR[0]);
if(RTC_ARR[1] > 0x58)
{
RTC_ARR[1] = 0x00;
WriteRTC(&RTC_ARR[0]);
}
else if((RTC_ARR[1]&0x0f) > 0x08)
{
RTC_ARR[1] = (RTC_ARR[1] + 0x10) & 0xf0;
WriteRTC(&RTC_ARR[0]);
}
else
{
RTC_ARR[1] = RTC_ARR[1] + 0x01;
WriteRTC(&RTC_ARR[0]);
}
delayms(10);
}

4.5

Software Development Process

All C programs have a common organization scheme, this organization scheme are
followed in order to construct the application smoothly.
In the first part, headers file are included in the source code. These headers contain
functions that are shared across different programs.
#include
#include
#include
#include
#include

<REGX52.h>
<stdio.h>
<math.h>
<ds1307.h>
<serial.h>

Next we declare the global variables. Since global variables are able to be
referenced across the entire program, the rows and columns data for the LED matrix
display and the data information from the DS1307 are declared.
ENG499 CAPSTONE PROJECT REPORT

30

unsigned char code number[15][5] =


0x3E, 0x51, 0x49, 0x45, 0x3E, //
0x44, 0x42, 0x7F, 0x40, 0x40, //
0x42, 0x61, 0x51, 0x49, 0x46, //
0x22, 0x41, 0x49, 0x49, 0x36, //
0x18, 0x14, 0x12, 0x7F, 0x10, //
0x27, 0x45, 0x45, 0x45, 0x39, //
0x3E, 0x49, 0x49, 0x49, 0x32, //
0x01, 0x71, 0x09, 0x05, 0x03, //
0x36, 0x49, 0x49, 0x49, 0x36, //
0x26, 0x49, 0x49, 0x49, 0x3E, //
0x00, 0x00, 0x00, 0x00, 0x00};

{
0
1
2
3
4
5
6
7
8
9

unsigned char code dis_y[] =


{0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0x
fe,0xff,0x0f,0x1f,0x2f,0x3f,0x4f,0x5f,0x6f,0x7f,0x8f,0x9f,0xaf,0xbf,0xcf,
0xdf,0xef,0xff};
unsigned char RTC_ARR[7];

// Buffer for second,minute,.....,year

After declaration of global variables, functions that are called by the main program
are written. Sub-programs that are triggered by external interrupts are written too.

Lastly, the main software program consists of initialization, and an infinite loop for
retrieving the real time clock information from DS1307 and updating the LED
matrix display.
main()
{
unsigned char x,y,m1,m2,h1,h2,blink;
InitSerial();

// Initialize serial port

setup_interrupts (); // Setup of interrupts


for(x=0;x<16;x++) //Testing of LED display
{
ledtest();
ledtest2();
}
ledtest3();
while(1) // Program starts
time clock display
{
ReadRTC(&RTC_ARR[0]);
h1=RTC_ARR[2]>>4;
//
h2=RTC_ARR[2]&0x0f;
//
m1=RTC_ARR[1]>>4;
//
m2=RTC_ARR[1]&0x0f;
//

to read information from DS1307 and update the real-

// Read
Get the
Get the
Get the
Get the

DS1307 for
tens digit
ones digit
tens digit
ones digit

information
for hour
for hour
for minutes
for minutes

// Select first and second panels of the four LED panels


P1_2=0;
ENG499 CAPSTONE PROJECT REPORT

31

P1_3=0;
// Display the hour
digit(x,2,h1);
digit(x,8,h2);
// Display the colon
if (blink<50)
{
colon(x,y);
}
else if (blink<100)
{
}
else
{
blink=0;
}
blink++;
// Select the third and fourth panels of the four LED panels
P1_2=1;
P1_3=0;
// Display the minutes
digit(x,3,m1);
digit(x,9,m2);
}
}

ENG499 CAPSTONE PROJECT REPORT

32

CHAPTER FIVE
PROJECT INTEGRATION AND ANALYSIS
5.1

PCB Design and Component Assembly

Taking into account that the number of components used in this design is little, it
achieves the aim of creating a simplified circuit that could be wired manually. This
eliminates the need of fabricating a PCB and allows changes to be made to the
circuit with ease.

Figure 5.1: Components Layout for Prototype

With reference to the hardware design from chapter three, the different components
are soldered to place. The wires are then carefully soldered, trying to minimise any
error which may lead to malfunctioning of the prototype.

Figure 5.2: Wiring for Prototype

ENG499 CAPSTONE PROJECT REPORT

33

The 7805 fixed voltage regulator is the main power source for most components. A
9V adapter is connected to the 7805 through the power jack to enable the 7805 to
supply a stable 5V.

Figure 5.3: 5V Fixed Voltage Regulator

The LED matrix display consists of four 8 x 8 dot matrix modules. The eight rows
are connected to the UDN2981, while the thirty-two columns are connected to two
74HC154.

Figure 5.4: Two 74HC154 for Columns Data


ENG499 CAPSTONE PROJECT REPORT

34

The DS1307 is connected to a 32 kHz crystal and two pull-up resistors for the I2C
bus. The DS1307 is also connected to a 3V backup. The 3V Lithium button battery
ensures the time keeping function continues running when off accidental power
failure occurs.

Figure 5.5: DS1307 and 3V Backup Battery

The 10 pin connector together with the 74HCT154 line buffer are used to program
the AT89S52 microcontroller when connected to the PC through the ISP cable.

Figure 5.6: ISP Circuit

ENG499 CAPSTONE PROJECT REPORT

35

Lastly, the AT89S52 microcontroller control system. The few essential circuits
include the 11 MHz oscillator, reset, and the external interrupts.

Figure 5.7: AT89S52 Control System

After completion of soldering all components and wires, the prototype was put into
test. All contact points were checked for short and cold joints. This ensures all
electrical contacts are securely connected. With the prototyping hardware in place, it
was ready to be loaded with the compiled executable firmware in HEX format.

5.2

Programming the AT89S52

With the success of writing and compiling the C program explained in chapter four,
a HEX file corresponding to the codes is generated. This HEX file is a binary format
executable code being run on the AT89S52 target after downloading.

To transfer the HEX file to the AT89S52 microcontroller, an ISP cable is connected
to the PC parallel port. After which a 5V supply is provided to the microcontroller.
Ensuring that the connections for the microcontroller are functioning and able to
operate correctly, the HEX file will be transferred to the microcontroller through an
ISP Flash Programmer.

ENG499 CAPSTONE PROJECT REPORT

36

Figure 5.8: Atmel ISP Flash Programmer


By launching the ISP Flash Programmer, it requires user to browse for the HEX file
through the Open File button. The Write button initiates the transfer of the HEX file
from PC to the microcontroller.

As soon as transfer is complete, the program starts and the LED matrix display is
turned on.

ENG499 CAPSTONE PROJECT REPORT

37

5.3

Prototype Under Test


To power up the prototype, a 9V adaptor is connected. The program undergoes an
initialization stage. In the initialisation stage, the LED matrix display displays a few
self-testing patterns, this ensure that all four LED matrix modules are properly
functioning prior to displaying real time information.

Figure 5.9: Prototype Powered Up

Following the initialization process, the program enters an infinite loop to display
real time clock on the LED matrix display in a scanning fashion. Due to the
limitation in display area, only hour and minutes digits are displayed in the present
design.

Figure 5.10: Initialization of LED Matrix Display

ENG499 CAPSTONE PROJECT REPORT

38

As backup battery is installed for the DS1307, the time keeping function can be
maintained even when the prototyping board is powered down. But if there is a need
for time adjustment, user can still adjust the hour and minute digits through the
dedicated push button switches being connected on interrupt pins.

Hour

Minutes

Figure 5.11: Push Switches for Hour and Minutes Adjustment

The first switch controls the hour. To simplify the time setting procedure of the
prototyping board, each push button switch triggers the increment of current hour by
1. When it reaches 23 hour, the next increment returns the hour to 00. The same
principle applies to the setting of minute, with a maximum count at 59 before being
reset to 00.

Figure 5.12: Digital Clock Display 21:50

With the capability of displaying real-time clock on the LED matrix display and
time adjustment, the prototyping circuit is well proven to be fully functioning.

ENG499 CAPSTONE PROJECT REPORT

39

CHAPTER SIX
CONCLUSIONS AND FUTURE WORK
6.1

Conclusions

The main objective of this project is to develop a prototype, where real time clock is
being displayed on LED matrix display modules. The idea is successfully
implemented on a prototyping platform using an Atmel AT89S52 microcontroller
together with interfacing discrete logic components to drive the LED matrix display
modules.

The development of this project is split into two major tasks, the hardware and
software development. The hardware mainly includes the circuit construction by
wiring up the AT89S52 microcontroller, DS1307 real time clock and four LED dot
matrix modules. Together with a few other components, the chosen hardware is
soldered and wired manually on the PCB.

Although this project manages to design a simple circuit by cutting down the
number of components, extra labour effort is still needed to be put in the soldering.
The circuit has gone through quite numerous several rounds of iterative checks in
order to eliminate short, poor contacts and wrong wiring. This process can be
considered the most labour intensive as all the work need to be done manually.

The second task is the software development. Having chosen the AT89S52
microcontroller, programming becomes a lot easier as 8051 series is practically a
de-facto industry standard which receives tremendous interest both academically
and commercially. Much information on 8051 is available hence the program is
developed with much reduced difficulty.

By combining the two major tasks described above, we ended up with a fully
functioning prototype equipped with the ability to adjust and display the real time
clock on an array of LED display modules.

ENG499 CAPSTONE PROJECT REPORT

40

6.2

Recommendations

The aim of this project involves an in-depth study of the system architecture for
controlling an array of LED display modules in a cost-effective manner, hence
designing a system of driving LED matrix display using a microcontroller. A chosen
low-cost microcontroller is proven to be a viable potential option which offers a
high degree of flexibility with minimal hardware construction and programming
effort. Therefore the design of the system was kept as simple and straight forward,
allowing this report with reference value of both theory and practical.

Keeping in mind that designing a simple circuit does not mean limiting its
flexibility, as long as the microcontroller I/O interface is expanded, and increase the
number of LED matrix panels and related chips, one can design a larger screen and
unleash the full potential of the LED matrix display. Based on the success of the
present implementation, any large scale display can be easily constructed by
cascading similar logic functions to form a bigger system.

By using the DS1307 real time clock, information including the day and date are
readily available for use. This information can be displayed together with the digital
clock on a bigger screen.

The 8051 series microcontroller is so widely use in the market, it is compatible with
many peripheral chips and devices can be build around it. The area of applications
need not be limited to time display but expand into display of information like
temperature, commercial advertisements, real-time traffic information, public
announcement etc.

As the core control unit of the system, that is AT89S52 has relatively low operating
frequency, displaying video on LED panel may require the support of more
advanced processors running at a higher clock rate.

ENG499 CAPSTONE PROJECT REPORT

41

REFLECTION
This project experience is considered one of the most challenging in my years of study. The
process of completing this project is never similar to others that I have done. Firstly, being
an individual project, it requires a lot of effort to ensure smooth progress. Secondly, as a
part time student, I must admit to the fact that I have lesser time to complete my project.
This is where factors like time constraint and limitation of resources come into play.

The project objectives are reviewed carefully, ensuring that realistic targets are set to be
achieved. As I happen to take the PMJ300 project management concurrently with this
project. I picked up many tips in managing my project. Keeping in mind the importance of
project management, I try to follow closely to the project plan.

As expected, things do not always goes as planned. I started facing issues with my
prototype design. The design of the circuit was made simple with little components, but the
prototype just did not work properly. Although I have both the hardware and software
ready, they just do not seem to cooperate. I was unable to flash sample program into the
microcontroller. To make things worse, I was not able to determine the issue as it involves
so many parameters. It could be the hardware, ISP programmer, cables or wirings.

Troubleshooting begins and that is where I start lagging behind. I try to focus on
troubleshooting the hardware as I believe I messed up the circuit. I manually check the
circuit for short. As I could not find any short circuit, I try touching up the soldering for the
whole board, removing chances of any poor contacts. The process feels like I am making a
new board. Thankfully, I was able to transfer the program to the microcontroller after all
the effort. With the prototype functioning, I begin focus on the programming the
microcontroller. I succeeded in programming the microcontroller and display the digital
clock on the LED matrix display. But having lost time in troubleshooting the board, I had to
compromise developing additional features for the prototype.

This project allows me to gain technical knowledge and skills in project management.
Having successfully develop the end product is rewarding, but the valuable experience
gained through the process of this project is priceless.

ENG499 CAPSTONE PROJECT REPORT

42

REFERENCES
[1]

Light Emitting Diode, Retrieved on Feb 2011, from World Wide Web:
http://en.wikipedia.org/wiki/Light-emitting_diode

[2]

Maxim Application note 1033, Retrieved on Feb 2011, from World Wide Web:
http://www.maxim-ic.com/app-notes/index.mvp/id/1033

[3]

How Light Emitting Diodes Work, Retrieved on Feb 2011, from World Wide Web:
http://www.howstuffworks.com/led.htm

[4]

LED Matrix Computer Controlled, Retrieved on Feb 2011, from World Wide Web:
http://www.jbprojects.net/projects/led

[5]

8051 tutorial, Retrieved on May 2011, from World Wide Web:


http://www.ikalogic.com/tut_8051_1.php

[6]

ATMEL ISP Programmer, Retrieved on Jun 2011, from World Wide Web:
http://www.sixca.com/eng/articles/at89s_isp/index.html

[7]

Frederick M. Cady, Microcontrollers and Microcomputers Principles of Software and


Hardware Engineering, Oxford University Press, Inc., 1997

[8]

Raj Kamal, Embedded Systems (2008), Architecture, Programming and Design, 2nd
ED, Tata McGraw Hill

[9]

Thomas Schultz (2004), C and the 8051, 3rd ED, Canada: Pagefree Publishing Inc,

ENG499 CAPSTONE PROJECT REPORT

43

Appendixes
Appendix A Program Source Code

Appendix A1: Serial Initialization


//--------------------------------------// Serial port driver
// KEIL C51 v7.5
//--------------------------------------#include<REGX52.h>

//--------------------------------------// Initialize serial port


//--------------------------------------void InitSerial(void)
{
SCON = 0x52;
// setup serial port control
TMOD = 0x20;
// hardware (9600 BAUD @11.05592MHZ)
TH1 = 0xFD;
// TH1
TR1
= 1;
// Timer 1 on
}

Appendix A2: DS1307 driver


//--------------------------------------// DS1307 driver
//--------------------------------------#include<REGX52.h>
#include<intrins.h>
#define
#define
#define
#define
#define
#define

ACK
1
NO_ACK
0
SLAVE
0xD0
WRITE 0x00
READ
0x01
ERR_ACK 0x01

unsigned char i;
const unsigned char * DayStr[7]

{{"Sun"},
{"Mon"},
{"Tue"},
{"Wen"},
{"The"},
{"Fri"},
{"Sat"}};

const unsigned char * MonthStr[12]

={{"Jan"},
{"Feb"},
{"Mar"},
{"Apr"},
{"May"},
{"Jun"},
{"Jul"},
{"Aug"},
{"Sep"},

ENG499 CAPSTONE PROJECT REPORT

44

{"Oct"},
{"Nov"},
{"Dec"}};

sbit SDA
sbit SCL

= P1^1; // connect to SDA pin (Data)


= P1^0; // connect to SCL pin (Clock)

//------------------------------// Convert BCD 1 byte to HEX 1 byte


//------------------------------unsigned char BCD2HEX(unsigned int bcd)
{
unsigned char temp;
temp=((bcd>>8)*100)|((bcd>>4)*10)|(bcd&0x0f);
return temp;
}
//------------------------------// start I2C
//------------------------------void Start(void)
{
SDA = 1;
SCL = 1;
_nop_();_nop_();
SDA = 0;
_nop_();_nop_();
SCL = 0;
_nop_();_nop_();
}
//------------------------------// stop I2C
//------------------------------void Stop(void)
{
SDA = 0;
_nop_();_nop_();
SCL = 1;
_nop_();_nop_();
SDA = 1;
}
//------------------------------// Write I2C
//------------------------------void WriteI2C(unsigned char Data)
{
for (i=0;i<8;i++)
{
SDA = (Data & 0x80) ? 1:0;
SCL=1;SCL=0;
Data<<=1;
}
SCL = 1;
_nop_();_nop_();
SCL = 0;
ENG499 CAPSTONE PROJECT REPORT

45

}
//------------------------------// Read I2C
//------------------------------unsigned char ReadI2C(bit ACK_Bit)
{
unsigned char Data=0;
SDA = 1;
for (i=0;i<8;i++)
{
SCL = 1;
Data<<= 1;
Data = (Data | SDA);
SCL = 0;
_nop_();
}
if (ACK_Bit == 1)
SDA = 0; // Send ACK
else
SDA = 1; // Send NO ACK
_nop_();_nop_();
SCL = 1;
_nop_();_nop_();
SCL = 0;
return Data;
}
//------------------------------// Read 1 byte form I2C
//------------------------------unsigned char ReadBYTE(unsigned char Addr)
{
unsigned char Data;
Start();
WriteI2C(0xD0);
WriteI2C(Addr);
Start();
WriteI2C(0xD1);
Data = ReadI2C(NO_ACK);
Stop();
return(Data);
}
//------------------------------// Write 1 byte to I2C
//------------------------------void WriteBYTE(unsigned char Addr,unsigned char Data)
{
Start();
WriteI2C(0xD0);
WriteI2C(Addr);
WriteI2C(Data);
Stop();
}
//------------------------------ENG499 CAPSTONE PROJECT REPORT

46

// Read RTC (all real time)


//------------------------------void ReadRTC(unsigned char * buff)
{

Start();
WriteI2C(0xD0);
WriteI2C(0x00);
Start();
WriteI2C(0xD1);
*(buff+0)=ReadI2C(ACK); //
*(buff+1)=ReadI2C(ACK); //
*(buff+2)=ReadI2C(ACK); //
*(buff+3)=ReadI2C(ACK); //
*(buff+4)=ReadI2C(ACK); //
*(buff+5)=ReadI2C(ACK); //
*(buff+6)=ReadI2C(NO_ACK);
Stop();

Second
Minute
hour
Day
date
month
// year

}
//------------------------------// Write RTC
//------------------------------void WriteRTC(unsigned char *buff)
{
Start();
WriteI2C(0xD0);
WriteI2C(0x00);
WriteI2C(*(buff+0));
WriteI2C(*(buff+1));
WriteI2C(*(buff+2));
WriteI2C(*(buff+3));
WriteI2C(*(buff+4));
WriteI2C(*(buff+5));
WriteI2C(*(buff+6));
Stop();
}
//------------------------------// Convert date (BCD) to string of Day
// 1=Sunday
// 2=Monday
// And so on
//------------------------------char * Int2Day(unsigned char day)
{
return DayStr[day-1];
}
//------------------------------// Convert month (BCD) to string of Month
// 0x01=January
// 0x02=February
// ...........
// 0x12 = December
// And so on
//------------------------------char * Int2Month(unsigned char month)
{
return MonthStr[BCD2HEX(month)-1];
ENG499 CAPSTONE PROJECT REPORT

47

Appendix A3: AT89S52 Main


//--------------------------------------// AT89s52 Main
// KEIL C51 v7.5
//--------------------------------------#include <REGX52.h>
#include <stdio.h>
#include <math.h>
#include <ds1307.h>
#include <serial.h>
unsigned char code number[15][5] =
0x3E, 0x51, 0x49, 0x45, 0x3E, //
0x44, 0x42, 0x7F, 0x40, 0x40, //
0x42, 0x61, 0x51, 0x49, 0x46, //
0x22, 0x41, 0x49, 0x49, 0x36, //
0x18, 0x14, 0x12, 0x7F, 0x10, //
0x27, 0x45, 0x45, 0x45, 0x39, //
0x3E, 0x49, 0x49, 0x49, 0x32, //
0x01, 0x71, 0x09, 0x05, 0x03, //
0x36, 0x49, 0x49, 0x49, 0x36, //
0x26, 0x49, 0x49, 0x49, 0x3E, //
0x00, 0x00, 0x00, 0x00, 0x36, //
0x36, 0x00, 0x00, 0x00, 0x00, //
0x55, 0xAA, 0x55, 0xAA, 0x55, //
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //
0x00, 0x00, 0x00, 0x00, 0x00};

{
0
1
2
3
4
5
6
7
8
9
dot1
dot2
checker
all on

unsigned char code dis_y[] =


{0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,0x0f
,0x1f,0x2f,0x3f,0x4f,0x5f,0x6f,0x7f,0x8f,0x9f,0xaf,0xbf,0xcf,0xdf,0xef,0xff};
unsigned char RTC_ARR[7]; // Buffer for second,minute,.....,year
setup_interrupts () // Function to setup the External interrupt
{
EA = 1; // global interrupts enable
EX0 = 1; // enable external interrupt 0
EX1 = 1; // enable external interrupt 1
IT0 = 1; // make ext. interrupt 0 edge triggered
IT1 = 1; // make ext. interrupt 1 edge trigerred
}
void delayms(unsigned int count) // Delay Function
{
unsigned int i;
while(count)
{
i = 120;
while(i>0)
i--;
count--;
}
}
void EXO_int0 (void) interrupt 0 // Interrupt Routine for Hour Increment
{
ReadRTC(&RTC_ARR[0]);
ENG499 CAPSTONE PROJECT REPORT

48

if(RTC_ARR[2] > 0x22)


{
RTC_ARR[2] = 0x00;
WriteRTC(&RTC_ARR[0]);
}
else if((RTC_ARR[2] & 0x0f) > 0x08)
{
RTC_ARR[2] = (RTC_ARR[2] + 0x10) & 0xf0;
WriteRTC(&RTC_ARR[0]);
}
else
{
RTC_ARR[2] = RTC_ARR[2] + 0x01;
WriteRTC(&RTC_ARR[0]);
}
delayms(10);
}
void EX1_int2 (void) interrupt 2 // Interrupt Routine for Minute Increment
{
ReadRTC(&RTC_ARR[0]);
if(RTC_ARR[1] > 0x58)
{
RTC_ARR[1] = 0x00;
WriteRTC(&RTC_ARR[0]);
}
else if((RTC_ARR[1]&0x0f) > 0x08)
{
RTC_ARR[1] = (RTC_ARR[1] + 0x10) & 0xf0;
WriteRTC(&RTC_ARR[0]);
}
else
{
RTC_ARR[1] = RTC_ARR[1] + 0x01;
WriteRTC(&RTC_ARR[0]);
}
delayms(10);
}
void digit(int x,y,z) // Function to display the character at specific location of
screen
{
for(x=0;x<5;x++)
{
P0=dis_y[y];
P2=number[z][x];
y++;
delayms(1);
}
}
void colon(int x,y) // Function to display the colon to seperate the hour n minutes
{
P1_2=0;
P1_3=0;
y=15;
for(x=0;x<1;x++)
ENG499 CAPSTONE PROJECT REPORT

49

{
P0=dis_y[y];
P2=0x36;
y++;
delayms(1);
}
P1_2=1;
P1_3=0;
y=0;
for(x=0;x<1;x++)
{
P0=dis_y[y];
P2=0x36;
y++;
delayms(1);
}
}
void ledtest() // Testing of LEDs
{
unsigned int y,x=10;
while(x>0)
{
P1_2=0;
P1_3=0;
y=0;
for(y=0;y<16;y++)
{
P0=dis_y[y];
if (y%2==0)
{P2=0x55;}
else
{P2=0xAA;}
delayms(1);
}
P1_2=1;
P1_3=0;
y=0;

for(y=0;y<16;y++)
{
P0=dis_y[y];
if (y%2==0)
{P2=0x55;}
else
{P2=0xAA;}
delayms(1);
}
x--;
}
}
void ledtest2() //Testing of LEDs
{
unsigned int y,x=10;
while(x>0)
ENG499 CAPSTONE PROJECT REPORT

50

{
P1_2=0;
P1_3=0;
y=0;
for(y=0;y<16;y++)
{
P0=dis_y[y];
if (y%2==0)
{P2=0xAA;}
else
{P2=0x55;}
delayms(1);
}
P1_2=1;
P1_3=0;
y=0;

for(y=0;y<16;y++)
{
P0=dis_y[y];
if (y%2==0)
{P2=0xAA;}
else
{P2=0x55;}
delayms(1);
}
x--;
}
}
void ledtest3() //Testing of LEDs
{
unsigned int y,x=60;
while(x>0)
{
P1_2=0;
P1_3=0;
y=0;
for(y=0;y<16;y++)
{
P0=dis_y[y];
P2=0xFF;
delayms(1);
}
P1_2=1;
P1_3=0;
y=0;
for(y=0;y<16;y++)
{
P0=dis_y[y];
P2=0xFF;
delayms(1);
}
x--;
}
}
ENG499 CAPSTONE PROJECT REPORT

51

main()
{
unsigned char x,y,m1,m2,h1,h2,blink;
InitSerial();

// Initialize serial port

setup_interrupts (); // Setup of interrupts


for(x=0;x<16;x++) //Testing of LED display
{
ledtest();
ledtest2();
}
ledtest3();
ReadRTC(&RTC_ARR[0]); // Read information from DS1307
/*
RTC_ARR[0] = RTC_ARR[0]
RTC_ARR[1] = 0x15;
RTC_ARR[2] = 0x09;
RTC_ARR[3] = 0x02;
RTC_ARR[4] = 0x06;
RTC_ARR[5] = 0x09;
RTC_ARR[6] = 0x11;
WriteRTC(&RTC_ARR[0]);

& 0x7F; // enable oscillator (bit 7=0)


// minute = 15
// hour = 09 ,24-hour mode(bit 6=0)
// Day = 1 or sunday
// Date = 30
// month = Sept
// year = 11 or 2011
// Set RTC

*/
while(1) // Program starts to read information from DS1307 and update the real-time
clock display
{
ReadRTC(&RTC_ARR[0]); // Read DS1307
h1=RTC_ARR[2]>>4;
// Get first hour digit
h2=RTC_ARR[2]&0x0f;
// Get second hour digit
m1=RTC_ARR[1]>>4;
// Get first minute digit
m2=RTC_ARR[1]&0x0f;
// Get second minute digit
// Select first and second panels of the four LED panels
P1_2=0;
P1_3=0;
// Update the hour
digit(x,2,h1);
digit(x,8,h2);
// Display the colon
if (blink<50)
{
colon(x,y);
}
else if (blink<100)
{
}
else
{
blink=0;
}
blink++;
// Select the third and fourth panels of the four LED panels
P1_2=1;
ENG499 CAPSTONE PROJECT REPORT

52

P1_3=0;
// Update the minutes
digit(x,3,m1);
digit(x,9,m2);
}
}

ENG499 CAPSTONE PROJECT REPORT

53

Appendix B: Schematic Diagrams


Appendix B1: Schematic for LED Matrix Display

Appendix B2: Schematic for ISP Program

ENG499 CAPSTONE PROJECT REPORT

54

Appendix B3: Schematic for 5V Supply

ENG499 CAPSTONE PROJECT REPORT

55

Appendix C: Dot Matrix Characters

ENG499 CAPSTONE PROJECT REPORT

56

You might also like