Code Conversion in 8085 Microprocessor

16,771 views 18 slides Sep 21, 2018
Slide 1
Slide 1 of 18
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18

About This Presentation

Code conversion types with programs


Slide Content

CODE CONVERSION IN 8085 MICROPROCESSOR MADE BY MOHIT AGARWAL – (161080107026) 5 TH SEM COMPUTER

INTRODUCTION Code conversion allows user to translate a number that is representated using one coding system to other coding system. The code conversion involves operations like : Binary to BCD BCD to Binary BCD to Hex Hex to BCD BCD to Seven Segment Binary to ASCII ASCII to Binary

BCD TO BINARY CONVERSION The microprocessor understands the binary/hex number system. To convert BCD number into its binary equivalent we need to use the principle of positional weighting in a given number. EXAMPLE : (2 Digit BCD to Binary) 60 = 6 x 0A H + 0 60 = 3C H + 0 60 = 3C H

PROGRAM         LDA 2200H               : Get the BCD number         MOV B, A                 : Save it         ANI OFH                 : Mask most significant four bits       MOV C, A             : Save unpacked BCD 1 in C register     MOV A, B             : Get BCD again         ANI FOH               : Mask least significant four bits         RRC                       : Convert most significant four bits into unpacked BCD 2         RRC         RRC         RRC         MOV B, A                 : Save unpacked BCD 2 in B register         XRA A                        : Clear accumulator (sum = 0)         MVI D, 0AH            : Set D as a multiplier of 10 SUM:ADD D                 : Add 10 until (B) = 0         DCR B                        : Decrement BCD2 by one         JNZ SUM                 : Is multiplication complete? If not, go back and add again         ADD C         : Add BCD 1         STA 2300H                : Store the result         HLT                         : Terminate program execution INPUT : 2200 H : 60 H OUTPUT : 2300 H : 3C H

BINARY TO BCD CONVERSION The microprocessor processes data in binary form but data that is displayed is in BCD form. Hence, we require to convert the Binary data to BCD. The series of operations to be performed is represented here using a flowchart.

Source Program:        LXI SP, 27FFH                       : Initialize stack pointer        LDA 6000H                           : Get the binary number in accumulator        CALL SUBROUTINE              : Call subroutine        HLT                                        : Terminate program execution Subroutine to convert binary number into its equivalent BCD number:        PUSH B                 : Save BC register pair contents        PUSH D                 : Save DE register pair contents        MVI B, 64H                 : Load divisor decimal 100 in B register        MVI C, 0AH                 : Load divisor decimal 10 in C register        MVI D, 00H                 : Initialize Digit 1        MVI E, 00H                 : Initialize Digit 2 PROGRAM

STEP1:CMP B                 : Check if number < Decimal 100         JC STEP 2                 : if yes go to step 2         SUB B                       : Subtract decimal 100         INR E                       : update quotient         JMP STEP 1             : go to step 1 STEP2:CMP C                 : Check if number < Decimal 10         JC STEP 3                 : if yes go to step 3         SUB C                         : Subtract decimal 10         INR D                         : Update quotient         JMP STEP 2               : Continue division by 10 STEP3:STA 6100H                 : Store Digit 0         MOV A, D                 : Get Digit 1         STA 6101H                 : Store Digit 1         MOV A, E                 : Get Digit 2         STA 6102H                 : Store Digit 2         POP D                 : Restore DE register pair         POP B                         : Restore BC register pair         RET                         : Return to main program INPUT : 3040 H : 8A H OUTPUT : 3041 H : 08 H 3042 H : 03 H 3043 H : 01 H

BINARY TO ASCII CONVERSION The ASCII (American Standard Code for Information Interchange) is used for communication purposes. Hence, it is necessary to convert Binary number to its ASCII equivalent.

