How to convert code for angle display using 8051 assembly?

Status
Not open for further replies.

DrWhoF

Advanced Member level 1
Joined
May 6, 2005
Messages
402
Helped
24
Reputation
48
Reaction score
11
Trophy points
1,298
Activity points
4,388
Code for angle display

I receive a string with coded angle from 0° to 360° (01h 68h). I would like to display this angle as -180° for 0° and +180° for 360°.
What will be the easiest way of converting these values using 8051 assembly?
Thanks.
DrWho
 

Re: Code for angle display

In pseudocode:
Code:
subtract 180
if negative (carry set)
  display "-"
  make complement of value
else
  optionally display "+"
endif
divide value by 100
if result > 0 display it
divide remainder by 10
if result >0 display it
display remainder
display  °
done

All of this should convert to '51 asm quite straighforwardly.

wek
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Re: Code for angle display

Try this code:
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Re: Code for angle display

Thank you very much for the code.
If I needed to move "0" by +/- 5 numbers to the left or right - to set physical zero - how much will this complicate the code?
Thanks.
DrWho
 

Re: Code for angle display

Not very much ..
If Constant is the name of number you want to add or subtract from NumberHNumberl then you can do the following:

Sbtract_Number:
CLR C
MOV A, NumberL
SUBB A, Constant
MOV NumberL, A
MOV A, NumberH
SUBB A, #00h
MOV NumberH, A
RET

Add_Number:
CLR C
MOV A, NumberL
ADDC A, Constant
MOV NumberL, A
MOV A, NumberH
ADDC A, #00h
MOV NumberH, A
RET

But first you will need to check if NumberHNumberL is bigger then Constant or smaller than 360-Constant, so bot operations can be done ..
An example on chow to check these conditions you will find in the previous post ..

Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…