Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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:
; Bit NumBelow180 is set when NumberHNumberL<180 and cleared if NumberHNumberL>180

Angle_Display: CLR C ; 01h 68h = 360d
MOV A, NumberH
CJNE A, #01h, Not_1 ; #01h
NOP ; NumberH = 01h
SJMP Check_Cont3
Not_1: JC Check_Cont1 ; NumberH < 01h
LJMP Set_Number ; NumberH > 01h
Check_Cont1: CLR C
MOV A, NumberL
CJNE A, #68h, Not_68 ; #68h
CLR C ; Number = 68h
SJMP Check_Cont2
Not_68: JC Check_Cont2 ; NumberL < 68h
Check_180: CLR C ; NumberL > 68h
MOV A, NumberL
CJNE A, #0B4h, Not_B4
CLR C ; NumberL = 180d
SJMP Check_Cont3
Not_B4: JC Check_Cont2 ; NumberL < 180d
More_180: CLR NumBelow180 ; NumberL > 180d
SJMP Check_Cont3

Check_Cont2: SETB NumBelow180
MOV Tmp0, #0B4h ; Number=180-Number Sign=-
MOV Tmp1, #00h
MOV Op0, NumberL
MOV Op1, #00h
SJMP Check_Cont4

Set_Number: MOV NumberL, #68h
MOV NumberH, #01h

Check_Cont3: MOV Tmp0, NumberL ; Number=Number-180 Sign=+
MOV Tmp1, NumberH
MOV Op0, #0B4h
MOV Op1, #00h

Check_Cont4: CLR C
MOV A, Tmp0
SUBB A, Op0
MOV NumberL, A
MOV A, Tmp1
SUBB A, Op1
MOV NumberH, A
RET
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top