Program To Blink an led in Assembly Language
org 0000h
mov P2,#00h ; initialize the Port2 as output port
top: cpl P2.0 ; compliment the bit
acall delay ; call delay procedure
sjmp top ; make this operation to run repeatedly
delay:
mov R1,#010h ; initialize the R1 register with an immediate value 10h = 16d
mov R0,#0FFh ; load R0 with FFh value to repeat the loop for 256 times
back: DJNZ R0 , back ;internal loop repeates 256 times
DJNZ R1,back ;external loop repeates 16 times
RET
End
org 0000h
mov P2,#00h ; initialize the Port2 as output port
top: cpl P2.0 ; compliment the bit
acall delay ; call delay procedure
sjmp top ; make this operation to run repeatedly
delay:
mov R1,#010h ; initialize the R1 register with an immediate value 10h = 16d
mov R0,#0FFh ; load R0 with FFh value to repeat the loop for 256 times
back: DJNZ R0 , back ;internal loop repeates 256 times
DJNZ R1,back ;external loop repeates 16 times
RET
End
Program To Blink an led in c
#include
sbit LED = P2^0; // define Port2 pin as an LED
void delay(int);
void main()
{
while(1) // infinite loop
{
LED = ~LED; // toggle LED
delay(10000);
} // end of while loop
} // end of main
void delay(int i)
{
for(;i>0;i--);
}
No comments:
Post a Comment