Tutorial AT8951 with Proteus : Driving LED


Dear al hand
In first tutor , we want to drive seven led (LED as out put) with AT89051 mic.
1. First we must draw the circuit below(click the image to enlarge and download (in proteus file)) :

Fig.1 : Driving LED

We use P3 port as out port, connect this port with seven led in common cathode configuration. So if we want activate a led, we must send '0' to the coresponding port.
Below is the program for driving led turning ON two group led alternatelly:


Org 0h
Start :
Mov P3,#000001111B ; LED p3.4---P3.7 ON
Acall Ldelay ; call Ldelay sub
Mov P3,#11110000B ; P3.0---P3.3 ON
Acall Ldelay;
Sjmp Start; jump to start


; ----------------
; 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, #0FFh ; fill R1 reg with FF

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
Ret


Ldelay sub is used for hold one group led in on condition; after delay time elapsed, another led group will turn on. Clik for download asm file.


We can program this circuit with C language :
# include
Delay( long int d)
{ //delay subs
long int i;
for (i=0; i<=d; i++) {} }// end delay sub unsigned char j,k; main() { do {k= 1; for (j=0;j<=7;j++)// repeat for seven time { P3= 0xFF-k; // turning on led k delay(10000); k=k*2;// left shifting }o for (j=0;j<=7;j++)// repeat for seven time P3= 0xFF-k; // turning on led k delay(10000); k=k/2;// right shifting } //end do } while (1);//main loop }



No comments:

Post a Comment