單片機(jī)40個(gè)實(shí)驗(yàn)之廣告燈的左移右移
每次送出的數(shù)據(jù)是不同,具體的數(shù)據(jù)如下表1所示 :
P1.7 | P1.6 | P1.5 | P1.4 | P1.3 | P1.2 | P1.1 | P1.0 | 說明 |
L8 | L7 | L6 | L5 | L4 | L3 | L2 | L1 | |
1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | L1亮 |
1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | L2亮 |
1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | L3亮 |
1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | L4亮 |
1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | L5亮 |
1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | L6亮 |
1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | L7亮 |
0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | L8亮 |
5.程序框圖
6. 匯編源程序
ORG 0
START: MOV R2,#8
MOV A,#0FEH
SETB C
LOOP: MOV P1,A
LCALL DELAY
RLC A
DJNZ R2,LOOP
MOV R2,#8
LOOP1: MOV P1,A
LCALL DELAY
RRC A
DJNZ R2,LOOP1
LJMP START
DELAY: MOV R5,#20 ;
D1: MOV R6,#20
D2: MOV R7,#248
DJNZ R7,$
DJNZ R6,D2
DJNZ R5,D1
RET
END
7.C語言源程序
#include
unsigned char i;
unsigned char temp;
unsigned char a,b;
void delay(void)
{
unsigned char m,n,s;
for(m=20;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}
void main(void)
{
while(1)
{
temp=0xfe;
P1=temp;
delay();
for(i=1;i<8;i++)
{
a=temp<b=temp>>(8-i);
P1=a|b;
delay();
}
for(i=1;i<8;i++)
{
a=temp>>i;
b=temp<<(8-i);
P1=a|b;
delay();
}
}
}
評(píng)論