;Using 16F877
;ASCBFR is located in RAM, len= 8 for 8 digit option
;latest convert 16bit bin to 5 asci in ASCBFR0
;can be modified for 8 digits.
BIN2ASC:
CLRF ASCBFR0
CLRF ASCBFR1
CLRF ASCBFR2
CLRF ASCBFR3
CLRF ASCBFR4
CLRF ASCBFR5
CLRF ASCBFR6
CLRF ASCBFR7
MOVLW 0X18;24 bits,,,16 bits to do 5 digit
MOVWF TMPCNT1
BITLP:;shift msb into carry
RLF B2AVL,F ; this is binary value to convert lo,med,hi
RLF B2AVM,F
RLF B2AVH,F
MOVLW ASCBFR7;0=msd 1st
MOVWF FSR;fsr=pointer to digits
MOVLW 0X8;digits to do
MOVWF TMPCNT2
ADJLP:
RLF INDF,F;shift digit 1 bit left
MOVLW 0X0A
SUBWF INDF,W;check and adjust for decimal overflow
BTFSC STATUS,C
MOVWF INDF
DECF FSR,F;incf=msd 1st next digit
DECFSZ TMPCNT2,F
GOTO ADJLP
DECFSZ TMPCNT1,F;next bit
GOTO BITLP
MOVLW 0X30;make ascii option
IORWF ASCBFR0,F
IORWF ASCBFR1,F
IORWF ASCBFR2,F
IORWF ASCBFR3,F
IORWF ASCBFR4,F
IORWF ASCBFR5,F
IORWF ASCBFR6,F
IORWF ASCBFR7,F
RETURN