基于51单片机漩涡流水点阵的设计

控制/MCU

1883人已加入

描述

#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; 

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 相关推荐
  • 5

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分