Pages

Program to count from 0-9 in 8051

here:mov a,#0h ;move 0 to a

up:mov p0,a ;move data from a to port0
acall delay ;call delay routine
add a,#01 ;increment a
cjne a,#010,up ;compare a with 10, if not equal, jump to location up
sjmp here ;jump to location here
;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 ;return
end

0 comments:

Post a Comment