; This is a programme for driving the beep test circuitry.
#PICAXE 14M2
#TERMINAL 38400
; Define the PICAXE port directions.
LET dirsB = %00111111 ; [0] is serial data output,
; [1..4] are BCDDa[0..3],
; [5] is the audio output to the loudspeaker.
LET dirsC = %00010100 ; [0] is the SETUP select DOWN input,
; [1] is the SETUP select UP input,
; [2] is the LED0 data strobe signal,
; [3] is the SETUP / RUN input,
; [4] is the LED1 data strobe signal,
; [5] is the serial data input.
; Define the input and output signals.
SYMBOL AudioPin = B.5
SYMBOL SelDownPin = pinC.0
SYMBOL SelUpPin = pinC.1
SYMBOL SetRunPin = pinC.3
SYMBOL Strobe0 = outpinC.2
SYMBOL Strobe1 = outpinC.4
; Define the registers.
SYMBOL Exercise = b4
SYMBOL DataLocStart = b5
SYMBOL DataLocStop = b6
SYMBOL DataPointer = b7
SYMBOL SecondsCounter = b8
SYMBOL StepCounter = b9
SYMBOL BeepCounter = b10
SYMBOL Temp02 = b26
SYMBOL Temp01 = b27
; The exercise to be run is stored in EEPROM at location 0. By default, this is
; set to 1.
EEPROM 0, (1)
; The next set of memory locations hold the starting memory location for the
; data for the exercise number that matches the memory location in this set.
; For example, memory location 1 holds the starting location of the data for
; exercise number 1. The final location for each set of data is deduced from
; the starting point of the following set of data, and so this information must
; be included even if there are no data.
EEPROM 1, (10)
EEPROM 2, (30)
; The remaining memory locations hold the actual data values for each of the
; exercises. These are always stored in pairs of values, first the length of
; each run in seconds and secondly the number of times that have to be completed
; before moving on to the next set of data.
EEPROM 10, (20, 2, 15, 2, 12, 4, 10, 6, 9, 6, 8, 7, 7, 8, 6, 10, 5, 12, 4, 15)
; A sub-routine to send the contents of a register to the two digit display.
; Leading zeroes are blanked.
#MACRO OutputValue(Reg)
LET b0 = Reg // 10
SendDigit(Strobe0)
IF Reg > 9 THEN
LET b0 = Reg / 10
ELSE
LET b0 = 0x1F
ENDIF
SendDigit(Strobe1)
#ENDMACRO
; This is the sub-routine that does the actual physical sending of a
; digit to the display. The strobe is active low, and there is a very
; wide margin for the timing.
#MACRO SendDigit(Strb)
LET outpinB.1 = bit0
LET outpinB.2 = bit1
LET outpinB.3 = bit2
LET outpinB.4 = bit3
PAUSEUS 1
LET Strb = 0
PAUSEUS 10
LET Strb = 1
PAUSEUS 1
#ENDMACRO
; The main part of the programme consists of first selecting a set of sequences,
; and then secondly running that set of sequences, the whole lot being set in an
; infinite loop.
DO
; First the set up phase. Select the programme to run.
setup:
READ 0, Exercise
SETINT OR 0x00, 0x03 ; Comment out this line for the mixed signal simulation.
DO WHILE SetRunPin = 0
WRITE 0, Exercise
OutputValue(Exercise)
LOOP
; The exercise has been selected, now run it. Start by disabling the interrupts
; and clearing the number of beeps.
SETINT OFF
LET BeepCounter = 0
OutputValue(BeepCounter)
; Next, get the start and stop points of the data to use.
READ Exercise, DataLocStart, DataLocStop
LET DataLocStop = DataLocStop - 2
; Send out three beeps warning that the test is about to start...
SOUND AudioPin, (125, 50)
PAUSE 250
SOUND AudioPin, (125, 50)
PAUSE 250
SOUND AudioPin, (125, 50)
PAUSE 500
; ... and then the start beep proper.
SOUND AudioPin, (90, 80)
; Now start the main looping.
FOR DataPointer = DataLocStart TO DataLocStop STEP 2
READ DataPointer, SecondsCounter, StepCounter
FOR Temp01 = 1 TO StepCounter
FOR Temp02 = 1 TO SecondsCounter
IF SetRunPin = 0 THEN
GOTO setup
ENDIF
PAUSE 1000
NEXT Temp02
SOUND AudioPin,(100, 80)
LET BeepCounter = BeepCounter + 1
OutputValue(BeepCounter)
NEXT Temp01
NEXT DataPointer
LOOP
; The interrupt is active only when the SetRunPin is low, i.e. for selectimg
; the test.
interrupt:
IF SelDownPin = 0 THEN
LET Exercise = Exercise - 1 MIN 1
ENDIF
IF SelUpPin = 0 THEN
LET Exercise = Exercise + 1 MAX 9
ENDIF
PAUSE 750 ; Crappy SW de-bounce filter. If no good, go back to HW solution.
SETINT OR 0x00, 0x03
RETURN