;   0x08	The ambient light sensor threshold
;---------------------------------------------------------------------------------------------

    ERRORLEVEL -302 ;remove message about using proper bank

;***** Declarations and microcontroller configuration *****
    PROCESSOR 16f88
    #include "p16f88.inc"
    __CONFIG _CONFIG1, _CP_OFF&_DEBUG_OFF&_WRT_PROTECT_OFF&_CPD_OFF&_LVP_OFF&_BODEN_ON&_MCLR_OFF&_PWRTE_ON&_WDT_OFF&_INTRC_IO
    __CONFIG _CONFIG2, _IESO_OFF&_FCMEN_OFF

;***** Declaration of variables *****
    cblock 0x20     ; Beginning of RAM in bank 0
    AMBIENT0        ; The AMBIENT0-F array MUST be aligned on a 16 byte boundary
    AMBIENT1        ; AMBIENT0-F hold the A/D results for the last 16 A/D conversions
    AMBIENT2        ;    of the ambient light sensor
    AMBIENT3
    AMBIENT4
    AMBIENT5
    AMBIENT6
    AMBIENT7
    AMBIENT8
    AMBIENT9
    AMBIENTA
    AMBIENTB
    AMBIENTC
    AMBIENTD
    AMBIENTE
    AMBIENTF
    AMBIENTIX       ; Index to the current AMBIENT address, used for indirect addressing
    AMBIENTSUML     ; Low order byte of the sum of the above 16 ambient samples
    AMBIENTSUMH     ; High order byte of the sum of the above 16 ambient samples
    AMBIENTAVG      ; Average of the 16 array entries above
    AMBIENTTHRESH   ; The level at which the display intensity should be lowered
    TEMP            ; Various temporary use
    VSSINTS         ; Counts the interrupts that result from the VSS square wave
    VSSINT          ; An internal (software) interrupt prescaler, boolean 0x00=no int, 0xff=int
    TMR0_1          ; Holds the first copy of the Timer0 counter
    TMR0_2          ; Holds the second copy of the Timer0 counter
    NUMGEARS        ; The number of gears
    GEAR            ; Holds the gear number to be displayed on the seven segment LED display
    GEAR2           ; Holds the gear number, used as a count down loop counter
    THRESH1         ; Retrieved from EEPROM, holds the "learned" number of IPG cycles for 1st gear
    THRESH2         ; Retrieved from EEPROM, holds the "learned" number of IPG cycles for 2nd gear
    THRESH3         ; Retrieved from EEPROM, holds the "learned" number of IPG cycles for 3rd gear
    THRESH4         ; Retrieved from EEPROM, holds the "learned" number of IPG cycles for 4th gear
    THRESH5         ; Retrieved from EEPROM, holds the "learned" number of IPG cycles for 5th gear
    THRESH6         ; Retrieved from EEPROM, holds the "learned" number of IPG cycles for 6th gear
    PAUSEH          ; Used by the Pausems routine, holds the high order byte of the number ms
    PAUSEL          ; Used by the Pausems routine, holds the low order byte of the number ms
    LOOPCOUNT       ; Used by various routines, as a loop counter 
    IPGSUML         ; Low order bye of the sum of IPG pulses
    IPGSUMH         ; High order bye of the sum of IPG pulses
    endc

    cblock 0x70     ; Beginning of RAM memory common to all banks
    W_TEMP          ; Temporary storage of the W register, used by the interrupt service routine
    STATUS_TEMP     ; Temporary storage of the STATUS register, used by the interrupt service routine
    endc

;***** Declaration of symbol equates *****
LEARNBTN        equ 6           ; PORTA, pin RA6, has the "Learn" mode pushbutton
NEUTRALSW       equ 0           ; PORTA, pin RA0, has the Neutral switch input
CLUTCHSW        equ 1           ;