/* 從右往左*/ #include <reg52.h> sbit ADDR0 = P1^0; sbit ADDR1 = P1^1; sbit ADDR2 = P1^2; sbit ADDR3 = P1^3; sbit ENLED = P1^4; void main() { unsigned int ...
/* 從右往左*/
#include <reg52.h>
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
void main()
{
unsigned int count = 0;
unsigned int cnt = 1;
ADDR0=0;
ADDR1=1;
ADDR2=1;
ADDR3=1;
ENLED=0;
while(1)
{
P0=~(0x01<<cnt);
for(count=0;count<30000;count++);
cnt++;
if(cnt>=8)
{
cnt=0;
}
}
}
/*來回閃爍*/ 自己編寫
#include <reg52.h>
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
void main()
{
unsigned int count = 0;
unsigned int cnt = 0;
unsigned int i=0;
ADDR0=0;
ADDR1=1;
ADDR2=1;
ADDR3=1;
ENLED=0;
for(cnt=0;cnt<8;cnt++)
{
P0=~(0x01<<cnt);
for(count=0;count<30000;count++);
}
if(cnt>=7)
{
for(i=0;i<8;i++)
{
P0=~(0x80>>i);
for(count=0;count<30000;count++);
}
}
}
/*來回閃爍*/ 參考
#include <reg52.h>
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
void main()
{
unsigned int i=0;
unsigned int j;
unsigned int k=0x01;
ADDR0=0;
ADDR1=1;
ADDR2=1;
ADDR3=1;
ENLED=0;
while(1)
{
P0=~k;
for(j=0;j<30000;j++);
if(i==0)
{
k=k<<1;
if(k==0x80)
i=1;
}
else
{
k=k>>1;
if(k==0x01)
i=0;
}
}
}