;*******************************************************
;*                 Code Produced by the                *
;*             PROTON+ Compiler. Version 3.01          *
;* Copyright Rosetta Technologies/Crownhill Associates *
;*              Written by Les Johnson. 2004           *
;*******************************************************
 NOLIST
 #include "C:\PICBASIC\KEY-ENCODER.PBP"
 LIST

 TEMP = 55
 KEYPAD = 56
	#Define BEEP PORTA,6
	#Define PAR_INT PORTA,7
	#Define SER_INT PORTA,1
	#Define SWITCH PORTA,4
	#Define RS232OUT PORTA,0
F1_SOF equ $ ; KEY-ENCODER.BAS
F1_000004 equ $ ; in [KEY-ENCODER.BAS] CONFIG INTRC_OSC_NOCLKOUT, CP_OFF, WDT_OFF, PWRTE_ON, LVP_OFF
F1_000005 equ $ ; in [KEY-ENCODER.BAS] Delayms 200                        ; stabilize
	Movlw 200
	Call dl@ms
F1_000006 equ $ ; in [KEY-ENCODER.BAS] all_digital = true
	Movlw 7
	Movwf CMCON
F1_000007 equ $ ; in [KEY-ENCODER.BAS] PORTB_PULLUPS = TRUE
	Bsf STATUS,5
ram_bank = 1
	Bcf OPTION_REG,7
F1_000017 equ $ ; in [KEY-ENCODER.BAS] trisa=%00010000
	Movlw 16
	Movwf TRISA
F1_000018 equ $ ; in [KEY-ENCODER.BAS] porta=255
	Bcf STATUS,5
ram_bank = 0
	Movlw 255
	Movwf PORTA
LOOP
F1_000022 equ $ ; in [KEY-ENCODER.BAS] repeat                          ; wait until a key is pressed
bc@LL1
F1_000023 equ $ ; in [KEY-ENCODER.BAS] temp = inkey
	Call Inkey
	Movwf TEMP
F1_000024 equ $ ; in [KEY-ENCODER.BAS] until temp<>16
	Movlw 16
	Subwf TEMP,W
	Btfsc STATUS,2
	Goto bc@LL1
bc@LL2
F1_000025 equ $ ; in [KEY-ENCODER.BAS] keypad = lookup temp, [138,128,139,255,135,136,137,255,132,133,134,255,129,130,131]  ;conversion to 'true' bin-values
	Movf TEMP,W
	Sublw 14
	Btfss STATUS,0
	Goto Le@lb1
	Call l@lb3
	Movwf KEYPAD
	Goto Le@lb1
l@lb3
	Movlw high lk@lb2
	Movwf PCLATH
	Movf TEMP,W
	if($ >> 8) != (($ + 15) >> 8)
	Goto so@lb3
	Org (($ + 255) & 65280)
so@lb3
	endif
	Addwf PCL,F
lk@lb2
	Retlw 138
	Retlw 128
	Retlw 139
	Retlw 255
	Retlw 135
	Retlw 136
	Retlw 137
	Retlw 255
	Retlw 132
	Retlw 133
	Retlw 134
	Retlw 255
	Retlw 129
	Retlw 130
	Retlw 131
Le@lb1
F1_000027 equ $ ; in [KEY-ENCODER.BAS] if switch = 0 then              ; read jumper setting
	Btfsc PORTA,4
	Goto bc@LL5
F1_000028 equ $ ; in [KEY-ENCODER.BAS] porta = keypad              ; send true-value to portA
	Movf KEYPAD,W
	Movwf PORTA
F1_000029 equ $ ; in [KEY-ENCODER.BAS] pulsout par_int, 100, low       ; interrupt pulse 1 ms.
	Clrf PP0H
	Movlw 100
	Movwf PP0
	Bsf STATUS,5
ram_bank = 1
	Bcf TRISA,7
	Bcf STATUS,5
ram_bank = 0
	Bsf PORTA,7
	Movlw 5
	Movwf FSR
	Movlw 128
	Call p@out
	Goto bc@LL6
bc@LL5
F1_000030 equ $ ; in [KEY-ENCODER.BAS] else
F1_000031 equ $ ; in [KEY-ENCODER.BAS] keypad = keypad - 128
	Movlw 128
	Subwf KEYPAD,F
F1_000032 equ $ ; in [KEY-ENCODER.BAS] pulsout ser_int, 100, low       ; interrupt pulse 1 ms.
	Clrf PP0H
	Movlw 100
	Movwf PP0
	Bsf STATUS,5
ram_bank = 1
	Bcf TRISA,1
	Bcf STATUS,5
ram_bank = 0
	Bsf PORTA,1
	Movlw 5
	Movwf FSR
	Movlw 2
	Call p@out
F1_000033 equ $ ; in [KEY-ENCODER.BAS] serout rs232out, 16486, [ keypad ]   ; send data serial to portA.0. 8 bits, 9600 baud, no parity
	Movlw PORTA
	Movwf GEN
	Movlw 1
	Movwf GENH
	Movlw 64
	Movwf PP5H
	Movlw 102
	Movwf PP5
	Clrf GEN3H
	Clrf GEN3
	Movlw 32
	Movwf BPFH
	Movf KEYPAD,W
	Call Serout
F1_000034 equ $ ; in [KEY-ENCODER.BAS] end if
bc@LL6
F1_000036 equ $ ; in [KEY-ENCODER.BAS] sound beep, [115,9]             ; short beep at every keypress + debounce
	Movlw PORTA
	Movwf GEN
	Movlw 64
	Movwf GENH
	Movlw 115
	Movwf PP1
	Movlw 9
	Call Noise
F1_000038 equ $ ; in [KEY-ENCODER.BAS] repeat                          ; wait until key is released
bc@LL7
F1_000039 equ $ ; in [KEY-ENCODER.BAS] temp=inkey
	Call Inkey
	Movwf TEMP
F1_000040 equ $ ; in [KEY-ENCODER.BAS] until temp = 16
	Movlw 16
	Subwf TEMP,W
	Btfss STATUS,2
	Goto bc@LL7
bc@LL8
F1_000041 equ $ ; in [KEY-ENCODER.BAS] porta = 255                     ; send initial value to portA
	Movlw 255
	Movwf PORTA
F1_000043 equ $ ; in [KEY-ENCODER.BAS] goto loop
	Goto LOOP
F1_EOF equ $ ; KEY-ENCODER.BAS
	END

