流水燈來回點(diǎn)亮程序(匯編和C)
匯編:
本文引用地址:http://butianyuan.cn/article/201611/316931.htmORG 0000H
JMP MAIN
ORG 30H
MAIN:
MOV A,#0FFH
CLR C
MOV R2,#08H
LOOP1:;實(shí)驗(yàn)中二極管低電平點(diǎn)亮,loop1帶進(jìn)位位的循環(huán)左移
RLC A
MOV P1,A
CALL DELAY
DJNZ R2,LOOP1
MOV R2,#07H
LOOP2:;loop2循環(huán)右移動
RR A
MOV P1,A
CALL DELAY
DJNZ R2,LOOP2
JMP MAIN
DELAY: ;延時約1s
MOV R3,#10
D1: MOV R4,#200
D2: MOV R5,#248
DJNZ R5,$
DJNZ R4,D2
DJNZ R3,D1
RET
END
C語言:
#include
#include
#define uchar unsigned char
#define uint unsigned int
void delay(uint);
void main()
{ while(1)
{
{ uchar l;
P1=0xfe;
delay(100);
for( l=1;l<=7;l++)
{ P1=_crol_ (P1,1);
delay(100);
}
}
{ uchar l;
for( l=1;l<=7;l++)
{ P1=_cror_ (P1,1);
delay(100);
}
}
}
}
void delay(uint k)
{
uint i,j;
for( i=0;i<=k;i++)
for( j=0;j<=1000;j++)
;
}
評論