Documente Academic
Documente Profesional
Documente Cultură
Mechatronics 576
Spring 2010
February 23rd 2010
“Group D”
Priyanshu Agarwal
Dipen Harishbhai Dave
Ravikiran Chollangi
Jason Lieu
2. Hardware
2.1 List of Components
2.2 Hardware Description
2.3 Microcontroller (Basic Stamp 2) Pin Assignment
2.4 Circuit Diagrams
3. Software
4. Mathematical Methods
5. Implementation
5.1 Software Algorithms
5.1.1 System Flowchart
5.1.2 Normal Mode (D0) Flowchart
5.1.3 Timer Mode (D1) Flowchart
5.1.4 Show Time Flowchart
5.1.5 Start Timer Flowchart
5.1.6 Sleep Mode Option Flowchart
5.1.7 Pause Watch Option Flowchart
5.2 Subroutines
6. Testing Procedure
7. Discussion
8. Conclusion
Bibliography
Appendix
A. PBASIC Code for Digital Stopwatch
B. Data Sheets
B.1 MAX7219, Serially Interfaced, 8‐digit LED Driver Display
B.2 74HC165, 8‐bit parallel‐in/serial out shift register
B.3 HD44780U (LCD‐II) Dot Matrix Liquid Crystal Display Controller /Driver
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 amount
of 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, specialized
BASIC interpreter (PBASIC) built into ROM. It is made by Parallax, Inc. and has been popular with
electronics 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 the
various 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 provide
various audio visual cues to be user-friendly.
1. Modes of Operation – In order to serve multiple purposes the watch has the following two modes of
operation:
(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 lap
and the mode selected.
2. User Input – The system is based on the input provided by the user. It seeks input from the user
using a set of 8 switches with different roles assigned to each switch based on the current state of
the 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 to
enter timer time.
3. Laps – The stop watch also provides a feature to divide the time into two laps. The current lap can be
assessed both from the LCD and the blinking LEDs.
4. Auto Sleep Mode – In order to save power which is always the case in standalone applications, the
system 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 the
feature 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 the
user:
(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.
“PICK” Message on 7-Segment Display “Run” Message signifying that the watch is running
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 and
“Invalid 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 watch
is 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 set
time 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 options
for 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
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 to
press 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 the
watch is running or not.
3. Hardware
The following sections deals with the details of the hardware used to implement the digital stop watch.
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 modules
2. 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 motors
10. Pulse generator for 1Hz, 10 Hz, 100 Hz, and 1 kHz
11. RS-232 interface port for communication with COM program
12. Socket for 24-pin BASIC Stamp modules
13. Parallel LCD module with connector and brightness control
14. Piezospeaker
15. 10K potentiometer
16. 2.5" x 7" breadboard with 800 contact points
17. 7.5V DC 1 amp power supply with polarity protection
Source: http://www.apexvalue.com/basic_stamp/product_id_28135.htm
http://www.nipahut.com.ph
‐ 16 x 2 Alphanumeric characters
‐ 4-bit or 8-bit MPU interface enabled
MAX 7219 Display
M D Driiver
T MAX 72219 are com
The mpact, serial input/output
i cathode dispplay drivers that interfacce microproccessors
t seven segm
to ment numeriic displays. TheT chip conntains a BCD D code-B decoder, multiiplex scan ciircuitry.
S
Segment andd digit driverrs and a 8X88 static RAM
M. It also alloows driving individual
i diigits of a dissplay.
This is an LE
T ED driver thaat requires juust three miccrocontrollerr pins to conntrol up to 8 7-segment digits
d or
a bar graph display
d or up
p to 64 individual LEDs.
7
74HC165 Sh
hift Registerr
www.seeedstudio.coom
This shift reggister allowss a microconntroller to reaad a large nuumber of diggital inputs using
T u just three
m
microcontrol ller pins. Eacch 74HC1655 provides 8 input pins. Any A numberr of 74HC1665 chips can be
c
cascaded using the same set of microocontroller pins.
p It has syynchronous serial input.
P
Piezo Speak
ker
http://www
w.hvwtech.coom
7
7-Segment D
Display
3.3 Microcontroller (BASIC Stamp 2) Pin Assignment
P0, P3, P4, P5, P6, P7 are the inputs from microcontroller.
P4-P7 are data pins
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.
P2 and P4 are outputs from the microcontroller which drives two LEDs ( Lap 1 and Lap 2).
16 10K
2 11 D0
P8
7 12 D1
P9
1 13 D2
P10
Shift
Register 14 D3
74HC165
3 D4
4 D5
5 D6
6 D7
8 15
Vss
P8: Clock Pin input to 74X165
P9: 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
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 the
program specified by Address; with the intention of returning to the stored address.
Syntax: GOSUB Address
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 Counter
variable passes the EndValue.
Syntax: FOR Counter = StartValue TO EndValue {STEP StepValue} ... NEXT
5. IF…THEN – Evaluate Condition and, if it is true, go to the point in the program marked by Address.
Syntax: IF Condition THEN Address
6. LOOKUP – Find the value at location Index and store it in Variable. If Index exceeds the highest
index value of the items in the list, Variable is left unaffected.
Syntax: LOOKUP Index, [Value0, Value1, ...ValueN], Variable
7. LOOKDOWN - Compare Target value to a list of values and store the index number of the first
value that matches into Variable. If no value in the list matches, Variable is left unaffected.
Syntax: LOOKDOWN Target, {ComparisonOp} [Value0, Value1, ...ValueN], Variable
8. SHIFTIN – Shift data in from a synchronous serial device. The SHIFTIN instruction first causes the
clock pin to output low and the data pin to switch to input mode. Then, SHIFTIN either reads the
data 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: SHIFTIN Dpin, Cpin, Mode, [Variable {\Bits} {, Variable {\Bits}...}]
9. SHIFTOUT – Shift data out to a synchronous serial device. The SHIFTOUT instruction first
causes 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: SHIFTOUT Dpin, Cpin, Mode, [OutputData {\Bits} {,OutputData {\Bits}...}]
13. FREQOUT – Generate one or two sine-wave tones for a specified duration.
Syntax: FREQOUT Pin, Duration, Freq1 {, Freq2}
14. READ - Read value at Location in EEPROM and store the result in result in Variable.
Syntax: READ Location, {Word} Variable {, {Word} Variable, ...}
15. RETURN – Return from a subroutine, assuming there was a previous GOSUB or ON...GOSUB
executed.
Syntax: RETURN
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.
where, represents the floor function. The BASIC stamp module by default implements the floor
function in all its calculation.
The digits from the above calculated number of hours are now extracted using the following:
10
10 x
10
The digits from the above calculated number of minutes are now extracted using the following:
10
10 x
10
The digits from the above calculated number of minutes are now extracted using the following:
10
10 x
10
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 Algorithms
The following section presents the various algorithms used to implement different modes in the system.
The different algorithms used are as follows:
1. System Flowchart
2. Normal Mode (D0) Flowchart
3. Timer Mode (D1) Flowchart
4. Show Time Flowchart
5. Start Timer Flowchart
6. Sleep Mode Option Flowchart
7. Pause Watch Option Flowchart
6.1.1 System Flowchart
6.1.2 Normal Mode (D0) Flowchart
6.1.3 Timer Mode (D1) Flowchart
6.1.4 Show Time Flowchart
1. Initialization Subroutines – The following subroutines are used for initialization of variables and
display messages in different modes:
(i) LCD Initialization – Initializes the LCD for display.
(ii) Normal Mode Initialization – Initialize variables and display messages for Normal Mode
operation.
(iii) Timer Mode Initialization – Initialize variables and display message for Timer Mode
operation.
(iv) Lap Initialization – Initialized variables and display message for Next Lap.
2. Display Subroutines – The following subroutines are used for display of messages, characters and
digits 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 press
beeps:
(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 the
corresponding 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 and
evaluate 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 register
and 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 the
system 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.
(iv) Sleep Mode On – Turn on the sleep mode option.
7. Lap Subroutines – The following subroutines perform the tasks pertaining to the lap updation and
lap 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.
7. Testing Procedure
Accuracy
The 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 stopwatches
and 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 any
pause.
Test Results
S. No. XNote Watch Time Digital Stop Watch Time
1 Test 1
59.858 1:01
2 Test 2
Set I
(i) 30.42 31
(ii) 01:00.2 1:02
Set II
(i) 30.1 31
(ii) 01:00.6 1:02
3 Test 3
(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 Test 4
30:00.3 30:45:00
The stop watch was found to have an error of 2 seconds per minute.
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 doesn’t exactly coincide with the rising or falling edge of the
pulse generator.
The Auto Sleep mode currently does not function when the system prompts for Sleep mode on/off
mode 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 LCD
module 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 time
mode, 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.
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.
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 and
lab report.
Ravikiran Chollangi: Algorithm for Pause/Continue and Stop buttons, Component interfacing, hardware
details and lab report.
Jason Lieu: Algorithm for modes of the system, circuit diagrams, flow charts and lab report.
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.
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 & VARIABLES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
E CON 0 ' LCD Enable pin (1 = enabled)
RS CON 3 ' Register Select (1 = char)
LCDout VAR OUTB ' 4‐bit LCD data
ClrLCD CON $01 ' clear the LCD
CrsrHm CON $02 ' move cursor to home position
CrsrLf CON $10 ' move cursor left
CrsrRt CON $14 ' move cursor right
DispLf CON $18 ' shift displayed chars left
DispRt CON $1C ' shift displayed chars right
DDRam CON $80 ' Display Data RAM control
DispOff CON 8 ' LCD Display Off
DispOn CON 12 ' LCD Display On
Line1 CON $80
Line2 CON $C0
char VAR Byte ' character sent to LCD
Msg VAR Byte ' Msg to be displayed on LCD
index VAR Byte ' loop counter
indexstart VAR Byte ' Starting index of Msg
indexend VAR Byte ' End index of the Msg
line VAR Byte ' line in LCD
Msgmode 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)
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 OFF‐Y" ' preload EEPROM with message (count 16)
'MsgPowerOff DATA "AUTO POWER OFF‐N" ' preload EEPROM with message (count 16)
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐TIMER CONSTANTS & VARIABLES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
segs VAR OUTL ' segments
digSel VAR OUTC ' digit select
tic VAR IN15 ' 1 Hz Pulse Generator input
DPoint CON %10000000 ' decimal point bit
D0 CON 1
D1 CON 2
D2 CON 4
D3 CON 8
D4 CON 16
D5 CON 32
D6 CON 64
D7 CON 128
secs VAR Word ' seconds
lsecs VAR Word ' seconds
digit VAR Nib ' current display digit
val VAR Byte
lap VAR Nib
SetTime VAR Byte
Setsecs VAR Word
convfac VAR Word
sflag VAR Bit
DelayTime CON 25
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SPEAKER CONSTANTS & VARIABLES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Speaker CON 1 ' piezo speaker on pin 0
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SHIFT REGISTER INPUT 74X165 CONSTANTS &VARIABLES‐‐‐‐‐‐‐‐‐‐‐
Clock 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 & VARIABLES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
d7219 VAR Byte ' data for MAX7219
Dpin 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 register
Brite CON $0A ' intensity register
Scan CON $0B ' scan limit register
ShutDn CON $0C ' shutdown register (1 = on)
Test CON $0F ' display test mode
DecPnt CON %10000000
Blank CON %1111 ' blank a digit
Yes CON 1
No CON 0
indexMAX VAR Nib
idxOdd VAR indexMAX.BIT0 ' is index odd? (1 = yes)
segdata VAR Byte
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐7‐SEGMENT DATA‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' Segments .abcdefg
' ‐‐‐‐‐‐‐‐
CLEAR DATA %00000000 ' Clear Segment Digit 1
DATA %00000000 ' Clear Segment Digit 2
DATA %00000000 ' Clear Segment Digit 3
DATA %00000000 ' Clear Segment Digit 4
Stop7 DATA %01011011 ' S
DATA %00001111 ' t
DATA %00011101 ' o
DATA %01100111 ' p
HALT DATA %00110111 ' H
DATA %01110111 ' A
DATA %00001110 ' L
DATA %01110000 ' T
Run DATA %01110111 ' R
DATA %00011100 ' u
DATA %00010101 ' n
DATA %00000000 ' clear
PICK DATA %01100111 ' P
DATA %00000110 ' I
DATA %01001110 ' C
DATA %00110111 ' K
Invalid DATA %00000001 ' ‐
DATA %00000001 ' ‐
DATA %00000001 ' ‐
DATA %00000001 ' ‐
HII DATA %00110111 ' H
DATA %00110000 ' I
DATA %10110000 ' !
DATA %00000000 ' clear
LAP2 DATA %00001110 ' L
DATA %01110111 ' A
DATA %01100111 ' P
DATA %01101101 ' 2
HOUR DATA %00110111 ' H
DATA %01111110 ' O
DATA %00111110 ' U
DATA %01110111 ' R
MIn7 DATA %01110110 ' Half M
DATA %01110110 ' Half M
DATA %00110000 ' I
DATA %00010101 ' n
SEC DATA %01011011 ' S
DATA %01001111 ' E
DATA %01001110 ' C
DATA %00000000 ' clear
AUTO DATA %01110111 ' A
DATA %00111110 ' U
DATA %01110000 ' T
DATA %01111110 ' O
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐'VARIABLES & CONSTANTS RELATED TO LAP‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
LAPLED1 VAR OUT2
LAPLED2 VAR OUT14
MAXLAP CON 2
lflag VAR Bit
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐'VARIABLES & CONSTANT RELATED TO POWER SAVER MODE‐‐‐‐‐‐‐‐‐‐‐‐‐
counterMAX VAR Word
idlecounter VAR Word
counterPS CON 100
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐INITIALIZATION‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Initialize:
DIRL = %11111111 ' setup pins for LCD, Lap LED as out, Speaker as out
GOSUB LCDinit ' initialize LCD for 4‐bit mode
HIGH Load ' make output; initialize to 1
DIRH = %01111101 ' data, clock and load (74X165) as out,
' data as in, clock and load as out for MAX7219
' Lap LED as out
'7 SEGMENT INITIALIZATION
FOR indexMAX = 0 TO 7
LOOKUP indexMAX,[Scan,3,Brite,5,Decode,0,ShutDn,1],d7219
SHIFTOUT Dpin,ClockMAX,MSBFIRST,[d7219]
IF idxOdd = No THEN NoLoad
PULSOUT LoadMAX,3 ' load parameter
NoLoad:
NEXT
segdata = CLEAR
GOSUB SegDisp
segdata = HII ' dispaly "HI!" on 7‐Segment display
GOSUB SegDisp
Msg = MsgGreet ' display welcome message on LCD
indexend = 15
line = Line1
GOSUB MsgDisp
Msg = MsgClock
indexend = 15
line = Line2
GOSUB MsgDisp
PAUSE 1000
idlecounter = 0
counterMAX = counterPS
lap = 0
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐MAIN PROGRAM‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'DEBUG "Above"
RepeatMsg:
Msg = Msgmode
indexend = 15
line = Line1
GOSUB MsgDisp
Msg = Msgselect
indexend = 15
line = Line2
GOSUB MsgDisp
Repeat:
idlecounter = (idlecounter + 1)
'DEBUG CR, DEC idlecounter, DEC counterMAX
IF idlecounter = counterMAX THEN ShutDownRepeat
segdata = PICK
GOSUB SegDisp
PAUSE 100
segdata = CLEAR
GOSUB SegDisp
GOSUB ReadSwitches
IF Switches = 0 THEN Repeat
IF Switches = D0 THEN IniNormMod
IF Switches = D1 THEN IniTimerMod
IF Switches = D7 THEN AutoPowerOff
IF Switches <> 2 THEN InvalidInput
MainSetTime:
GOSUB ReadSwitches
'DEBUG CR, "Setsecs = ", DEC Setsecs
IF Switches = 0 THEN Resetsflag
Resetted:
'DEBUG "Looping"
IF (Switches <> 0) AND (sflag = 0) THEN EvalSetTime
GOTO MainSetTime
MainClr:
idlecounter = 0
GOSUB ClrLine1
Main:
'DEBUG CR, "Main"
'PAUSE DelayTime
GOSUB ShowTime ' show current Time
GOSUB SwitchStatus
StartWatch:
GOSUB LapLedOff
'PAUSE DelayTime
IF tic = 1 THEN IncSec ' new second?
GOSUB ReadSwitches
GOTO Main ' do it again
IncSec:
lsecs = (lsecs+1)
secs = (secs+1)
FREQOUT Speaker,10,1 ' seconds tic 1Hz for 10ms
'PAUSE DelayTime
Waiting:
GOSUB LapLedOn
GOSUB ShowTime ' show current digit
GOSUB SwitchStatus
IF secs >= SetSecs THEN TimeUp
'PAUSE DelayTime
IF tic = 0 THEN Main ' if last tic gone, go back
GOTO Waiting ' do tic check again
END
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SUBROUTINES USED IN THE PROGRAM‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐INITIALIZATION SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐LCD INITIALIZATION‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
LCDinit:
PAUSE 500 ' let the LCD settle
LCDout = %0011 ' 8‐bit mode
PULSOUT E,1
PAUSE 500
PULSOUT E,1
PULSOUT E,1
LCDout = %0010 ' 4‐bit mode
PULSOUT E,1
char = %00001100 ' disp on, crsr off, blink off
GOSUB LCDcommand
char = %00000110 ' inc crsr, no disp shift
GOSUB LCDcommand
char = ClrLCD
GOSUB LCDcommand
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐INITIALIZE VARIABLES FOR NORMAL MODE (D0)‐‐‐‐‐‐‐‐‐‐‐
IniNormMod:
GOSUB CommonIni
SetSecs = 65535
Msg = MsgD0
indexend = 15
line = Line2
GOSUB MsgDisp
line = Line1
GOTO Main
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐INITIALIZE VARIABLES FOR TIMER MODE (D1)‐‐‐‐‐‐‐‐‐‐‐‐
IniTimerMod:
GOSUB CommonIni
SetSecs = 10
Msg = MsgD1
indexend = 15
line = Line2
GOSUB MsgDisp
line = Line1
index = 5
GOTO HrsDispSet
' GOTO Main
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐COMMON INITILIZATION BETWEEN TWO MODES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
CommonIni:
FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms
GOSUB ClrAll
sflag = 0
secs = 0
lsecs = 0
lap = 1
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐INITIALIZATION FOR NEXT LAP‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
NextLap:
IF lap = MAXLAP THEN NoUpdate
FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms
segdata = LAP2
GOSUB SegDisp
PAUSE 100
GOSUB ClrLine2
line = Line2
index = 0
lap = lap+1
lsecs = 0
NoUpdate:
lflag = 1
GOTO Main
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DISPLAY SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐WRITE ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
LCDcommand:
LOW RS ' enter command mode
LCDwrite:
'char = %11000110
LCDout = char.HIGHNIB ' output high nibble
PULSOUT E,1 ' strobe the Enable line
LCDout = char.LOWNIB ' output low nibble
PULSOUT E,1
HIGH RS ' return to character mode
'GOSUB ReadSwitches
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DISPLAY DIGIT ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
DigDisp:
char = line+index ' set new DDRAM address
GOSUB LCDcommand
LOOKUP val,["0","1","2","3","4","5","6","7","8","9",":"," "],char
GOSUB LCDwrite ' write the character
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐LCD MSG WRITE‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
MsgClrDisp:
GOSUB ClrAll
MsgDisp:
FOR index = indexstart TO indexend ' get message from EEPROM
char = line + index ' set new DDRAM address
GOSUB LCDcommand
READ (Msg + index),char ' read a character
GOSUB LCDwrite ' write it
NEXT
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐CLEAR FULL LCD DISPLAY‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
ClrAll:
char = ClrLCD ' Clear the LCD
GOSUB LCDcommand
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐CLEAR LINE 1 OF LCD DISPLAY‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
ClrLine1:
Msg = Msgclr
indexend = 15
line = Line1
GOSUB MsgDisp
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐CLEAR LINE 2 OF LCD DISPLAY‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
ClrLine2:
Msg = Msgclr
indexend = 15
line = Line2
GOSUB MsgDisp
line = Line1
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DISPLAY DATA ON 7‐SEGMENT‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
SegDisp:
FOR indexMAX = 4 TO 1
READ (4 ‐ indexMAX + segdata),d7219 ' read and send letter
SHIFTOUT Dpin,ClockMAX,MSBFIRST,[indexMAX,d7219]
PULSOUT LoadMAX,3
NEXT
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SHOW TIME ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
ShowTime:
segdata = Run
GOSUB SegDisp
char = CrsrHm ' move the cursor home
GOSUB LCDcommand
index = 0
val = lap 'lap number
GOSUB DigDisp 'display ten's digit of hours
index = index +1
val = 11
GOSUB DigDisp 'display space
index = index +1
val = (lsecs/3600)/10 'ten's digit of hours
GOSUB DigDisp 'display ten's digit of hours
val = (lsecs/3600)//10 'one's digit of hours
GOSUB DigDisp 'display one's digit of hours
index = index +1
val = 10
GOSUB DigDisp 'display colon
index = index +1
val = (lsecs/60)/10 'ten's digit of minutes
GOSUB DigDisp 'display ten's digit of minutes
index = index +1
val = (lsecs/60)//10 'one's digit of minute
GOSUB DigDisp 'display one's digit of minutes
index = index +1
val = 10
GOSUB DigDisp 'display colon
index = index +1
val = (lsecs//60)/10 'ten's digit of second
GOSUB DigDisp 'display ten's digit of second
index = index +1
val = (lsecs//60)//10 'one's digit of second
GOSUB DigDisp 'display one's digit of second
index = 0
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ SPEAKER SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐TIMEUP SPEAKER RING‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
TimeUp:
secs = 0
lsecs = 0
sflag = 0
lap = 0
GOSUB LapLedOff
Msg = Msgup
indexend = 15
line = Line2
GOSUB MsgDisp
FREQOUT Speaker,2000,440,480 ' combine 440 Hz and 480 Hz
Msg = Msgreset
indexend = 9
line = Line2
GOSUB MsgDisp
PAUSE 200
line = Line1
GOTO RepeatMsg
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐START WATCH BUTTON PRESS BEEP‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
StartWatchBeep:
FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms
GOTO StartWatch
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐INVALID INPUT BEEP AND MESSAGE‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
InvalidBeepMsg:
FREQOUT Speaker,50,1000,100 ' button press tic 1000Hz/100Hz for 50ms
segdata = Invalid
GOSUB SegDisp
GOSUB ClrLine2
Msg = Msginvinp
indexend = 13
line = Line2
GOSUB MsgDisp
PAUSE 200
line = Line1
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐TIMER SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐EVALUATE SET TIME FOR TIMER‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
EvalSetTime:
' DEBUG "EvalTime", CR, DEC Switches
FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms
sflag = 1
LOOKDOWN Switches, [D0, D1, D2, D3, D4, D5, D6, D7], Switches
IF Switches = 7 THEN EvalSecs
val = Switches
index = (index + 1)
GOSUB DigDisp
SetTime = SetTime*10
LOOKUP Switches, [SetTime+0, SetTime+1, SetTime+2, SetTime+3, SetTime+4, SetTime+5, SetTime+6], SetTime
' DEBUG CR, DEC SetTime
GOTO MainSetTime
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐EVALUATE SECONDS FOR TIMER‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
EvalSecs:
SetSecs = SetSecs+SetTime*convfac
SetTime = 0
IF convfac = 3600 THEN MinDispSet
IF convfac = 60 THEN SecDispSet
IF convfac = 1 THEN MainClr
GOTO MainSetTime
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DISPLAY HOURS? ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
HrsDispSet:
Setsecs = 0
SetTime = 0
sflag = 1
segdata = HOUR
GOSUB SegDisp
' GOSUB ClrAll
GOSUB ClrLine1
Msg = Msghrs
indexend = 5
line = Line1
GOSUB MsgDisp
convfac = 3600
GOTO MainSetTime
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DISPLAY MINUTES? ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
MinDispSet:
segdata = Min7
GOSUB SegDisp
GOSUB ClrLine1
Msg = Msgmins
indexend = 7
line = Line1
GOSUB MsgDisp
convfac = 60
GOTO MainSetTime
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DISPLAY SECONDS? ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
SecDispSet:
segdata = SEC
GOSUB SegDisp
GOSUB ClrLine1
Msg = Msgsecs
indexend = 7
line = Line1
GOSUB MsgDisp
convfac = 1
GOTO MainSetTime
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐RESET FLAG FOR SETTING TIMER‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Resetsflag:
sflag = 0
GOTO Resetted
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SWITCH SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐READ SWITCH STATUS FROM 74x165.BS2‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
ReadSwitches:
PULSOUT Load,3 ' grab the switch inputs
SHIFTIN D_in,Clock,MSBPRE,[switches] ' shift them in
' DEBUG HOME, IBIN8 switches ' display binary mode
' PAUSE 100
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SWITCH STATUS WHILE WATCH IS RUNNING‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
SwitchStatus:
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 PauseWatchBeep
IF Switches = D4 THEN StopWatchBeep
IF (Switches = D5) AND (lflag = 0) THEN NextLap
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐STOP WATCH AND RESET‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
StopWatchBeep:
FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms
StopWatch:
segdata = Stop7
GOSUB SegDisp
Msg = Msgreset
indexend = 15
line = Line1
GOSUB MsgDisp
PAUSE 200
GOSUB ClrAll
lap = 0
GOTO RepeatMsg
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐PAUSE STOP WATCH‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
PauseWatchBeep:
idlecounter = 0
FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms
GOSUB LapLedOn
PauseWatch:
segdata = HALT
GOSUB SegDisp
PAUSE 100
segdata = CLEAR
GOSUB SegDisp
GOSUB ReadSwitches
IF Switches = D3 THEN StartWatchBeep
IF Switches = 0 THEN IncIdleCount
idlecounter = 0
IncIdleCount:
idlecounter = (idlecounter + 1)
'DEBUG CR, DEC idlecounter
IF idlecounter = counterMAX THEN ShutDownPause
' DEBUG CR, "RETURNED"
GOTO PauseWatch
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐POWER SAVING SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SHUTDOWN LCD & 7‐SEG FOR POWER SAVING‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
ShutDown:
SHIFTOUT Dpin,ClockMAX,MSBFIRST,[Shutdn,0] ' ShutDown 7‐Segment Display
PULSOUT LoadMAX,1
char = DispOff ' turn the LCD Off
GOSUB LCDcommand
ShutLoop:
GOSUB ReadSwitches
IF Switches <> 0 THEN Start
GOTO ShutLoop
Start:
'Switches = 0
FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms
SHIFTOUT Dpin,ClockMAX,MSBFIRST,[Shutdn,1] ' ShutDown 7‐Segment Display
PULSOUT LoadMAX,1
char = DispOn ' turn the LCD On
GOSUB LCDcommand
idlecounter = 0
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SHUTDOWN FOR REPEAT MSG‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
ShutDownRepeat:
GOSUB ShutDown
GOTO Repeat
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SHUTDOWN FOR PAUSE‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
ShutDownPause:
GOSUB ShutDown
GOTO PauseWatch
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐AUTOPOWER OFF SETTING‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
AutoPowerOff:
Msg = MsgPower
indexend = 15
line = Line1
GOSUB MsgDisp
Msg = MsgYN
indexend = 15
line = Line2
GOSUB MsgDisp
idlecounter = 0
PowerLoop:
segdata = PICK
GOSUB SegDisp
GOSUB ReadSwitches
IF Switches = D0 THEN PowerN
IF Switches = D1 THEN PowerY
PAUSE 200
segdata = CLEAR
GOSUB SegDisp
GOTO PowerLoop
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐AUTOPOWER OFF YES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
PowerY:
FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms
GOSUB ClrAll
Msg = MsgY
indexend = 2
line = Line1
GOSUB MsgDisp
counterMAX = counterPS
PAUSE 1000
GOTO RepeatMsg
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐AUTOPOWER OFF NO‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
PowerN:
FREQOUT Speaker,10,5000 ' button press tic 5000Hz for 10ms
GOSUB ClrAll
Msg = MsgN
indexend = 1
line = Line1
GOSUB MsgDisp
counterMAX = 65535
PAUSE 1000
GOTO RepeatMsg
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐LAP SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐RESET FLAG FOR LAP‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Resetlflag:
lflag = 0
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐TURN ON LAP LEDS‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
LapLedOn:
IF lap = 1 THEN Led1
IF lap = 2 THEN Led2
Led1:
LAPLED1 = 1
RETURN
Led2:
LAPLED2 = 1
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐TURN OFF LAP LEDS‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
LapLedOff:
LAPLED1 = 0
LAPLED2 = 0
RETURN
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐MISC‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SEND BACK ON INVALID INPUT‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
InvalidInput:
idlecounter = 0
GOSUB InvalidBeepMsg
GOTO RepeatMsg
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
B. Data Sheets