Source program:         LXI SP, 27FFH         : Initialize stack pointer         LXI H, 2000H         : Source memory pointer         LXI D, 2200H         : Destination memory pointer       MVI C, O5H               : Initialize the counter BACK: MOV A, M                 : Get the number         CALL ASCII                 : Call subroutine ASCII         STAX D                 : Store result         INX H                         : Increment source memory pointer         INX D                         : Increment destination memory pointer         DCR C                 : Decrement count by 1                 CJNZ                         : If not zero, repeat         HLT                         : Stop program execution a PROGRAM

Subroutine ASCII: ASCII:CPI, OAH                : Check if number is OAR         JNC NEXT               : If yes go to next otherwise continue         ADI 30H         JMP LAST NEXT:ADI 37H LAST:RET                         : Return to main program INPUT :  (2000H) = 1 (2001H) = 2 (2002H) = 9 (2003H) = A (2004H) = B OUTPUT : (2200H) = 31 (2201H) = 32 (2202H) = 39 (2203H) = 41 (2204H) = 42

ASCII TO BINARY CONVERSION Steps for ASCII to Binary code conversion : If ASCII code is less than 3A H then 30 H is subtracted from the number to get its Binary Equivalent. If the number is between 41 H and 5A H then 37 H is subtracted to get the binary equivalent of the letter A-F. EX: 41 H (ASCII) = 41 H - 37 H = 04 H (BINARY)

BCD TO HEX CONVERSION Steps for BCD to HEX code conversion : We get the value from the user. Then we take the Most Significant Digit (MSD). We multiply MSD by 10, using repeated addition. Then we add the Least Significant Digit (LSD) to the result obtained in previous step. And finally the value is stored in the next memory location.

PROGRAM LXI H,0030H : Get the BCD number MOV A,M : Initialize the memory Pointer ADD A : Value in accumulator is doubled MOV B,A : Value in accumulator is moved to register B ADD A : Value in accumulator is doubled again ADD A : Value in accumulator is doubled again ADD B : Value in Register B is added to accumulator (A is 10 x MSD of the BCD stored at 0030H) INX H : Point to LSD ADD M : LSD is added to accumulator INX H Next location is pointed MOV M,A : Value obtained is stored here HLT : Terminate the program INPUT : 0030 H : 02 H 0031 H : 09 H OUTPUT : 0032 H : 1D H

HEX TO BCD CONVERSION Steps for HEX to BCD code conversion : We get the HEX number from user. Then shift the hexadecimal number to C register. We perform repeated addition for C number of times. And adjust for BCD count in each step. Now the BCD value obtained is stored in memory.

LXI H,0030H : Get the HEX number MOV C,M : Shift the number to C register LOOP1: ADI 01H : Start a loop of repeated addition for C times DAA : Adjust for BCD count JNC LOOP2 : Start another loop for Higher order number INR D LOOP2: DCR C : Decrease C till it reaches Zero JNZ LOOP1 STA 0051H : Store the Lower order here MOV A,D : Move the Higher order value to accumulator STA 0050H : Store the Higher order here HLT PROGRAM INPUT : 0030 H : 1D H OUTPUT : 0050 H : 02 H 0051 H : 09 H

BCD TO SEVEN SEGMENT CONVERSION The seven segment LCD display is used for displaying the results in a microprocessor based system. In such cases we need to convert the results in the seven segment code. Such conversion can be obtained with a look-up table. DIGIT CODE 3F 1 06 2 5B 3 4F 4 66 5 6D 6 7D 7 07 8 7F 9 6F

LXI H, 6200H  : Initialize lookup table pointer  LXI D, 6000H  : Initialize source memory pointer  LXI B, 7000H  : Initialize destination memory pointer  BACK: LDAX D  : Get the number  MOV L, A  : A point to the 7-segment code MOV A, M  : Get the 7-segment code STAX B  : Store the result at destination memory location INX D  : Increment source memory pointer  INX B : Increment destination memory pointer  MOV A, C  CPI O5H : Check for last number  JNZ BACK  : If not repeat  HLT : End of program PROGRAM

THANK YOU