8051_Count_Num
This 8051 project is used to count the occurrence of a number from a set of numbers stored in external memory. The number to be checked is specified in the source code. 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.
This circuit contains an 8051 chip, Buffer register, Binary to 7-Segment Decoder, 128K x 8-Bit CMOS One Time PROM and 7- Segment LED Display. In this circuit Port P1 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 number given internally. 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 count showing the occurrence of the given number after all the comparisons will be available in register B. This value is then 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 program is as shown:
mov b,#0x00 ; Register B, which is assigned to store the occurrence of a given number is initialized with value ‘00’.
mov r0,#21 ; Register R0 is initialized with value ‘21’.Here this register works as a counter.
mov dptr,#0x000 ; Data pointer is loaded with the starting address ‘0000’.
loop:
movx a,@dptr ; Content of the memory location pointed by the data pointer is copied to Accumulator
cjne a,#0x34,skip; Compare accumulator content with the value ‘34’. If not equal then jumps to label skip
; Here the number whose occurrence is to be calculated is given as ‘34’.
inc b ; Increment register B by one
skip:
inc dptr ; Increment data pointer by one
djnz r0,loop ; Decrement ‘r0’ by one and checks whether it is zero or not. If not, then jump to label ‘loop’.
dec b ; Decrement register B by one
mov a,b ; The contents of register B is copied to accumulator
add a,#01 ; Accumulator is added with value ‘1’
da a ; Accumulator content is converted to decimal
mov p1,a ; Accumulator content is copied to Port 1
clr p3.0 ; Port 3.0 is set to zero
mov r1,#20 ; Register r1 is initialized with value ‘20’
repeat:
djnz r1,repeat ; R1 is decremented by one and checked whether it is zero or not. If not, then jump to label ‘repeat’
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.