Write HEX to LCD

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Write HEX to LCD

Jump to solution
2,677 Views
mariaotero
Contributor II

Hello, i'm kinda new in all this world. So, i'm trying to display like decimal an hexadecimal value into a LCD 16x2 display.

I know the i need to write it in ASCII, but my problem is the i can't figure it out how to split that value into 4 or 5 bytes, for example:
0x270F = 0x39 0x39 0x39 0x39 (9999)
0xFFFF = 0x36 0x35 0x35 0x33 0x35 (65535).

 

Don't even know how to search for what i'm looking . Some guidance would be useful.

Thank you . (sorry for my bad english not my native language

 

PD: Working with S08AW32 Relocatable ASM in CodeWarrior 10.2

Labels (1)
Tags (3)
0 Kudos
Reply
1 Solution
2,324 Views
mariaotero
Contributor II

This is how i solved, any advice or critic would be nice :smileyhappy:.

;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DataRAM DS 2

Centena ds 1

Decena ds 1

Unidad ds 1

Stack ds 1

;*************************************

;DataRAM = Any value between 0 and 999

;*************************************

LDHX DataRAM

CPHX #100

BLO MENOR

BHI MAYOR

MENOR LDA DataRAM+1

LDHX #10

DIV

STA Decena

ldhx           #10

MUL

ldhx           DataRAM

JSR srAIXdc

stx          Unidad

Jsr srBCD

RTS

MAYOR            CPHX #255

BHI MAYOR2

LDA DataRAM+1

LDHX #100

DIV

rtMY1 STA Centena

LDHX #100

MUL

LDHX DataRAM

jsr srAIXct

STX Stack

LDA Stack

LDHX #10

DIV

STA Decena

ldhx           #10

MUL

ldx          Stack

JSR srAIXdc

stx          Unidad

Jsr srBCD

RTS

MAYOR2 LDA DataRAM+1

LDHX DataRAM+0

LDX #100

DIV

JMP rtMY1

;*************************************

;*************SubRoutines*************

;*************************************

srAIXct:           LDA Centena

lpAIct aix #-100

deca

cmp #0

bne lpAIct

RTS

srAIXdc:           LDA Decena

lpAIdc aix #-10

deca

cmp #0

bne lpAIdc

RTS

srBCD: LDA #$89

JSR LCDi

LDA Centena

ADD #$30

JSR LCDw

LDA Decena

ADD #$30

JSR LCDw

LDA Unidad

ADD #$30

JSR LCDw

RTS

;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View solution in original post

4 Replies
2,325 Views
mariaotero
Contributor II

This is how i solved, any advice or critic would be nice :smileyhappy:.

;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DataRAM DS 2

Centena ds 1

Decena ds 1

Unidad ds 1

Stack ds 1

;*************************************

;DataRAM = Any value between 0 and 999

;*************************************

LDHX DataRAM

CPHX #100

BLO MENOR

BHI MAYOR

MENOR LDA DataRAM+1

LDHX #10

DIV

STA Decena

ldhx           #10

MUL

ldhx           DataRAM

JSR srAIXdc

stx          Unidad

Jsr srBCD

RTS

MAYOR            CPHX #255

BHI MAYOR2

LDA DataRAM+1

LDHX #100

DIV

rtMY1 STA Centena

LDHX #100

MUL

LDHX DataRAM

jsr srAIXct

STX Stack

LDA Stack

LDHX #10

DIV

STA Decena

ldhx           #10

MUL

ldx          Stack

JSR srAIXdc

stx          Unidad

Jsr srBCD

RTS

MAYOR2 LDA DataRAM+1

LDHX DataRAM+0

LDX #100

DIV

JMP rtMY1

;*************************************

;*************SubRoutines*************

;*************************************

srAIXct:           LDA Centena

lpAIct aix #-100

deca

cmp #0

bne lpAIct

RTS

srAIXdc:           LDA Decena

lpAIdc aix #-10

deca

cmp #0

bne lpAIdc

RTS

srBCD: LDA #$89

JSR LCDi

LDA Centena

ADD #$30

JSR LCDw

LDA Decena

ADD #$30

JSR LCDw

LDA Unidad

ADD #$30

JSR LCDw

RTS

;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

2,324 Views
mariaotero
Contributor II

Sorry for not saying, but i don't know C. I can read it, but i can't code in that language.

Okay, i will try to make a project with C and ASM to see if i can debug it, to get the ASM code.

Any idea of how can i search for what i'm looking?


Thank you for the answers :smileyhappy:.

0 Kudos
Reply
2,324 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

I am not assembly code expert, but if use C, we can implement the code this way: thus D0,D1,D2,D3 is 9,9,9,9. can it help you?

//////////////////////////////////////////////////////////////////////

int ASCII(int data)

void main(void) {

volatile  int data=0x270F;

volatile  int D0,D1,D2,D3;

D0 = ASCII(data%10);

D1 = ASCII((data%100-data%10)/10);

D2 = ASCII((data%1000-data%100)/100);

D3 = ASCII((data%10000-data%1000)/1000);

}

int ASCII(int data) {

if ( (data<=9) && (data>=0))

   return (data + '0');

else

   return 1;

  

}

///////////////////////////////////////////////////


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
2,324 Views
StenS
Contributor III

The easiest (but absolutely not the most efficient) way is to use the sprintf-function:

char buff[6];

unsigned int num;

sprintf(buff, "%u", num);

After this the number will be as a null-terminated string (1..5 characters plus the terminating \0) in buff. By adding formating specifications you can affect how the number is converted.

Sten

0 Kudos
Reply