mae576 groupd lab1 report

Upload: mail2priyanshu8428

Post on 30-May-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 MAE576 GroupD LAB1 Report

    1/47

  • 8/9/2019 MAE576 GroupD LAB1 Report

    2/47

    Abstract

    The major goal of this lab assignment was to develop a digital stop watch. The basic interfacing of LCD

    module, MAX7219 7-Segment display driver, speaker, shift register for capturing inputs using switches

    and pulse generator is first achieved. The successful implementation of the stop watch is possible with

    synergistic integration of the components in the system. A digital stop watch is developed which

    operates in two modes i.e. normal stop watch mode and timer mode. The timer mode provides the user

    an option to enter hours, minutes and seconds after which the watch should give a buzzer. Both the

    modes provide option to pause or continue and stop the watch. In addition, the watch also has the feature

    of Auto Sleep Mode which kicks in when the watch is idle for some time. The user can also turn this

    mode off. Also, the watch provides audio visual cues to the user for user friendliness.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    3/47

    Contents

    AbstractContents

    1.Introduction1.1 Design Objective1.2 Features of Digital Stop Watch1.3 User Operation Instructions

    2. Hardware2.1 List of Components2.2 Hardware Description

    2.3 Microcontroller (Basic Stamp 2) Pin Assignment2.4 Circuit Diagrams3. Software4. Mathematical Methods5. Implementation

    5.1 Software Algorithms5.1.1 System Flowchart

    5.1.2 Normal Mode (D0) Flowchart5.1.3 Timer Mode (D1) Flowchart5.1.4 Show Time Flowchart5.1.5 Start Timer Flowchart5.1.6 Sleep Mode Option Flowchart5.1.7 Pause Watch Option Flowchart

    5.2 Subroutines6. Testing Procedure

    7. Discussion8. ConclusionBibliographyAppendix

  • 8/9/2019 MAE576 GroupD LAB1 Report

    4/47

    A. PBASIC Code for Digital StopwatchB. Data SheetsB.1 MAX7219, Serially Interfaced, 8digit LED Driver Display

    B.2 74HC165, 8bit parallelin/serial out shift registerB.3 HD44780U (LCDII) Dot Matrix Liquid Crystal Display Controller /Driver

  • 8/9/2019 MAE576 GroupD LAB1 Report

    5/47

    1. Introduction

    A microcontroller (also microcomputer, MCU or C) is a small computer on a single integrated circuit

    consisting internally of a relatively simple CPU, clock, timers, I/O ports, and memory [1]. Program

    memory in the form of flash or ROM is also often included on chip, as well as a typically small amountof RAM. Microcontrollers are designed for small or dedicated applications. The microcontroller used in

    this lab assignment is BASIC Stamp II. The BASIC Stamp is a microcontroller with a small, specializedBASIC interpreter (PBASIC) built into ROM. It is made by Parallax, Inc. and has been popular withelectronics hobbyists since the early 1990s due to its low threshold of learning and ease of use (due to its

    simple BASIC language).

    In this assignment interfacing of the microcontroller with few electronic components like 7-Segment

    display using MAX7219 display driver, LCD, speaker, switches using shift register and pulse generator

    is achieved. It was decided that the developed system should be such that the above mentioned

    components should work as an integrated system. Also earlier discussions laid the foundations for thevarious features that the system should provide to the user. It was decided that not only should the

    developed stop watch provide the user with an option of a normal stop watch but it should also have

    some feature to set up a timer, a system typically provided in mobile phones as a countdown timer.Further, it was decided that system should try to reproduce as many features as possible of a typical stop

    watch available in mobile phones. Inspired from the options provided by Nokia 6070, it was also

    decided to provide the option for laps in our stop watch. Also, it was decided the watch should providevarious audio visual cues to be user-friendly.

    1.1 Design ObjectiveThe following are the design objectives for the developed digital stop watch:

    (i) It should display the time elapsed in hours, minutes and seconds.

    (ii) It should also provide a facility to set up a timer.(iii) It should have the feature of laps.

    (iv) It should, if possible, have power saving techniques.

    (v) It should be user friendly.

    1.2 Features of Digital Stop Watch

    This section describes the various features of the digital stop watch developed.

    1. Modes of Operation In order to serve multiple purposes the watch has the following two modes ofoperation:

    (i)Normal Mode This is the normal mode of stop watch with which all of us are familiar. In this

    mode the system displays the time elapsed in hours, minutes and seconds along with the current lapand the mode selected.

    Normal Mode (D0) Timer Mode (D1)

  • 8/9/2019 MAE576 GroupD LAB1 Report

    6/47

    (ii) Timer Mode This is the timer mode which can be used to set up a timer based on the timeelapsed. Once the set time has passed the timer will stop and the watch will produce a ringing

    sound stating that the set time is over. The mode also provides the user to manually enter the time

    in hours, minutes and seconds after which the watch should ring.

    2. User Input The system is based on the input provided by the user. It seeks input from the userusing a set of 8 switches with different roles assigned to each switch based on the current state ofthe operation of the watch. The following inputs are acquired in different scenarios:

    (i) At the beginning the switches D0 and D1 are used to choose the mode to be selected.(ii) The switch D7 also provides the option to turn on/off the auto sleep mode.(iii) In case one of the modes is selected, the switches D2/D3/D4/D5 acts as Pause/Continue /Stop/Next

    Lap buttons.

    (iv) Also in Timer mode the switches D0-D1 convert into digits 0-6 providing the user the flexibility toenter timer time.

    Select Mode Screen Sleep Mode Selection Screen

    3. Laps The stop watch also provides a feature to divide the time into two laps. The current lap can beassessed both from the LCD and the blinking LEDs.

    Watch running in II Lap

    4. Auto Sleep Mode In order to save power which is always the case in standalone applications, thesystem implements the feature of auto sleep mode. When no key is pressed in idle or paused

    condition the system automatically turns off both the 7-segment display and the LCD in order to

    saver power. However, the state of both the components is retained. The system also provides thefeature of turning this mode off. By default the auto sleep mode is set to on.

    5. Audio Visual Cues In order to be user-friendly the watch has the following features to guide theuser:

    (i) Blinking message signifying that user input is required.

    (ii) Visual status for each lap with blink on each passing counted second.(iii) Invalid input feedback with message and beep when wrong key is pressed.

    (iv) Tick sound with each counted second.

    (v) LED blinking with each passing second.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    7/47

    PICK Message on 7-Segment Display Run Message signifying that the watch is running

    1.3 User Operation Instructions

    The following are the instructions for the user to operate the developed Digital Stop Watch:

    1. The clock starts with a welcome message on the LCD and a greeting on the 7-Segment Display.

    2. It will provide the user a visual cue on the 7-Segment display with a PICK message blinking on it.

    On the LCD it will display a message asking the user to pick one of the two modes available in the

    watch. The user is expected to press D0/D1/D7 button provided on the board. In case any other button is

    pressed it will provide a feedback to the user with a sound, a ---- display on the 7-Segment andInvalid Input! on the LCD.

    3. When the user presses the D0 button, the watch starts in Normal mode and the seconds tic will start.The lap LED will also start blinking. The 7-Segment display will show Run to signify that the watchis running. The mode will also be displayed on the LCD.

    4. While the watch is running the user can press Pause (D2) /Stop (D4) button to pause or stop the

    watch.

    5. When Pause (D2) is pressed the watch stops and the lap LED also glows steadily corresponding to the

    lap. The 7-Segment display will also show a message HALT on it.

    6. In order to resume, the user should press Continue (D3) button. Once the watch starts running again

    the 7-Segment display will again show the message Run.

    7. In case the user wants to split the time to another lap, the user can press Lap (D5) button. The watch

    supports 2 laps. The lap led corresponding to the current lap will now start blinking.

    8. In order to stop the watch the user should press Stop (D4) button. The 7-Segment display also shows

    the message Stop for a short while when this button is pressed. The watch is now reset to its select

    mode state.

    9. When the user presses the D1 button, the Timer mode is selected. In this mode the user is required to

    input the number of hours, minutes and seconds one by one. When the time corresponding to the settime has elapsed the watch will stop and give a ring sound.

    10. Once the user enters the required hours, minutes and seconds the watch starts ticking. The optionsfor Pause/ Continue, Stop and Lap are valid in this mode as well.

    11. In addition to the above modes the watch is by default set to the sleep mode which will be invoked if

    the watch is idle for around 15 seconds. In which case both the 7-Segment display and the LCD is turned

  • 8/9/2019 MAE576 GroupD LAB1 Report

    8/47

    off with their status still retained in the memory. The sleep mode kicks in when the watch is either idle

    with no mode selected or the watch is paused.

    12. The watch also provides the user an option to turn off the Auto Sleep Mode. This can be done by

    pressing the D7 button when the watch is not running in either of the two modes. The user is required topress D0 for setting off the Auto Sleep mode and D1 for turning on of the Auto Sleep mode.

    13. The watch also has an LED that glows with each passing second irrespective of the fact whether thewatch is running or not.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    9/47

    3. Hardware

    The following sections deals with the details of the hardware used to implement the digital stop watch.

    3.1 List of Components

    S. No. Component Quantity1. BASIC Stamp Kit NX-1000 1

    2. BASIC Stamp Module II 1

    3. Hitachi LCD Module , HD44780 14. MAX 7219 Display Driver 1

    5. 74HC165 Shift Register 1

    6. Piezo Speaker 1

    7. 7-Segment LED Display 4

    8. Pulse Generator 1

    9. LED 3

    10. Switch 8

    11. 10K Resistor 212. 5K Resistor 1

    3.2 Hardware Description

    Basic Stamp Kit INEX-1000

    http://www.mouser.com/catalog/supplier/library/ParallaxMiniCatalog.pdf

    1. INEX-1000 is a high-quality prototype and experiment area for all 24-pin BASIC Stamp modules2. Audio amplifiers with screw terminals for 8 ohm speakers. an audio amplifier for external speakers and current limit

    resistors sized for driving more LEDs. 510 ohm resistors allow more LED driving.

    3. Board provides socket ports for each BASIC Stamp I/O pin.4. A parallel LCD with cable.5. 16 LEDs to monitor I/O pin status.6. DB-9 connector for program download and debugging.7. 4-digit LED 7-segment display with common cathode.8. 8 pushbutton switches (active low without pull-up resistors) 8 DIP switches (with built-in pull-up resistors)9. ULN2003 high-current driver for relay and stepper motors10. Pulse generator for 1Hz, 10 Hz, 100 Hz, and 1 kHz

  • 8/9/2019 MAE576 GroupD LAB1 Report

    10/47

    11. RS-232 interface port for communication with COM program12. Socket for 24-pin BASIC Stamp modules13. Parallel LCD module with connector and brightness control14. Piezospeaker15. 10K potentiometer16. 2.5" x 7" breadboard with 800 contact points17. 7.5V DC 1 amp power supply with polarity protectionSource: http://www.apexvalue.com/basic_stamp/product_id_28135.htm

    Basic Stamp II Module

    ontroller C57 C signifies EPROM program memory

    sor Speed peration Frequency 20 MHz

    m Execution Speed PBASIC instructions/sec

    t Draw @ 5 VDC un, 50 A Sleep

    e DIPrce / Sink Current by any I/O pin 25mA

    M (Program) Size: 2 Kbytes BASIC instructions

    Size: es (6 for I/0, 26 for Variable)

    Hitachi LCD Module, HD44780

    http://www.nipahut.com.ph

    16 x 2 Alphanumeric characters

    4-bit or 8-bit MPU interface enabled

  • 8/9/2019 MAE576 GroupD LAB1 Report

    11/47

    t

    I

    AX 7219

    he MAX 7

    o seven segegment an

    t has the fol 10MHz

    Individu Decode/ 150A

    Digital a

    Display

    Drive C 24-Pin D

    his is an Lbar graph

    4HC165 S

    his shift re

    icrocontroascaded usi

    iezo Speak

    -Segment

    isplay Dri

    19 are com

    ent numerdigit drive

    lowing feat

    erial Interfl LED Seg

    o-Decode

    ow-Powerd Analog

    lanked on

    mmon-Cat

    IP and SO

    D driver thisplay or u

    ift Registe

    ister allow

    ler pins. Eang the same

    er

    isplay

    ver

    pact, serial i

    c displays.s and a 8X8

    res:

    ceent Contro

    igit Selecti

    hutdown (rightness C

    ower-Up

    ode LED D

    ackages

    at requires jto 64 indiv

    a microcon

    h 74HC165set of micr

    nput/output

    he chip costatic RA

    l, can control

    on

    ata Retaineontrol

    isplay

    st three miidual LEDs.

    www.se

    troller to re

    provides 8controller p

    http://ww

    cathode dis

    tains a BC. It also all

    up to 64 indi

    d)

    rocontrolle

    eedstudio.c

    d a large n

    input pins.ins. It has s

    .hvwtech.c

    play drivers

    code-B dews driving

    ividual LEDs,

    pins to co

    m

    mber of dig

    ny numbenchronous

    m

    that interfa

    coder, multiindividual d

    or eight 7-se

    trol up to 8

    ital inputs u

    of 74HC16serial input.

    e micropro

    plex scan ciigits of a dis

    gment LED

    7-segment

    sing just thr

    5 chips can

    essors

    rcuitry.play.

    igits

    igits or

    ee

    be

  • 8/9/2019 MAE576 GroupD LAB1 Report

    12/47

    3.3 Microcontroller (BASIC Stamp 2) Pin Assignment

    Pin No. I/O Description0 Output LCD Enable Pin

    1 Output Piezo Speaker

    2 Output Lap 1 LED

    3 Output LCD Register Select Pin

    4 Output LCD Data Pin

    5 Output LCD Data Pin

    6 Output LCD Data Pin

    7 Output LCD Data Pin

    8 Output Shift Register 74X165 Clock Pin

    9 Input Shift Register 74X165 Data In Pin

    10 Output Shift Register 74X165 Load Pin

    11 Output 7-Segment Display Driver MAX7219 Load Pin

    12 Output 7-Segment Display Driver MAX7219 Clock Pin

    13 Output 7-Segment Display Driver MAX7219 Data Pin

    14 Output Lap 2 LED15 Input Pulse Generator

    The pin directions as defined in PBASIC code is as follows:DIRL = %11111111

    DIRH = %01111101

    3.3 Circuit Diagrams

    HD44780 LCD Module Interface Circuit

    P0, P3, P4, P5, P6, P7 are the inputs from microcontroller.

    P4-P7 are data pins

  • 8/9/2019 MAE576 GroupD LAB1 Report

    13/47

    P0 is used to enable the LCD module while P3 selects the LCD register to be used.

    R/W is grounded since only data is written on the LCD.

    Piezo Speaker Interface Circuit

    P1 acts as output port driving an Piezo Speaker for alerts

    Lap LEDs Interface Circuit

    P2 and P4 are outputs from the microcontroller which drives two LEDs ( Lap 1 and Lap 2).

    Shift Register 74HC165 Interface Circuit

    +5+5

    Vss

    P8

    P9

    P10

    2

    7

    1

    11

    12

    13

    14

    3

    4

    5

    6

    8 15

    16

    D0

    D1

    D2

    D3

    D4

    D5

    D6

    D7

    ShiftRegister74HC165

    10K

  • 8/9/2019 MAE576 GroupD LAB1 Report

    14/47

    P8: Clock Pin input to 74X165P9: Data In from the display driver

    P10: Load pin input

    D0-D7 takes inputs from the corresponding switches (Miniature Single Pole Single Throw Switches)connected.

    10K resistors are pull-up resistors

    MAX7219 LED display driver CircuitThe LED display driver uses just three microcontroller pins P11 (Load), P12 (Clock) and P13 (Data) to

    control up to four 7-segment digits (max eight seven segment digits can be controlled)

  • 8/9/2019 MAE576 GroupD LAB1 Report

    15/47

    4. Software

    The following section presents a basic overview of the important commands used while implementing

    the system.

    The PBASIC version 2.0 is used to program the BASIC Stamp II module [2]. The following commands

    are used to program the module:

    1. DATA Write user data to the EEPROM location(s) during program download.Syntax: {Symbol}DATA {@Address,} {Word}DataItem {, DataItem ...}

    2. GOSUB Store the address of the next instruction after GOSUB, then go to the point in theprogram specified byAddress; with the intention of returning to the stored address.Syntax: GOSUBAddress

    3. HIGH/ LOW Make the specified pin an output and high/low.Syntax: HIGH/LOWPin

    4. FOR.NEXT Create a repeating loop that executes the program lines between FOR and NEXT,incrementing or decrementing Counter according to StepValue until the value of the Countervariable passes theEndValue.Syntax: FORCounter = StartValueTOEndValue {STEP StepValue} ... NEXT

    5. IFTHEN Evaluate Condition and, if it is true, go to the point in the program marked byAddress.Syntax: IFConditionTHENAddress

    6. LOOKUP Find the value at location Index and store it in Variable. IfIndex exceeds the highestindex value of the items in the list, Variable is left unaffected.

    Syntax: LOOKUPIndex, [Value0, Value1, ...ValueN], Variable

    7. LOOKDOWN - Compare Targetvalue to a list of values and store the index number of the firstvalue that matches into Variable. If no value in the list matches, Variable is left unaffected.

    Syntax: LOOKDOWNTarget, {ComparisonOp} [Value0, Value1, ...ValueN], Variable

    8. SHIFTIN Shift data in from a synchronous serial device. The SHIFTIN instruction first causes theclock pin to output low and the data pin to switch to input mode. Then, SHIFTIN either reads thedata pin and generates a clock pulse (PRE mode) or generates a clock pulse then reads the data pin

    (POST mode). SHIFTIN continues to generate clock pulses and read the data pin for as many data

    bits as are required.

    Syntax: SHIFTINDpin, Cpin, Mode, [Variable {\Bits} {, Variable {\Bits}...}]

    9. SHIFTOUT Shift data out to a synchronous serial device. The SHIFTOUT instruction firstcauses the clock pin to output low and the data pin to switch to output mode. Then,SHIFTOUT sets the data pin to the next bit state to be output and generates a clock pulse.

    SHIFTOUT continues to generate clock pulses and places the next data bit on the data pin for

    as many data bits as are required for transmission.Syntax: SHIFTOUTDpin, Cpin, Mode, [OutputData {\Bits} {,OutputData {\Bits}...}]

    10.PULSOUT Generate a pulse on Pin with a width ofDuration.Syntax: PULSOUTPin, Duration

  • 8/9/2019 MAE576 GroupD LAB1 Report

    16/47

    11.PAUSE Pause the program (do nothing) for the specified Duration.Syntax: PAUSEDuration

    12.GOTO Jump the point in the program specified by Address.Syntax: GOTOAddress

    13.FREQOUT Generate one or two sine-wave tones for a specified duration.Syntax: FREQOUTPin, Duration, Freq1 {, Freq2}

    14.READ - Read value atLocation in EEPROM and store the result in result in Variable.Syntax: READLocation, {Word} Variable {, {Word} Variable, ...}

    15.RETURN Return from a subroutine, assuming there was a previous GOSUB or ON...GOSUBexecuted.

    Syntax: RETURN

  • 8/9/2019 MAE576 GroupD LAB1 Report

    17/47

    5. Mathematical Methods

    The digital Stopwatch is based on the pulse generated by the pulse generator. The pulse generator sends

    a pulse at 1 Hz (1 pulse per sec) which acts a basis for counting seconds in the BASIC Stamp Module.

    With every pulse a counter is incremented in the module which tracks the number of seconds passed.Now, this counter is used to calculate the hours, minutes and seconds elapsed. The following section

    presents a description of the methodology used to calculate hours, minutes and seconds to be displayed

    on the LCD module.

    1. Calculation of Display hours

    3600

    where, represents the floor function. The BASIC stamp module by default implements the floorfunction in all its calculation.

    The digits from the above calculated number of hours are now extracted using the following:

    10

    10 x 10

    2. Calculation of Display minutes

    60

    The digits from the above calculated number of minutes are now extracted using the following:

    10

    10 x 10

    3. Calculation of Display seconds

    60 x 60

    The digits from the above calculated number of minutes are now extracted using the following:

    10

    10 x 10

  • 8/9/2019 MAE576 GroupD LAB1 Report

    18/47

    6. Implementation

    The following section details the algorithms used along with the various subroutines used to implement

    them.

    The following figure shows the final setup of the system implemented using NX-1000 Experiment

    Board.

    6.1 AlgorithmsThe following section presents the various algorithms used to implement different modes in the system.

    The different algorithms used are as follows:

    1. System Flowchart2. Normal Mode (D0) Flowchart3. Timer Mode (D1) Flowchart4. Show Time Flowchart5. Start Timer Flowchart6. Sleep Mode Option Flowchart7. Pause Watch Option Flowchart

  • 8/9/2019 MAE576 GroupD LAB1 Report

    19/47

    6.1.1 System Flowchart

  • 8/9/2019 MAE576 GroupD LAB1 Report

    20/47

    6.1.2 Normal Mode (D0) Flowchart

  • 8/9/2019 MAE576 GroupD LAB1 Report

    21/47

    6.1.3 Timer Mode (D1) Flowchart

  • 8/9/2019 MAE576 GroupD LAB1 Report

    22/47

    6.1.4 Show Time Flowchart

    6.1.5 Start Timer Flowchart

  • 8/9/2019 MAE576 GroupD LAB1 Report

    23/47

    6.1.6 Sleep Mode Option Flowchart

    6.1.7 Pause Watch Option Flowchart

  • 8/9/2019 MAE576 GroupD LAB1 Report

    24/47

    6.2 SubroutinesIn order to achieve efficiency the code is subdivided into subroutines so as to have an ability to executethe same piece of code as and when required. The subroutines used in the program can be categorized in

    the following major categories:

    1. Initialization Subroutines The following subroutines are used for initialization of variables anddisplay messages in different modes:

    (i) LCD Initialization Initializes the LCD for display.(ii) Normal Mode Initialization Initialize variables and display messages for Normal Modeoperation.

    (iii) Timer Mode Initialization Initialize variables and display message for Timer Modeoperation.

    (iv) Lap Initialization Initialized variables and display message for Next Lap.

    2. Display Subroutines The following subroutines are used for display of messages, characters anddigits on LCD and 7-Segment Display:

    (i) LCD Write Writes a character on the LCD module.(ii) LCD digit display Displays digit on the LCD module.

    (iii) LCD Message Write Writes EEPROM stored messages on the LCD module.(iv) LCD Clear All Clear the entire LCD module.(v) LCD Clear Line1 Clear the first line of LCD module.(vi) LCD Clear Line2 Clear the second line of LCD module.(vii) Segment Display Display characters on four 7-segment display.(viii) Show Time Show time and lap number on LCD module.

    3. Speaker Subroutines The following subroutines are used to handle speaker ring and button pressbeeps:(i) Time-up Speaker Ring Sends the required frequencies to the piezo speaker to create a ring

    sound.

    (ii) Invalid Input Beep and Message Creates an invalid input beep and display thecorresponding message on the LCD module and 7-segement display.

    4. Timer Subroutines The following subroutines are used to acquire user input for the timer mode andevaluate time-up seconds:

    (i) Evaluate Set Time Evaluates the user input corresponding to the timer mode.(ii) Evaluate Timer Seconds Evaluate the timer seconds corresponding to the user input.

    5. Switch Subroutines The following subroutines are used to read switch input from the shift registerand perform the necessary task based on the input:

    (i) Read Switch - Read the switch values from the shift register.(ii) Switch Status Sends the program control to the necessary subroutine based on the input

    provided by the user.

    (iii) Stop Watch & Reset Stop the watch and reset it.(iv) Pause Watch Pause the watch and put it into a loop until the continue key (D2) is pressed.

    6. Power Saving Subroutines The following subroutines performs the necessary task of putting thesystem in sleep mode for power saving.(i) Shutdown Shuts down the LCD and 7-Segment display for power saving and keeps the

    program control in a loop until a key is pressed.

    (ii) Sleep Mode Settings Provides user an option to select the sleep mode settings.(iii) Sleep Mode Off Sets the sleep mode option to off.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    25/47

    (iv) Sleep Mode On Turn on the sleep mode option.

    7. Lap Subroutines The following subroutines perform the tasks pertaining to the lap updation andlap LEDs blinking.

    (i) Lap LEDs On Turn on the lap LEDs corresponding to the current lap.(ii) Lap LEDs Off Turn off the lap LEDs.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    26/47

    7. Testing Procedure

    AccuracyThe accuracy of the developed stop watch was measured using Direct Comparison Method [3].

    We compare timekeeping of the stopwatch with a benchmark stopwatch. Here we use XNote

    stopwatch [4] for PC as a benchmark. We test the accuracy of the stopwatch over a period of 1

    minute and 30 minutes. We do this by simultaneously starting and stopping the two stopwatchesand comparing the respective time elapsed. Next we test the accuracy when pause button is used

    for multiple number of times during a given time period.

    Test # 1 The stop watch timekeeping is compared for a duration of 60 seconds without any

    pause.

    Test # 2 The stop watch timekeeping is compared for a duration of 60 seconds with 1 pause.

    Time Period: 60 seconds Start / Pause: 1

    Test # 3 The stop watch timekeeping is compared for a duration of 60 seconds with 5 pauses.Time Period: 60 seconds Start / Pause: 5

    Test # 4 The stop watch timekeeping is compared for a duration of 30 minutes without anypause.

    Test ResultsS.No. XNoteWatchTime DigitalStopWatchTime

    1 Test1

    59.858 1:01

    2 Test2

    SetI

    (i) 30.42 31

    (ii) 01:00.2 1:02

    SetII

    (i) 30.1 31

    (ii) 01:00.6 1:02

    3 Test3

    (i) 13.244 14

    (ii)

    11.435

    12

    (iii) 23.213 24

    (iv) 36.239 39

    (v) 45.646 50

    (vi) 01:00.2 01:00.0

    4 Test4

    30:00.3 30:45:00

    The stop watch was found to have an error of 2 seconds per minute.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    27/47

    9. Discussion

    The system still has a scope for improvement. The following is a list of the features that can either

    improve the performance of the system or can be an added feature:

    When the watch starts after the switch is pressed by the user the first second is not absolutely accurate.This is because of the fact that the external pulse generator that is being used as a reference is already

    running and so the switch press event doesnt exactly coincide with the rising or falling edge of thepulse generator.

    The Auto Sleep mode currently does not function when the system prompts for Sleep mode on/offmode and while asking for input in the timer mode.

    Ability to store and retrieve upto 10 laps- Current implementation is limited by the memory of

    EEPROM. Additional memory can solve the problem.

    Increase the least count of stopwatch/timer to one hundredth of a second - Onboard oscillator can

    generate pulses upto 1000 Hz. But the bottlenecks lie in the communication channel between the LCDmodule and microcontroller and the speed of execution of instructions. At 4000 instructions per

    second, it can run a 10 line loop 400 times in a second. That means 1/400th

    of a second is the upper

    limit on the least count. A possible workaround with the communication channel bottleneck could be

    to calculate and store time in hundredths of a second during run time and display the hundredth part

    only when the time is stopped.

    Light / Proximity sensor - Using a Light / Proximity sensor for switching, the stopwatch can be used

    for a variety of applications like speed measurement, timed switching etc.

    Adding Split time mode of operation - Current implementation can be extended to include split timemode, with slight modifications in the program.

    Interface the timer with an appliance - Slight modifications in the circuit can be made to switch an

    appliance on termination of timer.

    Increase the timer/stopwatch limit - Currently the maximum timer/stopwatch limit is 65536 seconds.

    Modifications can be made to store the time in two words which can give it the maximum time limit of

    232

    seconds.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    28/47

    10. Conclusion

    The following design objectives are met:

    (i) The watch displays the time elapsed in hours, minutes and seconds.

    (ii) It provides the user a facility to set up a timer.(iii) It also has the feature of laps.

    (iv) It also implements an Auto Sleep mode.

    (v) It provides various audio visual cues to the user for guidance.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    29/47

    Contribution by each Team Member

    Priyanshu Agarwal: Overall system integration, coordination among team members and lab report.

    Dipen Harishbhai Dave: Algorithm for stop watch and coding for LCD display, testing methodology andlab report.

    Ravikiran Chollangi: Algorithm for Pause/Continue and Stop buttons, Component interfacing, hardwaredetails and lab report.

    Jason Lieu:Algorithm for modes of the system, circuit diagrams, flow charts and lab report.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    30/47

    Bibliography[1] Wikipedia, The Free Encyclopedia

    Available: http://en.wikipedia.org/wiki/Microcontroller

    [2] PBASIC Syntax Guide, PARALLAX INC., BASIC Stamp Editor/Development System, Version

    2.4.2.[3] Jeff C. Gust, Robert M. Graham, Michael A. Lombardi, Stopwatch and Timer Calibrations,

    National Institute of Standards and Technology Recommended Practice Guide, 2004

    [4] http://www.xnotestopwatch.com/[5] StampWorks Manual Version 1.1a, Parallax Inc.

  • 8/9/2019 MAE576 GroupD LAB1 Report

    31/47

    Appendix

    A. PBASIC Code for Digital Stopwatch' {$STAMP BS2}' =========================================================================' LAB1: DIGITAL STOP WATCH PBASIC CODE'' GROUP D'' Priyanshu Agarwal' Dipen Harishbhai Dave' Ravikiran Chollangi' Jason Lieu'' =========================================================================

    ' ' CONSTANTS & VARIABLES DEFINITION' ' LCD CONSTANTS & VARIABLESE CON 0 ' LCD Enable pin (1 = enabled)RS CON 3 ' Register Select (1 = char)LCDout VAR OUTB ' 4bit LCD dataClrLCD CON $01 ' clear the LCDCrsrHm CON $02 ' move cursor to home positionCrsrLf CON $10 ' move cursor leftCrsrRt CON $14 ' move cursor rightDispLf CON $18 ' shift displayed chars leftDispRt CON $1C ' shift displayed chars rightDDRam CON $80 ' Display Data RAM controlDispOff CON 8 ' LCD Display OffDispOn CON 12 ' LCD Display On

    Line1 CON $80Line2 CON $C0char VAR Byte ' character sent to LCDMsg VAR Byte ' Msg to be displayed on LCDindex VAR Byte ' loop counterindexstart VAR Byte ' Starting index of Msgindexend VAR Byte ' End index of the Msgline VAR Byte ' line in LCDMsgmode DATA "MODE D0 MODE D1" ' preload EEPROM with message (count 16)Msgselect DATA "SELECT A MODE! " ' preload EEPROM with message (count 16)MsgD0 DATA "MODE D0 SELECTED" ' preload EEPROM with message (count 16)MsgD1 DATA "MODE D1 SELECTED" ' preload EEPROM with message (count 16)Msgup DATA "TIME UP! " ' preload EEPROM with message (count 16)Msgreset DATA "RESETTING!" ' preload EEPROM with message (count 10)Msginvinp DATA "INVALID INPUT!" ' preload EEPROM with message (count 14)Msgclr DATA " " ' preload EEPROM with message (count 16)Msghrs DATA "HOURS?" ' preload EEPROM with message (count 6)Msgmins DATA "MINUTES?" ' preload EEPROM with message (count 8)

  • 8/9/2019 MAE576 GroupD LAB1 Report

    32/47

    Msgsecs DATA "SECONDS?" ' preload EEPROM with message (count 8)MsgGreet DATA " WELCOME TO " ' preload EEPROM with message (count 16)MsgClock DATA " DIGITAL CLOCK " ' preload EEPROM with message (count 16)MsgPower DATA "AUTO SLEEP OFF? " ' preload EEPROM with message (count 16)MsgYN DATA " (Yes:D1/No:D0) " ' preload EEPROM with message (count 16)MsgY DATA "Yes"MsgN DATA "No"'MsgPowerOn DATA "AUTO POWER OFFY" ' preload EEPROM with message (count 16)'MsgPowerOff DATA "AUTO POWER OFFN" ' preload EEPROM with message (count 16)' ' TIMER CONSTANTS & VARIABLESsegs VAR OUTL ' segmentsdigSel VAR OUTC ' digit selecttic VAR IN15 ' 1 Hz Pulse Generator inputDPoint CON %10000000 ' decimal point bitD0 CON 1D1 CON 2D2 CON 4D3 CON 8D4 CON 16D5 CON 32D6 CON 64D7 CON 128secs VAR Word ' secondslsecs VAR Word ' secondsdigit VAR Nib ' current display digitval VAR Bytelap VAR NibSetTime VAR ByteSetsecs VAR Wordconvfac VAR Wordsflag VAR BitDelayTime CON 25' ' SPEAKER CONSTANTS & VARIABLESSpeaker CON 1 ' piezo speaker on pin 0' ' SHIFT REGISTER INPUT 74X165 CONSTANTS &VARIABLESClock CON 8 ' shift clock (74x165.2)D_in CON 9 ' shift data (74x165.7)Load CON 10 ' input load (74x165.1)switches VAR Byte ' inputs switches' ' MAX7219 CONSTANTS & VARIABLESd7219 VAR Byte ' data for MAX7219Dpin CON 13 ' data pin (MAX7219.1)ClockMAX CON 12 ' clock pin (MAX7219.13)LoadMAX CON 11 ' load pin (MAX7219.12)Decode CON $09 ' bcd decode registerBrite CON $0A ' intensity registerScan CON $0B ' scan limit registerShutDn CON $0C ' shutdown register (1 = on)Test CON $0F ' display test modeDecPnt CON %10000000

  • 8/9/2019 MAE576 GroupD LAB1 Report

    33/47

    Blank CON %1111 ' blank a digitYes CON 1No CON 0indexMAX VAR NibidxOdd VAR indexMAX.BIT0 ' is index odd? (1 = yes)segdata VAR Byte' ' 7SEGMENT DATA' Segments .abcdefg' CLEAR DATA %00000000 ' Clear Segment Digit 1

    DATA %00000000 ' Clear Segment Digit 2DATA %00000000 ' Clear Segment Digit 3DATA %00000000 ' Clear Segment Digit 4

    Stop7 DATA %01011011 ' SDATA %00001111 ' tDATA %00011101 ' oDATA %01100111 ' p

    HALT DATA %00110111 ' HDATA %01110111 ' ADATA %00001110 ' LDATA %01110000 ' T

    Run DATA %01110111 ' RDATA %00011100 ' uDATA %00010101 ' nDATA %00000000 ' clear

    PICK DATA %01100111 ' PDATA %00000110 ' IDATA %01001110 ' CDATA %00110111 ' K

    Invalid DATA %00000001 ' DATA %00000001 ' DATA %00000001 ' DATA %00000001 '

    HII DATA %00110111 ' HDATA %00110000 ' IDATA %10110000 ' !DATA %00000000 ' clear

    LAP2 DATA %00001110 ' LDATA %01110111 ' ADATA %01100111 ' PDATA %01101101 ' 2

    HOUR DATA %00110111 ' HDATA %01111110 ' ODATA %00111110 ' UDATA %01110111 ' R

    MIn7 DATA %01110110 ' Half MDATA %01110110 ' Half MDATA %00110000 ' I

  • 8/9/2019 MAE576 GroupD LAB1 Report

    34/47

    DATA %00010101 ' nSEC DATA %01011011 ' S

    DATA %01001111 ' EDATA %01001110 ' CDATA %00000000 ' clear

    AUTO DATA %01110111 ' ADATA %00111110 ' UDATA %01110000 ' TDATA %01111110 ' O

    ' ' 'VARIABLES & CONSTANTS RELATED TO LAPLAPLED1 VAR OUT2LAPLED2 VAR OUT14MAXLAP CON 2lflag VAR Bit' ' 'VARIABLES & CONSTANT RELATED TO POWER SAVER MODEcounterMAX VAR Wordidlecounter VAR WordcounterPS CON 100'

    ' 'INITIALIZATION' Initialize:DIRL = %11111111 ' setup pins for LCD, Lap LED as out, Speaker as outGOSUB LCDinit ' initialize LCD for 4bit modeHIGH Load ' make output; initialize to 1DIRH = %01111101 ' data, clock and load (74X165) as out,

    ' data as in, clock and load as out for MAX7219' Lap LED as out

    '7 SEGMENT INITIALIZATIONFOR indexMAX = 0 TO 7LOOKUP indexMAX,[Scan,3,Brite,5,Decode,0,ShutDn,1],d7219SHIFTOUT Dpin,ClockMAX,MSBFIRST,[d7219]IF idxOdd = No THEN NoLoadPULSOUT LoadMAX,3 ' load parameter

    NoLoad:NEXTsegdata = CLEARGOSUB SegDispsegdata = HII ' dispaly "HI!" on 7Segment displayGOSUB SegDispMsg = MsgGreet ' display welcome message on LCDindexend = 15line = Line1GOSUB MsgDispMsg = MsgClockindexend = 15line = Line2

  • 8/9/2019 MAE576 GroupD LAB1 Report

    35/47

    GOSUB MsgDispPAUSE 1000idlecounter = 0counterMAX = counterPSlap = 0

    '

    ' ' MAIN PROGRAM' 'DEBUG "Above"RepeatMsg:Msg = Msgmodeindexend = 15line = Line1GOSUB MsgDispMsg = Msgselectindexend = 15line = Line2GOSUB MsgDispRepeat:idlecounter = (idlecounter + 1)'DEBUG CR, DEC idlecounter, DEC counterMAXIF idlecounter = counterMAX THEN ShutDownRepeatsegdata = PICKGOSUB SegDispPAUSE 100segdata = CLEARGOSUB SegDispGOSUB ReadSwitchesIF Switches = 0 THEN RepeatIF Switches = D0 THEN IniNormModIF Switches = D1 THEN IniTimerModIF Switches = D7 THEN AutoPowerOffIF Switches 2 THEN InvalidInput

    MainSetTime:GOSUB ReadSwitches'DEBUG CR, "Setsecs = ", DEC SetsecsIF Switches = 0 THEN Resetsflag

    Resetted:'DEBUG "Looping"IF (Switches 0) AND (sflag = 0) THEN EvalSetTimeGOTO MainSetTime

    MainClr:idlecounter = 0GOSUB ClrLine1

    Main:'DEBUG CR, "Main"'PAUSE DelayTimeGOSUB ShowTime ' show current TimeGOSUB SwitchStatus

    StartWatch:GOSUB LapLedOff'PAUSE DelayTime

  • 8/9/2019 MAE576 GroupD LAB1 Report

    36/47

    IF tic = 1 THEN IncSec ' new second?GOSUB ReadSwitchesGOTO Main ' do it again

    IncSec:lsecs = (lsecs+1)secs = (secs+1)FREQOUT Speaker,10,1 ' seconds tic 1Hz for 10ms'PAUSE DelayTime

    Waiting:GOSUB LapLedOnGOSUB ShowTime ' show current digitGOSUB SwitchStatusIF secs >= SetSecs THEN TimeUp'PAUSE DelayTimeIF tic = 0 THEN Main ' if last tic gone, go backGOTO Waiting ' do tic check againEND

    '

    ''SUBROUTINES USED IN THE PROGRAM''INITIALIZATION SUBROUTINES' LCD INITIALIZATIONLCDinit:PAUSE 500 ' let the LCD settleLCDout = %0011 ' 8bit modePULSOUT E,1PAUSE 500PULSOUT E,1PULSOUT E,1LCDout = %0010 ' 4bit modePULSOUT E,1char = %00001100 ' disp on, crsr off, blink offGOSUB LCDcommandchar = %00000110 ' inc crsr, no disp shiftGOSUB LCDcommandchar = ClrLCDGOSUB LCDcommandRETURN

    ' ' INITIALIZE VARIABLES FOR NORMAL MODE (D0)IniNormMod:GOSUB CommonIniSetSecs = 65535Msg = MsgD0indexend = 15line = Line2GOSUB MsgDispline = Line1GOTO Main

    ' ' INITIALIZE VARIABLES FOR TIMER MODE (D1)IniTimerMod:

  • 8/9/2019 MAE576 GroupD LAB1 Report

    37/47

    GOSUB CommonIniSetSecs = 10Msg = MsgD1indexend = 15line = Line2GOSUB MsgDispline = Line1index = 5GOTO HrsDispSet

    ' GOTO Main' 'COMMON INITILIZATION BETWEEN TWO MODESCommonIni:FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10msGOSUB ClrAllsflag = 0secs = 0lsecs = 0lap = 1RETURN

    ' 'INITIALIZATION FOR NEXT LAP

    NextLap:IF lap = MAXLAP THEN NoUpdateFREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10mssegdata = LAP2GOSUB SegDispPAUSE 100GOSUB ClrLine2line = Line2index = 0lap = lap+1lsecs = 0NoUpdate:lflag = 1GOTO Main'

    ' DISPLAY SUBROUTINES' WRITE ON LCDLCDcommand:LOW RS ' enter command mode

    LCDwrite:'char = %11000110LCDout = char.HIGHNIB ' output high nibblePULSOUT E,1 ' strobe the Enable lineLCDout = char.LOWNIB ' output low nibblePULSOUT E,1HIGH RS ' return to character mode'GOSUB ReadSwitchesRETURN

    ' ' DISPLAY DIGIT ON LCDDigDisp:char = line+index ' set new DDRAM address

  • 8/9/2019 MAE576 GroupD LAB1 Report

    38/47

    GOSUB LCDcommandLOOKUP val,["0","1","2","3","4","5","6","7","8","9",":"," "],charGOSUB LCDwrite ' write the characterRETURN

    ' 'LCD MSG WRITEMsgClrDisp:GOSUB ClrAll

    MsgDisp:FOR index = indexstart TO indexend ' get message from EEPROMchar = line + index ' set new DDRAM addressGOSUB LCDcommandREAD (Msg + index),char ' read a characterGOSUB LCDwrite ' write it

    NEXTRETURN

    ' ' CLEAR FULL LCD DISPLAYClrAll:char = ClrLCD ' Clear the LCDGOSUB LCDcommandRETURN

    ' ' CLEAR LINE 1 OF LCD DISPLAYClrLine1:Msg = Msgclrindexend = 15line = Line1GOSUB MsgDispRETURN

    '

    ' CLEAR LINE 2 OF LCD DISPLAYClrLine2:Msg = Msgclrindexend = 15line = Line2GOSUB MsgDispline = Line1RETURN

    ' ' DISPLAY DATA ON 7SEGMENTSegDisp:FOR indexMAX = 4 TO 1READ (4 indexMAX + segdata),d7219 ' read and send letterSHIFTOUT Dpin,ClockMAX,MSBFIRST,[indexMAX,d7219]PULSOUT LoadMAX,3

    NEXTRETURN

    ' ' SHOW TIME ON LCDShowTime:segdata = RunGOSUB SegDispchar = CrsrHm ' move the cursor homeGOSUB LCDcommand

  • 8/9/2019 MAE576 GroupD LAB1 Report

    39/47

    index = 0val = lap 'lap numberGOSUB DigDisp 'display ten's digit of hoursindex = index +1val = 11GOSUB DigDisp 'display spaceindex = index +1val = (lsecs/3600)/10 'ten's digit of hoursGOSUB DigDisp 'display ten's digit of hoursval = (lsecs/3600)//10 'one's digit of hoursGOSUB DigDisp 'display one's digit of hoursindex = index +1val = 10GOSUB DigDisp 'display colonindex = index +1val = (lsecs/60)/10 'ten's digit of minutesGOSUB DigDisp 'display ten's digit of minutesindex = index +1val = (lsecs/60)//10 'one's digit of minuteGOSUB DigDisp 'display one's digit of minutesindex = index +1val = 10GOSUB DigDisp 'display colonindex = index +1val = (lsecs//60)/10 'ten's digit of secondGOSUB DigDisp 'display ten's digit of secondindex = index +1val = (lsecs//60)//10 'one's digit of secondGOSUB DigDisp 'display one's digit of secondindex = 0RETURN

    '

    ' SPEAKER SUBROUTINES' TIMEUP SPEAKER RINGTimeUp:secs = 0lsecs = 0sflag = 0lap = 0GOSUB LapLedOffMsg = Msgupindexend = 15line = Line2GOSUB MsgDispFREQOUT Speaker,2000,440,480 ' combine 440 Hz and 480 HzMsg = Msgresetindexend = 9line = Line2GOSUB MsgDispPAUSE 200

  • 8/9/2019 MAE576 GroupD LAB1 Report

    40/47

    line = Line1GOTO RepeatMsg

    ' ' START WATCH BUTTON PRESS BEEPStartWatchBeep:FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10msGOTO StartWatch

    ' ' INVALID INPUT BEEP AND MESSAGEInvalidBeepMsg:FREQOUT Speaker,50,1000,100 ' button press tic 1000Hz/100Hz for 50mssegdata = InvalidGOSUB SegDispGOSUB ClrLine2Msg = Msginvinpindexend = 13line = Line2GOSUB MsgDispPAUSE 200line = Line1RETURN'

    ' TIMER SUBROUTINES' EVALUATE SET TIME FOR TIMEREvalSetTime:' DEBUG "EvalTime", CR, DEC SwitchesFREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10mssflag = 1LOOKDOWN Switches, [D0, D1, D2, D3, D4, D5, D6, D7], SwitchesIF Switches = 7 THEN EvalSecsval = Switchesindex = (index + 1)GOSUB DigDispSetTime = SetTime*10LOOKUP Switches, [SetTime+0, SetTime+1, SetTime+2, SetTime+3, SetTime+4, SetTime+5, SetTime+6], SetTime' DEBUG CR, DEC SetTimeGOTO MainSetTime

    ' 'EVALUATE SECONDS FOR TIMEREvalSecs:SetSecs = SetSecs+SetTime*convfacSetTime = 0IF convfac = 3600 THEN MinDispSetIF convfac = 60 THEN SecDispSetIF convfac = 1 THEN MainClrGOTO MainSetTime

    ' ' DISPLAY HOURS? ON LCDHrsDispSet:Setsecs = 0SetTime = 0sflag = 1segdata = HOURGOSUB SegDisp

  • 8/9/2019 MAE576 GroupD LAB1 Report

    41/47

    ' GOSUB ClrAllGOSUB ClrLine1Msg = Msghrsindexend = 5line = Line1GOSUB MsgDispconvfac = 3600GOTO MainSetTime

    ' ' DISPLAY MINUTES? ON LCDMinDispSet:segdata = Min7GOSUB SegDispGOSUB ClrLine1Msg = Msgminsindexend = 7line = Line1GOSUB MsgDispconvfac = 60GOTO MainSetTime

    ' ' DISPLAY SECONDS? ON LCDSecDispSet:segdata = SECGOSUB SegDispGOSUB ClrLine1Msg = Msgsecsindexend = 7line = Line1GOSUB MsgDispconvfac = 1GOTO MainSetTime

    ' ' RESET FLAG FOR SETTING TIMERResetsflag:sflag = 0GOTO Resetted

    '

    ' SWITCH SUBROUTINES' READ SWITCH STATUS FROM 74x165.BS2ReadSwitches:PULSOUT Load,3 ' grab the switch inputsSHIFTIN D_in,Clock,MSBPRE,[switches] ' shift them in' DEBUG HOME, IBIN8 switches ' display binary mode

    ' PAUSE 100RETURN

    ' ' SWITCH STATUS WHILE WATCH IS RUNNINGSwitchStatus:IF Switches = 0 THEN Resetlflag ' Lap Button Wil work only when lflag = 0

    ' (Avoid looping due to repetitive pressing in one go)IF Switches = D2 THEN PauseWatchBeepIF Switches = D4 THEN StopWatchBeepIF (Switches = D5) AND (lflag = 0) THEN NextLap

  • 8/9/2019 MAE576 GroupD LAB1 Report

    42/47

    RETURN' ' STOP WATCH AND RESETStopWatchBeep:FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms

    StopWatch:segdata = Stop7GOSUB SegDispMsg = Msgresetindexend = 15line = Line1GOSUB MsgDispPAUSE 200GOSUB ClrAlllap = 0GOTO RepeatMsg

    ' ' PAUSE STOP WATCHPauseWatchBeep:idlecounter = 0FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10msGOSUB LapLedOn

    PauseWatch:segdata = HALTGOSUB SegDispPAUSE 100segdata = CLEARGOSUB SegDispGOSUB ReadSwitchesIF Switches = D3 THEN StartWatchBeepIF Switches = 0 THEN IncIdleCountidlecounter = 0IncIdleCount:idlecounter = (idlecounter + 1)'DEBUG CR, DEC idlecounterIF idlecounter = counterMAX THEN ShutDownPause

    ' DEBUG CR, "RETURNED"GOTO PauseWatch

    '

    ' POWER SAVING SUBROUTINES' SHUTDOWN LCD & 7SEG FOR POWER SAVINGShutDown:SHIFTOUT Dpin,ClockMAX,MSBFIRST,[Shutdn,0] ' ShutDown 7Segment DisplayPULSOUT LoadMAX,1char = DispOff ' turn the LCD OffGOSUB LCDcommand

    ShutLoop:GOSUB ReadSwitchesIF Switches 0 THEN StartGOTO ShutLoop

    Start:'Switches = 0FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10msSHIFTOUT Dpin,ClockMAX,MSBFIRST,[Shutdn,1] ' ShutDown 7Segment DisplayPULSOUT LoadMAX,1

  • 8/9/2019 MAE576 GroupD LAB1 Report

    43/47

    char = DispOn ' turn the LCD OnGOSUB LCDcommandidlecounter = 0RETURN

    ' ' SHUTDOWN FOR REPEAT MSGShutDownRepeat:GOSUB ShutDownGOTO Repeat'

    ' SHUTDOWN FOR PAUSEShutDownPause:GOSUB ShutDownGOTO PauseWatch

    ' ' AUTOPOWER OFF SETTINGAutoPowerOff:Msg = MsgPowerindexend = 15line = Line1GOSUB MsgDispMsg = MsgYNindexend = 15line = Line2GOSUB MsgDispidlecounter = 0

    PowerLoop:segdata = PICKGOSUB SegDispGOSUB ReadSwitchesIF Switches = D0 THEN PowerNIF Switches = D1 THEN PowerYPAUSE 200segdata = CLEARGOSUB SegDispGOTO PowerLoop

    ' ' AUTOPOWER OFF YESPowerY:FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10msGOSUB ClrAllMsg = MsgYindexend = 2line = Line1GOSUB MsgDispcounterMAX = counterPSPAUSE 1000GOTO RepeatMsg

    ' ' AUTOPOWER OFF NOPowerN:FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10msGOSUB ClrAllMsg = MsgNindexend = 1line = Line1

  • 8/9/2019 MAE576 GroupD LAB1 Report

    44/47

    GOSUB MsgDispcounterMAX = 65535PAUSE 1000GOTO RepeatMsg

    '

    ' LAP SUBROUTINES

    ' RESET FLAG FOR LAPResetlflag:lflag = 0RETURN

    ' ' TURN ON LAP LEDSLapLedOn:IF lap = 1 THEN Led1IF lap = 2 THEN Led2

    Led1:LAPLED1 = 1RETURN

    Led2:LAPLED2 = 1RETURN

    ' ' TURN OFF LAP LEDSLapLedOff:LAPLED1 = 0LAPLED2 = 0RETURN

    '

    ' MISC'SEND BACK ON INVALID INPUTInvalidInput:idlecounter = 0GOSUB InvalidBeepMsgGOTO RepeatMsg

    '

  • 8/9/2019 MAE576 GroupD LAB1 Report

    45/47

    B. Data Sheets

    B.1 MAX7219, Serially Interfaced, 8-digit LED Driver Display (www.datasheetcatalog.com)

  • 8/9/2019 MAE576 GroupD LAB1 Report

    46/47

    B.2 74HC165, 8-bit parallel-in/serial out shift register (NXP Semiconductors)

    Pin Configuration Functional Diagram

  • 8/9/2019 MAE576 GroupD LAB1 Report

    47/47

    B.3 HD44780U (LCD-II) Dot Matrix Liquid Crystal Display Controller /Driver