Bin to decimal

Bin to decimal

Post by Peter Pohlman » Tue, 16 Sep 2003 15:38:05



Hi Guys,

I am new to this. How to convert an 8 bit binary value to a decimal value
for an HC11 ?

Thanks

 
 
 

Bin to decimal

Post by Everett M. Gree » Tue, 16 Sep 2003 20:38:14



> I am new to this. How to convert an 8 bit binary value to a decimal value
> for an HC11 ?

The following appeared in another newsgroup today...


> Newsgroups: comp.realtime
> Subject: Need help with HC11 Display

> Gurus,

> I am a * and need some help here. I want to display the content of a
> location on the LCD Display. Please have a look at the code and help me.
> With the current progra the problem is that it displays correctly the value
> at the first
> 2 postions of the display, but after these positions there is junk
> displayed.

> Below is the relevant code. IT is for an HC11

> LDA #$01 ;CLEAR AND HOME
> BSR WCTRL ;WRITE CONTROL BYTE TO LCD
> LDA #%11111111 ; load something.. in this case the display should show FF
> JSR BIN2ASC ; convert bin2ascii
> STD 0,X

  CLR 2,X                       <-- won't work without this

- Show quoted text -

Quote:> BSR LCDTEXT ; show it
> SWI ; break here for now

> ***************************************************
> * SEND A LINE OF TEXT TO LCD
> * PASS START ADDRESS OF TEXT IN X
> * TEXT STRING TERMINATED BY $00 OR $04
> ***************************************************
> LCDTEXT PSHA
> LCD LDAA 0,X ;GET BYTE FROM MESSAGE TABLE
> CMPA #$00 ;Check for end of string         <-- instruction not needed
> BEQ DLCD ;$00 OR $04
> CMPA #$04
> BEQ DLCD
> BSR WDAT ;SEND CHARACTER TO LCD
> INX
> BRA LCD
> DLCD PULA
> RTS

> ********************************************
> ******* BIN TO ASCII ************
> ********************************************
> *Converts 8 bit binary value in ACCA to ACII
> *PASSED : Binary value in ACCA
> *RETURNS: ASCII in D
> *EFFECTS: ACCB is destroyed
> ********************************************
> HEX_TABLE FCC "0123456789ABCDEF" ; Table for conversion values

> BIN2ASC PSHA ; Save a copy of the input number on the stack
> TAB ; Copy into ACCB
> ANDB #%00001111 ; Strip the upper nibble of ACCB
> CLRA ; D now contains 000n where n is the LS nibble
> ADDD #HEX_TABLE ; setup for indexed load
> XGDX
> LDA 0,X ; GEt the LSnibble Character
> PULB ; retrieve the input number into ACCB
> PSHA ; put the LSNIBBLE into place
> RORB ; Move the upper * into of the input number
> RORB ; into the llower position
> RORB
> RORB
> ANDB #%00001111 ; strip off the upper *
> CLRA ; D now contains 000n where n is the msnibble
> ADDD #HEX_TABLE
> XGDX
> LDAA 0,X ; Get the MSnibble character in ACCA
> PULB ; retrieve the LSnibble character into ACCB
> RTS