Second Day AT89s51 Tutorial : Driving led in Ring Counter

Program for turning on LED in RING COUNTER mode

(sequentially shifting and repeating mode)

Circuit For Second Day

Program list :

Org 0h

Mov A, #1111110B; fill Acumulator with 11111110 binerr

Setb C ; set cary flag become 1


Start:

Mov P3,A ; push A fill to the output (P3)

Acall Ldelay ; call Ldelay sub

Rlc A ; Rotate Accu left with carrry

; <-C b7 b6 b5 b4 b3 b2 b1 b0<-

; |_____________________________|


Sjmp start ;jump to start label

; ----------------

; Sub Rutine delay

;-----------------

Delay : Mov R0, #0FFh ; fill RO reg with FF


Delay1:

Djnz R0,Delay1 ; decrement R0 and if not zero jum to delay1

Ret ; come back to the adres affter ACALL delay instruction



; ----------------

; Sub Rutine Ldelay

;-----------------

Ldelay : Mov R1, #20h ; fill R1 reg with 20 h


Ldelay1:

Acall Delay ;

Djnz R1,Ldelay1 ; decrement R0 and if not zero jum to delay1

Ret ; come back to the adres affter ACALL delay instruction


;

end


Program expalanation:

At first we load the Accu with 11111110 and push it to P3 port,as result P3.0 led will turn on (because P3.0 = 0)

To make the shift of led turning, we use RLC (Rotate Left with Carry) instruction, but with carry setting become 1 as first,

This carry bit useful to make all led turn off after 9 time shifting. Below state table of ACCU register and Carry Register After every shift operation


Shifting C b7b6 b5 b4b3 b2 b1 b0
11 1 11 1 1 1 1 0
2 1 1 1 1 1 1 1 0 1
31 1 1 1 1 1 0 1 1
4 1 1 1 1 1 0 1 1 1
6 1 1 1 1 0 1 1 1 1
7 1 1 1 0 1 1 1 1 1
8 1 1 0 1 1 1 1 1 1
9 1 0 1 1 1 1 1 1 1
0 0 1 1 1 1 1 1 1 1















































































































No comments:

Post a Comment