51单片机 8*8LED点阵横向流水 使用位运算生成中间帧
扫描二维码
随时随地手机看文章
#include
typedefunsignedcharuchar;
sbitADDR0=P1^0;
sbitADDR1=P1^1;
sbitADDR2=P1^2;
sbitADDR3=P1^3;
sbitENLED=P1^4;
codeucharimage[5][8]={
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},//??¨?”???§0
{0xFF,0xC3,0xE7,0xE7,0xE7,0xE7,0xE7,0xC3},//??¨?”???§8
{0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7},//??¨?”???§16
{0xFF,0x99,0x99,0x99,0x99,0x99,0x81,0xC3},//??¨?”???§24
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}//??¨?”???§32
};
voidmain(){
EA=1;
ENLED=0;
ADDR3=0;
TMOD=0x01;
TH0=0xFC;
TL0=0x67;
ET0=1;
TR0=1;
while(1);
}
voidinterruptTimer0()interrupt1{
staticuchari=0,tmr=0,index=0;
ucharp=index/8,q=index%8;
TH0=0xFC;
TL0=0x67;
P0=0xFF;
P1=(P1&0xF8)|i;
if(q==0)P0=image[p][i];
elseP0=(image[p][i]<>(8-q));
if(i<7)i++;
elsei=0;
if(tmr<125)tmr++;
else{
tmr=0;
if(index<39)index++;
elseindex=0;
}
}
反向移动:
#include
typedefunsignedcharuchar;
sbitADDR0=P1^0;
sbitADDR1=P1^1;
sbitADDR2=P1^2;
sbitADDR3=P1^3;
sbitENLED=P1^4;
codeucharimage[5][8]={
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},//??¨?”???§0
{0xFF,0xC3,0xE7,0xE7,0xE7,0xE7,0xE7,0xC3},//??¨?”???§8
{0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7},//??¨?”???§16
{0xFF,0x99,0x99,0x99,0x99,0x99,0x81,0xC3},//??¨?”???§24
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}//??¨?”???§32
};
voidmain(){
EA=1;
ENLED=0;
ADDR3=0;
TMOD=0x01;
TH0=0xFC;
TL0=0x67;
ET0=1;
TR0=1;
while(1);
}
voidinterruptTimer0()interrupt1{
staticuchari=0,tmr=0,index=0;
ucharp=index/8,q=index%8,tmp;
TH0=0xFC;
TL0=0x67;
P0=0xFF;
P1=(P1&0xF8)|i;
if(q==0)P0=image[p][i];
else{
tmp=(image[p][i]<>(8-q));
tmp=(tmp<<1&0xAA)|(tmp>>1&0x55);
tmp=(tmp<<2&0xCC)|(tmp>>2&0x33);
tmp=(tmp<<4)|(tmp>>4);
P0=tmp;
}
if(i<7)i++;
elsei=0;
if(tmr<125)tmr++;
else{
tmr=0;
if(index<39)index++;
elseindex=0;
}
}