; down counter 8bit
; counts from 255 to 0
ORG 0H
COUNT_FROM EQU 100
MAIN:
LCALL COUNT
SJMP MAIN
COUNT:
MOV A,#COUNT_FROM ;load COUNT_FROM in A
down: MOV P0,A ;move data from a to port0
ACALL delay ;call delay routine
DEC A ;decrement a
CJNE A,#0,up ;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 - bcd up counter 8bit | 8051 Program - bcd down 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