控制/MCU
#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;//定时器计数频率
tmp=(tmp*ms2)/1000;//计算所需的计数值
tmp=65536-tmp;//计算定时器重载值
tmp=tmp+12;//补偿中断响应延时造成的误差
T0RH=tmp>>8;//定时器重载值拆分为高低字节
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;//定时器计数频率
tmp=(tmp*ms2)/1000;//计算所需的计数值
tmp=65536-tmp;//计算定时器重载值
tmp=tmp+12;//补偿中断响应延时造成的误差
T0RH=tmp>>8;//定时器重载值拆分为高低字节
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;
全部0条评论
快来发表一下你的评论吧 !