Professional Documents
Culture Documents
APPLICATION OF MICROCONTROLLER IN
LED MATRIX DISPLAY
STUDENT
: CHEW HANWEI
(PI NO. E0806350)
SUPERVISOR
: DR. FUNG CHI FUNG
PROJECT CODE : JAN2011/ENG/045
TABLE OF CONTENTS
Page
ABSTRACT
iv
ACKNOWLEDGEMENT
LISTS OF FIGURES
vi
CHAPTER ONE
INTRODUCTION
1.1
Project Objective
1.2
Overall Objective
1.3
1.4
Project Management
CHAPTER TWO
LITERATURE REVIEW
12
12
2.1
Introduction of LED
12
2.2
13
2.3
15
CHAPTER THREE
HARDWARE SYSTEM IMPLEMENTATION
17
17
3.1
17
3.2
19
3.3
20
3.4
21
3.5
22
3.6
23
CHAPTER FOUR
SOFTWARE SYSTEM IMPLEMENTATION
25
25
4.1
25
4.2
26
4.3
27
4.4
29
4.5
30
CHAPTER FIVE
PROJECT INTEGRATION AND ANALYSIS
33
33
5.1
33
5.2
36
ii
5.3
CHAPTER SIX
CONCLUSIONS AND FUTURE WORK
38
40
40
6.1
Conclusions
40
6.2
Recommendations
41
REFLECTION
42
REFERENCES
43
Appendixes
44
44
44
44
48
54
54
54
55
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.
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.
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.
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
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.
1.2
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.
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
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.
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.
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.
10
11
6. Project Review
1. Literature Review
Week
Project Tasks
Plan
Actual
Feb-11
2 3 4
5
Mar-11
6 7 8
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
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.
12
2.2
13
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.
14
2.3
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.
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
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.
16
CHAPTER THREE
HARDWARE SYSTEM IMPLEMENTATION
3.1
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.
17
DS1307 Real
Time Clock
AT89S52
Row Scanning
Circuit
LED Matrix
Display
Column Scanning
Circuit
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.
18
3.2
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.
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.
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.
19
3.3
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.
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
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.
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.
21
3.5
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
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
23
The 10-pin connector is then connected to the computer parallel port as shown.
24
CHAPTER FOUR
SOFTWARE SYSTEM IMPLEMENTATION
4.1
Start
Initialize Serial
Setup Interrupts
Read DS1307
Infinite Loop
Display Time
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.
25
4.2
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
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
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;
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.
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.
27
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)
{
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
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
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
{
0
1
2
3
4
5
6
7
8
9
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();
// 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
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);
}
}
32
CHAPTER FIVE
PROJECT INTEGRATION AND ANALYSIS
5.1
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.
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.
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.
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.
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.
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.
35
Lastly, the AT89S52 microcontroller control system. The few essential circuits
include the 11 MHz oscillator, reset, and the external interrupts.
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
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.
36
As soon as transfer is complete, the program starts and the LED matrix display is
turned on.
37
5.3
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.
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
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.
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.
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.
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.
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.
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]
[6]
ATMEL ISP Programmer, Retrieved on Jun 2011, from World Wide Web:
http://www.sixca.com/eng/articles/at89s_isp/index.html
[7]
[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,
43
Appendixes
Appendix A Program Source Code
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"}};
={{"Jan"},
{"Feb"},
{"Mar"},
{"Apr"},
{"May"},
{"Jun"},
{"Jul"},
{"Aug"},
{"Sep"},
44
{"Oct"},
{"Nov"},
{"Dec"}};
sbit SDA
sbit SCL
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
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
{
0
1
2
3
4
5
6
7
8
9
dot1
dot2
checker
all on
48
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();
*/
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);
}
}
53
54
55
56