Code:
; check for pressed Mode switch
	
CHK_MDE	bsf	PORTA,1		; RA1 high so disp2 off
	bsf	PORTA,2		; RA2 high so disp3 off
	nop
	nop
	bcf	PORTA,0		; clear RA0 to check if mode switch pressed
	nop
	nop
	btfsc	PORTA,4		; is mode switch pressed
	goto	NO_OPEN		; switch open so no change
	btfss	REPEAT,3	; test for speedo on/off flag bit 3	
	goto	CLRSPED		; clear speedo on/off 
	bcf	REPEAT,3	; set speedo
	movlw	B'01001000'	; 's' on display for speedo
	movwf	TEMP_1
	goto	MODEOPN
CLRSPED	bsf	REPEAT,3	; set speedo on/off flag
	movlw	B'01111110'	; '-' on display for no speedo
	movwf	TEMP_1
	bcf	REPEAT,2	; clear speedometer flag
MODEOPN	bsf	PORTA,2		; display off
	bsf	PORTB,5		; clear a segment
	bsf	PORTB,1		; clear c segment
	bsf	PORTB,2		; d segment
	bsf	PORTB,4		; f segment
	bsf	PORTB,7		; g segment
	bcf	PORTA,0		; clear RA0 to check if mode switch pressed
	call	DELMO		; more delay time (multiplex time)
	call	DELMO		; more delay time 
	btfsc	PORTA,4		; wait for switch to open
	goto	MODESTO		; store repeat setting when switch open

; multiplex display until switch opens

	bsf	PORTA,0		; RA0 high
	nop
	nop
	nop
	bcf	PORTA,2		; RA2 low so display 1 lit
	movf	TEMP_1,w
	movwf	PORTB		; 
	call	DELMO		; more delay time (multiplex)
	goto 	MODEOPN

; delay period for multiplex rate

DELMO	movlw 	D'255'		; delay period
	movwf	TEMP_2
SMALR	decfsz	TEMP_2,f	; reduce temp_2
	goto	SMALR		; temp_2 smaller by 1
	return			; end delay

; write new mode option to EEPROM4

MODESTO	movlw	EEPROM4		; address for EEPROM4
	movwf	EEADR		; address for write
	movf	REPEAT,w	; flag stored
	call	EWRITE		; write to EEPROM
	
; calculate speed equivalent value

NO_OPEN	call	SPDEQIV		; calculate speed equivalent
	goto	INT_SET
	
; subroutine to read EEPROM memory

EEREAD	movwf 	EEADR		; indirect special function register
	bsf 	STATUS,RP0	; select memory bank 1
	bsf	EECON1,RD	; read EEPROM
RD_RD	nop
	btfsc	EECON1,RD	; skip if RD low (read complete)
	goto 	RD_RD		; wait for low RD (read RD)	
	bcf	STATUS,RP0	; select bank 0
	movf	EEDATA,w	; EEPROM value in w
	return

; subroutine to calculate speed equivalent of 8 per 5km/h this value is compared with 
; counted pulses from speed sensor.  
	
SPDEQIV	bcf	FLAG_1,5	; overspeed flag
	bcf	FLAG_1,4	; clear alarm off flag
	clrf	PULSE_CNT	; clear pulse counter
	clrf	TIME_CNT1	; clear time counter 1
	clrf	TIME_CNT2	; clear time counter 2 	
	bsf	PORTA,3		; alarm output high 
	clrf	SPEED_EQV	; clear speed equivalent store

; Convert the display readings to a binary speed equivalent value	

	movf	DISP3,w		; look at DISP3 value
	btfsc	STATUS,z	; check if 0
	goto 	ZERO
	xorlw	0x01		; check if a 1
	btfsc	STATUS,z	; z is 1 if a 1
	goto	ONE		; 
	movlw	D'100'		; 100
	movwf	SPEED_EQV	; 100 in speed equivalent
ONE	movlw	D'100'
	addwf	SPEED_EQV,f	; 200 if disp3 was a 2
ZERO	movf	DISP2,w		; look at display 2
	movwf	TEMP_X		; place in temporary register
INC_SE	movlw	D'10'		; 10
	addwf	SPEED_EQV,f	; increase speed equivalent by 10		
	decfsz	TEMP_X,f	; reduce disp2 value
	goto	INC_SE		; do again
	movf	DISP1,w		; display 1 value
	addwf	SPEED_EQV,f	; add display 1 value 		 
	return

	
; allow interrupts

INT_SET	btfss	REPEAT,1	; bit 1 on/off flag
	goto	RB0_INT		; no RB0 interrupt if speed alarm unit in off mode
	bsf	INTCON,INTE	; set interrupt enable for RB0
RB0_INT	bsf	INTCON,T0IE	; set interrupt enable for TMR0 
SWITCH	bsf	INTCON,GIE	; set global interrupt enable for above

; check if a switch is pressed

	bcf	FLAG_1,0	; clear multiplex update flag
MULTIP	btfss	FLAG_1,0	; check if multiplex update occured
	goto	MULTIP		; wait for new multiplex update for display
	btfsc	PORTA,4		; if a switch is pressed, then bit 4 will be low
	goto	SWITCH		; no switch pressed so look again
	
; check for Cal switch

	bcf	INTCON,GIE	; clear interrupts
	bcf	ERR_FLG,0	; clear error flag when any switch pressed
	movf	PORTA,w		; look at RA0-RA2
	
	movwf	TEMP_1		; store in temporary memory
	iorlw	B'00000111'	; bit 0-2 high
	movwf	PORTA		; place in port A, displays off
	
	movlw	0x1F		; delay period
	movwf	VALUE_1		; VALUE_1 = w
DELOOP	decfsz	VALUE_1,f	; decrease VALUE_1, skip if zero
	goto	DELOOP	

	btfss	PORTA,4		; is the cal switch pressed
	goto 	CALIBRT		; yes it is the cal switch
	movf	TEMP_1,w	; retrieve port A bit 0-2
	movwf	PORTA		; port A bits 0-2 as before
	nop			; give time for ports to change
	nop
	nop
	btfsc	PORTA,4		; if a switch is pressed, then bit 4 will be low
	goto	SWITCH		; no switch pressed so look again
	btfsc	PORTA,0		; is it the mode switch	
	goto	D_U_CHK
	goto 	MODE
D_U_CHK	btfss	REPEAT,1	; is on/off flag on
	goto	WAIT		; no up down selection allowed when speed alarm unit is off
	btfsc	PORTA,1		; is it the Down switch
	goto	U_CHK
	goto	DOWN
U_CHK	btfsc	PORTA,2		; is it the UP switch
	goto	SWITCH		; no switch reading
	goto 	UP