LED Display by 8051

  • Upload
    sandeep

  • View
    374

  • Download
    13

Embed Size (px)

Citation preview

  • 8/10/2019 LED Display by 8051

    1/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 Universityin partial fulfilment of the requirements for the degree of

    Bachelor of Engineering

    November 2011

  • 8/10/2019 LED Display by 8051

    2/56

    ENG499 CAPSTONE PROJECT REPORT ii

    TABLE OF CONTENTSPage

    ABSTRACT iv

    ACKNOWLEDGEMENT v

    LISTS OF FIGURES vi

    CHAPTER ONE 7

    INTRODUCTION 7

    1.1 Project Objective 7

    1.2 Overall Objective 7

    1.3 Proposed Approach and Method 8

    1.4 Project Management 9

    CHAPTER TWO 12

    LITERATURE REVIEW 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 17

    HARDWARE SYSTEM IMPLEMENTATION 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 25

    SOFTWARE SYSTEM IMPLEMENTATION 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 33

    PROJECT INTEGRATION AND ANALYSIS 33

    5.1 PCB Design and Component Assembly 33

    5.2 Programming the AT89S52 36

  • 8/10/2019 LED Display by 8051

    3/56

    ENG499 CAPSTONE PROJECT REPORT iii

    5.3 Prototype Under Test 38

    CHAPTER SIX 40

    CONCLUSIONS AND FUTURE WORK 40

    6.1 Conclusions 40

    6.2 Recommendations 41

    REFLECTION 42

    REFERENCES 43

    Appendixes 44

    Appendix AProgram 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 56

  • 8/10/2019 LED Display by 8051

    4/56

    ENG499 CAPSTONE PROJECT REPORT iv

    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 32-

    pixel. 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 hasadvantages 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.

  • 8/10/2019 LED Display by 8051

    5/56

    ENG499 CAPSTONE PROJECT REPORT v

    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.

  • 8/10/2019 LED Display by 8051

    6/56

    ENG499 CAPSTONE PROJECT REPORT vi

    LISTS OF FIGURES

    Figure 1.1: Project Gantt Chart 11

    Figure 2.1: Structure of a LED 12

    Figure 2.2: 8*8 LED matrix 13

    Figure 2.3: Bus Stopping 13

    Figure 2.4: ERP gantry 14

    Figure 2.5: Common-Anode LED matrix 15Figure 2.6: Example of a 5x7 font characters within 8x8 LED matrixes 16

    Figure 3.1: ATMEL AT89S52 Microcontroller 17

    Figure 3.2: Overview System Design 18

    Figure 3.3: Clock Circuit for AT89S52 19

    Figure 3.4: Reset Circuit for AT89S52 19

    Figure 3.5: AT89S52 External Interrupts 20

    Figure 3.6: DS1307 Real Time Clock 20

    Figure 3.7: Four 8x8 LED Matrix Panels 21

    Figure 3.8: UDN2981 LED Driver 21

    Figure 3.9: Two 74HC154 for Columns Date 22

    Figure 3.10: 5V Power Supply 22

    Figure 3.11: AT89S52 ISP Timing Diagram 23

    Figure 3.12: AT89S52 ISP Circuit 24

    Figure 3.13: ISP Download Cable 24

    Figure 4.1: Program Flowchart 25

    Figure 4.2: Code for Dot Matrix Character 26

    Figure 4.3: DS1307 I2C Timing Diagram 27

    Figure 5.1: Components Layout for Prototype 33

    Figure 5.2: Wiring for Prototype 33Figure 5.3: 5V Fixed Voltage Regulator 34

    Figure 5.4: Two 74HC154 for Columns Data 34

    Figure 5.5: DS1307 and 3V Backup Battery 35

    Figure 5.6: ISP Circuit 35

    Figure 5.7: AT89S52 Control System 36

    Figure 5.8: Atmel ISP Flash Programmer 37

    Figure 5.9: Prototype Powered Up 38

    Figure 5.10: Initialization of LED Matrix Display 38

    Figure 5.11: Push Switches for Hour and Minutes Adjustment 39

    Figure 5.12: Digital Clock Display 21:50 39

  • 8/10/2019 LED Display by 8051

    7/56

  • 8/10/2019 LED Display by 8051

    8/56

    ENG499 CAPSTONE PROJECT REPORT 8

    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 1Background Information research

    Phase 2Preparation of initial reportTMA01

    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 5Program microcontroller to display real-time clock on LED matrix display

    Phase 6Project review

    Phase 7Preparation of final report

    Phase 8Preparation 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.

  • 8/10/2019 LED Display by 8051

    9/56

    ENG499 CAPSTONE PROJECT REPORT 9

    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

  • 8/10/2019 LED Display by 8051

    10/56

    ENG499 CAPSTONE PROJECT REPORT 10

    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.

    http://en.wikipedia.org/wiki/Projecthttp://en.wikipedia.org/wiki/Project
  • 8/10/2019 LED Display by 8051

    11/56

    ENG499 CAPSTONE PROJECT REPORT 11

    Figure 1.1: Project Gantt Chart

    eek

    1

    2

    3

    4

    5

    6

    7

    8

    910

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    3435

    36

    37

    38

    39

    40

    41

    42

    43

    4

    rjct

    ss

    Plan

    Actual

    6.

    ProjectReview

    7.

    PreparationofFinalReport

    8.

    PreparationofPosterandOralPresentation

    evsonee

    ExaminationWeek

    4.

    ImplementationofprototypeconsistingofLED

    display

    odulesand

    icrocontroller

    4.1Finalizeonprototypedesign

    4.2Implementprototype

    5.

    Programm

    icrocontrollertodisplayreal-timeclockon

    LE

    trix

    isly

    5.1MicrocontrollerprogrammingusingCcomp

    lier

    1.1UnderstandingProjectdefinition

    1.2ResearchonProjectBackground

    2.

    ProjectInitialReport

    3.

    ResearchonLEDmatrixdisplay,8051Microcont

    rollerand

    fin

    alizesplanonprototypingdesign

    3.1LEDmatrixdisplay

    3.28051Microcontroller

    ec-

    1.

    LiteratureReview

    Feb-

    ar-

    p

    r-

    ay-

    Jun-

    Jul-

    u-

    Sep-

    ct-

    ov-

    Gantt

    Chartclearlyshows

    delay

    inTask4.

    Additiontimewasspenton

    protot

    ypetroubleshooting,

  • 8/10/2019 LED Display by 8051

    12/56

    ENG499 CAPSTONE PROJECT REPORT 12

    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.

  • 8/10/2019 LED Display by 8051

    13/56

    ENG499 CAPSTONE PROJECT REPORT 13

    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.

  • 8/10/2019 LED Display by 8051

    14/56

    ENG499 CAPSTONE PROJECT REPORT 14

    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.

  • 8/10/2019 LED Display by 8051

    15/56

    ENG499 CAPSTONE PROJECT REPORT 15

    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

  • 8/10/2019 LED Display by 8051

    16/56

    ENG499 CAPSTONE PROJECT REPORT 16

    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.

  • 8/10/2019 LED Display by 8051

    17/56

    ENG499 CAPSTONE PROJECT REPORT 17

    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 non-

    volatile memory programmer. For the aforementioned reasons, AT89S52 is chosen

    as the controller of the entire system for the present application.

  • 8/10/2019 LED Display by 8051

    18/56

    ENG499 CAPSTONE PROJECT REPORT 18

    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.

    DS1307 RealTime Clock

    AT89S52 LED Matrix

    Display

    Column ScanningCircuit

    Row Scanning

    Circuit

  • 8/10/2019 LED Display by 8051

    19/56

  • 8/10/2019 LED Display by 8051

    20/56

    ENG499 CAPSTONE PROJECT REPORT 20

    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.

  • 8/10/2019 LED Display by 8051

    21/56

    ENG499 CAPSTONE PROJECT REPORT 21

    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.

  • 8/10/2019 LED Display by 8051

    22/56

    ENG499 CAPSTONE PROJECT REPORT 22

    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

  • 8/10/2019 LED Display by 8051

    23/56

    ENG499 CAPSTONE PROJECT REPORT 23

    7805 is equipped with built-in protection circuitry against overheating and short-

    circuits, 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

  • 8/10/2019 LED Display by 8051

    24/56

    ENG499 CAPSTONE PROJECT REPORT 24

    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

  • 8/10/2019 LED Display by 8051

    25/56

    ENG499 CAPSTONE PROJECT REPORT 25

    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.

    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.

    Initialize Serial

    Start

    Setup Interrupts

    Display Time

    Read DS1307

    Infinite Loop

  • 8/10/2019 LED Display by 8051

    26/56

    ENG499 CAPSTONE PROJECT REPORT 26

    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 0 1 1 1 0

    R2 1 0 0 0 1R3 1 0 0 1 1

    R4 1 0 1 0 1

    R5 1 1 0 0 1

    R6 1 0 0 0 1

    R7 0 1 1 1 0

    R8 0 0 0 0 0

    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 de-

    asserted. 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.

    unsignedcharcode number[15][5] = {

    0x3E, 0x51, 0x49, 0x45, 0x3E, // 0

    0x44, 0x42, 0x7F, 0x40, 0x40, // 1

    0x42, 0x61, 0x51, 0x49, 0x46, // 20x22, 0x41, 0x49, 0x49, 0x36, // 3

    0x18, 0x14, 0x12, 0x7F, 0x10, // 4

    0x27, 0x45, 0x45, 0x45, 0x39, // 5

    0x3E, 0x49, 0x49, 0x49, 0x32, // 6

    0x01, 0x71, 0x09, 0x05, 0x03, // 7

    0x36, 0x49, 0x49, 0x49, 0x36, // 8

    0x26, 0x49, 0x49, 0x49, 0x3E, // 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.

  • 8/10/2019 LED Display by 8051

    27/56

    ENG499 CAPSTONE PROJECT REPORT 27

    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

    //---------------------------------------

    voidInitSerial(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 = P1^1; // connect to SDA pin (Data)

    sbit SCL = P1^0; // 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.

  • 8/10/2019 LED Display by 8051

    28/56

    ENG499 CAPSTONE PROJECT REPORT 28

    //-------------------------------

    // start I2C

    //-------------------------------

    voidStart(void)

    {

    SDA = 1;

    SCL = 1;

    _nop_();_nop_();SDA = 0;

    _nop_();_nop_();

    SCL = 0;

    _nop_();_nop_();

    }

    //-------------------------------

    // stop I2C

    //-------------------------------

    voidStop(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)//-------------------------------

    voidReadRTC(unsignedchar* buff)

    {

    Start();

    WriteI2C(0xD0);

    WriteI2C(0x00);

    Start();

    WriteI2C(0xD1);

    *(buff+0)=ReadI2C(ACK); // Second

    *(buff+1)=ReadI2C(ACK); // Minute

    *(buff+2)=ReadI2C(ACK); // hour

    *(buff+3)=ReadI2C(ACK); // Day

    *(buff+4)=ReadI2C(ACK); // date

    *(buff+5)=ReadI2C(ACK); // month

    *(buff+6)=ReadI2C(NO_ACK); // year

    Stop();

    }

    //-------------------------------

    // Write RTC

    //-------------------------------

    voidWriteRTC(unsignedchar*buff){

  • 8/10/2019 LED Display by 8051

    29/56

    ENG499 CAPSTONE PROJECT REPORT 29

    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.

    voidEXO_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]);

    }

    elseif((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);

    }

  • 8/10/2019 LED Display by 8051

    30/56

    ENG499 CAPSTONE PROJECT REPORT 30

    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.

    voidEX1_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]);

    }

    elseif((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

    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.

  • 8/10/2019 LED Display by 8051

    31/56

    ENG499 CAPSTONE PROJECT REPORT 31

    unsignedcharcode number[15][5] = {

    0x3E, 0x51, 0x49, 0x45, 0x3E, // 0

    0x44, 0x42, 0x7F, 0x40, 0x40, // 1

    0x42, 0x61, 0x51, 0x49, 0x46, // 2

    0x22, 0x41, 0x49, 0x49, 0x36, // 3

    0x18, 0x14, 0x12, 0x7F, 0x10, // 4

    0x27, 0x45, 0x45, 0x45, 0x39, // 5

    0x3E, 0x49, 0x49, 0x49, 0x32, // 6

    0x01, 0x71, 0x09, 0x05, 0x03, // 7

    0x36, 0x49, 0x49, 0x49, 0x36, // 8

    0x26, 0x49, 0x49, 0x49, 0x3E, // 9

    0x00, 0x00, 0x00, 0x00, 0x00};

    unsignedcharcode 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};

    unsignedcharRTC_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()

    {

    unsignedcharx,y,m1,m2,h1,h2,blink;

    InitSerial(); // Initialize serial port

    setup_interrupts (); // Setup of interrupts

    for(x=0;x>4; // Get the tens digit for hour

    h2=RTC_ARR[2]&0x0f; // Get the ones digit for hour

    m1=RTC_ARR[1]>>4; // Get the tens digit for minutes

    m2=RTC_ARR[1]&0x0f; // Get the ones digit for minutes

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

    P1_2=0;

  • 8/10/2019 LED Display by 8051

    32/56

    ENG499 CAPSTONE PROJECT REPORT 32

    P1_3=0;

    // Display the hour

    digit(x,2,h1);

    digit(x,8,h2);

    // Display the colon

    if(blink

  • 8/10/2019 LED Display by 8051

    33/56

    ENG499 CAPSTONE PROJECT REPORT 33

    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

  • 8/10/2019 LED Display by 8051

    34/56

    ENG499 CAPSTONE PROJECT REPORT 34

    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

  • 8/10/2019 LED Display by 8051

    35/56

    ENG499 CAPSTONE PROJECT REPORT 35

    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

  • 8/10/2019 LED Display by 8051

    36/56

    ENG499 CAPSTONE PROJECT REPORT 36

    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.

  • 8/10/2019 LED Display by 8051

    37/56

    ENG499 CAPSTONE PROJECT REPORT 37

    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.

  • 8/10/2019 LED Display by 8051

    38/56

    ENG499 CAPSTONE PROJECT REPORT 38

    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

  • 8/10/2019 LED Display by 8051

    39/56

    ENG499 CAPSTONE PROJECT REPORT 39

    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.

    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.

    Hour Minutes

  • 8/10/2019 LED Display by 8051

    40/56

    ENG499 CAPSTONE PROJECT REPORT 40

    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 isdeveloped 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.

  • 8/10/2019 LED Display by 8051

    41/56

    ENG499 CAPSTONE PROJECT REPORT 41

    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 andunleash 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.

  • 8/10/2019 LED Display by 8051

    42/56

    ENG499 CAPSTONE PROJECT REPORT 42

    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.

  • 8/10/2019 LED Display by 8051

    43/56

    ENG499 CAPSTONE PROJECT REPORT 43

    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,

    http://en.wikipedia.org/wiki/Light-emitting_diodehttp://en.wikipedia.org/wiki/Light-emitting_diodehttp://www.maxim-ic.com/app-notes/index.mvp/id/1033http://www.maxim-ic.com/app-notes/index.mvp/id/1033http://www.howstuffworks.com/led.htmhttp://www.howstuffworks.com/led.htmhttp://www.jbprojects.net/projects/led/http://www.jbprojects.net/projects/led/http://www.howstuffworks.com/led.htmhttp://www.maxim-ic.com/app-notes/index.mvp/id/1033http://en.wikipedia.org/wiki/Light-emitting_diode
  • 8/10/2019 LED Display by 8051

    44/56

    ENG499 CAPSTONE PROJECT REPORT 44

    Appendixes

    Appendix AProgram Source Code

    Appendix A1: Serial Initialization

    //---------------------------------------

    // Serial port driver// KEIL C51 v7.5

    //---------------------------------------

    #include

    //---------------------------------------

    // Initialize serial port

    //---------------------------------------

    voidInitSerial(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

    #include

    #defineACK 1

    #defineNO_ACK 0

    #defineSLAVE 0xD0

    #defineWRITE 0x00

    #defineREAD 0x01

    #defineERR_ACK 0x01

    unsignedchari;

    constunsignedchar* DayStr[7] = {{"Sun"},

    {"Mon"},

    {"Tue"},{"Wen"},

    {"The"},

    {"Fri"},

    {"Sat"}};

    constunsignedchar* MonthStr[12] ={{"Jan"},

    {"Feb"},

    {"Mar"},

    {"Apr"},

    {"May"},

    {"Jun"},

    {"Jul"},

    {"Aug"},

    {"Sep"},

  • 8/10/2019 LED Display by 8051

    45/56

  • 8/10/2019 LED Display by 8051

    46/56

    ENG499 CAPSTONE PROJECT REPORT 46

    }

    //-------------------------------

    // Read I2C

    //-------------------------------

    unsignedcharReadI2C(bit ACK_Bit)

    {

    unsignedcharData=0;

    SDA = 1;

    for(i=0;i

  • 8/10/2019 LED Display by 8051

    47/56

    ENG499 CAPSTONE PROJECT REPORT 47

    // Read RTC (all real time)

    //-------------------------------

    voidReadRTC(unsignedchar* buff)

    {

    Start();

    WriteI2C(0xD0);

    WriteI2C(0x00);

    Start();

    WriteI2C(0xD1);

    *(buff+0)=ReadI2C(ACK); // Second

    *(buff+1)=ReadI2C(ACK); // Minute

    *(buff+2)=ReadI2C(ACK); // hour

    *(buff+3)=ReadI2C(ACK); // Day

    *(buff+4)=ReadI2C(ACK); // date

    *(buff+5)=ReadI2C(ACK); // month

    *(buff+6)=ReadI2C(NO_ACK); // year

    Stop();

    }

    //-------------------------------// Write RTC

    //-------------------------------

    voidWriteRTC(unsignedchar*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(unsignedcharday){

    returnDayStr[day-1];

    }

    //-------------------------------

    // Convert month (BCD) to string of Month

    // 0x01=January

    // 0x02=February

    // ...........

    // 0x12 = December

    // And so on

    //-------------------------------

    char* Int2Month(unsignedcharmonth){

    returnMonthStr[BCD2HEX(month)-1];

  • 8/10/2019 LED Display by 8051

    48/56

    ENG499 CAPSTONE PROJECT REPORT 48

    }

    Appendix A3: AT89S52 Main

    //---------------------------------------

    // AT89s52 Main

    // KEIL C51 v7.5

    //---------------------------------------

    #include

    #include#include

    #include

    #include

    unsignedcharcode number[15][5] = {

    0x3E, 0x51, 0x49, 0x45, 0x3E, // 0

    0x44, 0x42, 0x7F, 0x40, 0x40, // 1

    0x42, 0x61, 0x51, 0x49, 0x46, // 2

    0x22, 0x41, 0x49, 0x49, 0x36, // 3

    0x18, 0x14, 0x12, 0x7F, 0x10, // 4

    0x27, 0x45, 0x45, 0x45, 0x39, // 5

    0x3E, 0x49, 0x49, 0x49, 0x32, // 6

    0x01, 0x71, 0x09, 0x05, 0x03, // 70x36, 0x49, 0x49, 0x49, 0x36, // 8

    0x26, 0x49, 0x49, 0x49, 0x3E, // 9

    0x00, 0x00, 0x00, 0x00, 0x36, // dot1

    0x36, 0x00, 0x00, 0x00, 0x00, // dot2

    0x55, 0xAA, 0x55, 0xAA, 0x55, // checker

    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // all on

    0x00, 0x00, 0x00, 0x00, 0x00};

    unsignedcharcode 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};

    unsignedcharRTC_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

    }

    voiddelayms(unsignedintcount) // Delay Function

    {unsignedinti;

    while(count)

    {

    i = 120;

    while(i>0)

    i--;

    count--;

    }

    }

    voidEXO_int0 (void) interrupt 0 // Interrupt Routine for Hour Increment

    {ReadRTC(&RTC_ARR[0]);

  • 8/10/2019 LED Display by 8051

    49/56

    ENG499 CAPSTONE PROJECT REPORT 49

    if(RTC_ARR[2] > 0x22)

    {

    RTC_ARR[2] = 0x00;

    WriteRTC(&RTC_ARR[0]);

    }

    elseif((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);

    }

    voidEX1_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]);

    }

    elseif((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);

    }

    voiddigit(intx,y,z) // Function to display the character at specific location of

    screen

    {

    for(x=0;x

  • 8/10/2019 LED Display by 8051

    50/56

    ENG499 CAPSTONE PROJECT REPORT 50

    {

    P0=dis_y[y];

    P2=0x36;

    y++;

    delayms(1);

    }

    P1_2=1;

    P1_3=0;

    y=0;

    for(x=0;x0)

    {

    P1_2=0;

    P1_3=0;

    y=0;

    for(y=0;y

  • 8/10/2019 LED Display by 8051

    51/56

    ENG499 CAPSTONE PROJECT REPORT 51

    {

    P1_2=0;

    P1_3=0;

    y=0;

    for(y=0;y

  • 8/10/2019 LED Display by 8051

    52/56

    ENG499 CAPSTONE PROJECT REPORT 52

    main()

    {

    unsignedcharx,y,m1,m2,h1,h2,blink;

    InitSerial(); // Initialize serial port

    setup_interrupts (); // Setup of interrupts

    for(x=0;x>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 colonif(blink

  • 8/10/2019 LED Display by 8051

    53/56

    ENG499 CAPSTONE PROJECT REPORT 53

    P1_3=0;

    // Update the minutes

    digit(x,3,m1);

    digit(x,9,m2);

    }

    }

  • 8/10/2019 LED Display by 8051

    54/56

    ENG499 CAPSTONE PROJECT REPORT 54

    Appendix B: Schematic Diagrams

    Appendix B1: Schematic for LED Matrix Display

    Appendix B2: Schematic for ISP Program

  • 8/10/2019 LED Display by 8051

    55/56

    ENG499 CAPSTONE PROJECT REPORT 55

    Appendix B3: Schematic for 5V Supply

  • 8/10/2019 LED Display by 8051

    56/56

    Appendix C: Dot Matrix Characters