8051_Biggest_Numb
This 8051 project is used to find the biggest number from a set of numbers stored in external memory. 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, 128K x 8-Bit CMOS One Time PROM, Buffer Register, Binary to 7- Segment Decoder and 7-Segment LED Display. In this circuit Port P1 of 8051 is used as the output port while the ports P0 and P2 are used for memory addressing.
The address of the memory location is send to the memory via latch from the address lines of 8051. The content of this location is loaded to accumulator and is compared with the register, which is assigned to store the biggest value. The number of memory locations to be compared is specified in the code. For each comparison, the data pointer is incremented so as to point to the next memory location. The biggest number obtained after all the comparisons will be available in the register and this value is copied to port P1. The value at Port P1 is send to the Binary to 7- Segment Decoders and the result is displayed in
7-segment form.
The
code editor window
contains the source code written in either C or assembly language.
The program is as shown:
mov b,#0x00 ; Register B that is assigned to store the biggest value is initialised with ‘00’.
mov r0,#11 ; Register R0 is initialised with value ‘11’.Here this register works as a counter
mov dptr,#0x000 ; Data pointer is loaded with the starting address ‘0000’.
rep:
movx a,@dptr ; Reads the content of the external memory location pointed by data pointer and is copied to Accumulator
cjne a,b,loop ; Compares Accumulator with register B and jumps to label ‘loop’ if they are
not equal jumps to label ‘loop’.
; If the accumulator content is smaller than the content of b register, then CY
flag is set.
; If the accumulator content is greater than the content of b register, then CY
flag is reset.
loop:
jnc skip ; Checks whether there is carry, if CY flag is not set, jumps to label ‘skip’
sjmp last ; Jumps to label ‘last’
skip:
mov b,a ; Accumulator content is copied to register B.
last:
inc dptr ; Data pointer is incremented to point to the next memory location
djnz r0,rep ; Decrements content of R0 and checks whether it is zero or not. If not, jumps
to label ‘rep’.
mov p1,b ; The biggest value which is stored in register B is copied to port P1
clr p3.0 ; Enables the decoder
mov r1,#20 ; Register R1 is initialised with value ‘20’ - just to get some delay
repeat:
djnz r1, repeat ; Decrements R1 and checks whether it is zero or not. If not, jumps to label
‘repeat’.
00101$:
ret
.area CSEG (CODE)
.area XINIT (CODE)
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.