———
|
num2hex - convert byte to 2 hexadecimal ascii charactersConverts byte in WREG to hexadecimal “string” consisting of 2 characters - low and high. Result is written in variables hexL and hexH (which must be defined) num2hex local noAddL local noAddH movwf temp movlw 0x0F andwf temp, w addlw '0' ; 9 - WREG movwf hexL movlw '9'+1 subwf hexL, w skippz ; skip if hexL>'9': hexL - ('9'+1) >= 0 goto noAddL movlw 'A'-'9'-1 ; 65-57-1 = 7; 58+7=65 addwf hexL, f noAddL swapf temp, w andlw 0x0F addlw '0' movwf hexH movlw '9'+1 subwf hexH, w skippz ; skip if hexL>'9': hexL - ('9'+1) >= 0 goto noAddH movlw 'A'-'9'-1 ; 65-57-1 = 7; 58+7=65 addwf hexH, f noAddH return |