Saturday, April 30, 2016

8051 Program – bcd down counter 8bit

; bcd down counter 8bit
; counts from 99 to 0
ORG 0H
COUNT_FROM EQU 99H
MAIN:
LCALL COUNT
SJMP MAIN
COUNT:
MOV B,#COUNT_FROM ;load COUNT_FROM in B
down: MOV A,B ;move data from b to a
ADD A,#99h ;add 99h to decrement bcd by 1
DA A ;decimal adjust accumulator after addition
MOV B,A ;move data from a to b
MOV P0,A ;move data from a to port0
ACALL delay ;call delay routine
MOV A,B ;move data from b to a
CJNE A,#0,down ;compare a with 0, if not equal, jump to location up
RET
;delay routine
delay:
MOV R1,#0FFH ;move 0ffh to r1
l3: MOV R2,#0FFH ;move 0ffh to r2
l2: MOV R3,#0FFH ;move 0ffh to r3
l1: DJNZ R1,l1 ;decrement r1, repeat till r1=0
DJNZ R3,l2 ;decrement r3,repeat l2 till r3=0
DJNZ R2,l3 ;decrement r2, repeat l3 till r2=0
RET
END



Related topics:
8051 Program - up counter 8bit   |   8051 Program - down counter 8bit   |   8051 Program - bcd up counter 8bit   |   8051 Program - bcd up and down counters   |   8051 Program - hex up and down counters   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment