8051_Div_Mul
This project shows the multiplication and division process using 8051. To simulate circuit in this project, initially activate Mixed Mode simulator from the Schematic Editor window. Simulation can be performed by selecting Run Transient analysis (Oscillograph) from Simulation menu.
The circuit contains an 8051 chip and a voltage source. Port P0 and P2 of 8051 are used for displaying the result. A ‘Low’ state at Port 0.0 invokes Multiplication while a ‘High’ state invokes Division. The data at Ports P1 and P3 can be edited as required.
If the state at P0.0 is ‘Low’, then the data at Port P3 is multiplied with the data at Port P1. Port 3 data will be divided by Port 1 data when the state at P0.0 is ‘High’.
The final result appears at the ports, P0 and P2.
The source code written either in C or Assembly The source code written either in C or Assembly language can be viewed from the
code editor window
The program is as shown
_main;
mov p0,#0x0ff ; Port P0 is assigned as input port.
mov a,p0 ; The current value at Port P0 is copied to Accumulator
subb a,#0x01 ; Subtract the value ‘01’ from the Accumulator content
jz loop ; Check whether the difference s zero. If zero, jumps to loop
mov a, p3 ; Data at Port P3 is copied to Accumulator
mov b,p1 ; Data at Port P1 is copied to register ‘B’
mul ab ; Multiply Accumulator content with the data in register ’B’
sjmp skip ; Jump to ‘skip’
loop:
mov a, p3 ; Data at Port P3 is copied to Accumulator
mov b,p1 ; Data at Port P1 is copied to register ‘B’
div ab ; Divide Accumulator content with the data in register ’B’
skip:
mov p0,#0x00 ; Port P0 is assigned as output port.
mov p0,a ; The content of Accumulator is copied to Port P0
mov p2,b ; The content of register ‘B’ is copied to Port P2
The source code in the
code editor window
has to be
compiled
after making any modifications
(editing).
Also the code can be
debugged
during
simulation.