#include
typedefunsignedcharuchar;
typedefunsignedintuint;
typedefunsignedlongulong;
sbitADDR0=P1^0;
sbitADDR1=P1^1;
sbitADDR2=P1^2;
sbitADDR3=P1^3;
ucharimage[8]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
ucharT0RH,T0RL;
uintrate;
voidLEDScan();
voidresetImage();
voidconfigTmr0(uintms1,ucharms2);
voidmain(){
EA=1;
ADDR3=0;
ENLED=0;
configTmr0(50,2);
while(1);
}
voidconfigTmr0(uintms1,ucharms2){
ulongtmp;
rate=ms1/ms2;
tmp=11059200/12;//定時(shí)器計(jì)數(shù)頻率
tmp=(tmp*ms2)/1000;//計(jì)算所需的計(jì)數(shù)值
tmp=65536-tmp;//計(jì)算定時(shí)器重載值
tmp=tmp+12;//補(bǔ)償中斷響應(yīng)延時(shí)造成的誤差
T0RH=tmp>>8;//定時(shí)器重載值拆分為高低字節(jié)
T0RL=tmp;
TMOD&=0xF0;
TMOD|=0x01;
TH0=T0RH;
TL0=T0RL;
ET0=1;
TR0=1;
}
#defineLEDScan();{\
staticuchari=0;\
P0=0xFF;\
P1=(P1&0xF8)|i;\
P0=image[i];\
i=++i&0x07;\
}
voidresetImage(){
staticucharx=0,y=0;
image[y]^=(0x80>>x);
if(x==3&&y==4){
x=0;
y=0;
}
elseif(y<=x+1&&x+y<7){
x++;
}
elseif(x+y>=7&&y
y++;
}
elseif(y>=x&&x+y>7){
x--;
}
else
y--;
}
voidinterruptTmr0()interrupt1{
staticuinti=0;
TH0=T0RH;
TL0=T0RL;
LEDScan();
if(i==rate){
resetImage();
i=0;
}
else
i++;
}
雙向流水:
#include
typedefunsignedcharuchar;
typedefunsignedintuint;
typedefunsignedlongulong;
sbitADDR0=P1^0;
sbitADDR1=P1^1;
sbitADDR2=P1^2;
sbitADDR3=P1^3;
sbitENLED=P1^4;
ucharimage[8]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
ucharT0RH,T0RL;
uintrate;
voidLEDScan();
voidresetImage();
voidconfigTmr0(uintms1,ucharms2);
voidmain(){
EA=1;
ADDR3=0;
ENLED=0;
configTmr0(50,2);
while(1);
}
voidconfigTmr0(uintms1,ucharms2){
ulongtmp;
rate=ms1/ms2;
tmp=11059200/12;//定時(shí)器計(jì)數(shù)頻率
tmp=(tmp*ms2)/1000;//計(jì)算所需的計(jì)數(shù)值
tmp=65536-tmp;//計(jì)算定時(shí)器重載值
tmp=tmp+12;//補(bǔ)償中斷響應(yīng)延時(shí)造成的誤差
T0RH=tmp>>8;//定時(shí)器重載值拆分為高低字節(jié)
T0RL=tmp;
TMOD&=0xF0;
TMOD|=0x01;
TH0=T0RH;
TL0=T0RL;
ET0=1;
TR0=1;
}
#defineLEDScan();{\
staticuchari=0;\
P0=0xFF;\
P1=(P1&0xF8)|i;\
P0=image[i];\
i=++i&0x07;\
}
voidresetImage(){
staticucharx=0,y=0;
image[y]^=(0x80>>x);
image[7-y]^=(0x01<
if(x==3&&y==4){
x = 0;?
評(píng)論
查看更多