单片机程序8x8led点阵显示心形并实现左移右移的程序

单片机程序8x8led点阵显示心形并实现左移右移的程序,第1张

你用取模软件先点个心形,然后用字节左右移来实现就可以了

我有16*16点汪纯阵的败陵汪各种动态效果程序

给你看下总共有12种动态效果,你改成8*8就可以了

/*************呈现各种显示效果的函数集****************/

void flash_bai(uchar *flash_word,uchar flash_heard,uchar number,uchar sdu,uchar state)//百叶窗效果

{register uchar i,j,k,l

for(i=0i<numberi++)

{

for(j=0j<16j++)

{

for(l=0l<8l++)

{

if(j<8)

{

dispram[l*4+1]=dispram[l*4+1]&0xff<<j|(flash_word[(flash_heard+i)*32+l*4]>>(7-j))

dispram[l*4+2]=dispram[l*4+2]&0xff>>j|(flash_word[(flash_heard+i)*32+l*4+3]<<(7-j)&0x10)

}

else

{

dispram[l*4] =dispram[l*4]&0xff<<(j-7)|flash_word[(flash_heard+i)*32+l*4]>>(15-j)

dispram[l*4+1]=flash_word[(flash_heard+i)*32+l*4]<<(j-7)|(flash_word[(flash_heard+i)*32+l*4+1]>>(15-j))

dispram[l*4+2]=flash_word[(flash_heard+i)*32+l*4+2]<<(15-j)|(flash_word[(flash_heard+i)*32+l*4+3]>>(j-7))

dispram[l*4+3]=(dispram[l*4+3]&0xff>>(j-7))|flash_word[(flash_heard+i)*32+l*4+3]<<(15-j)

}

}

delay(sdu*SPEED)

}

delay(state*SPEED)

}

}

/*******************霓虹灯效果************************/

void flash(uchar *flash_word,uchar flash_heard,uchar number,uchar sdu,uchar state)

{register uchar i,j,k,l

for(i=0i<察仔numberi++)

{

for(j=0j<=16j++)

{

for(k=17k>jk--)

{

for(l=0l<16l++)

{

if(j>8)

{

dispram[l*2] =1<<(8-k+j)|(flash_word[(flash_heard+i)*32+l*2]&0xff>>(16-j))

dispram[l*2+1]=flash_word[(flash_heard+i)*32+l*2+1]

}

else

{

dispram[l*2]=1<<(8-k+j)

dispram[l*2+1]=1<<(16-k+j)|(flash_word[(flash_heard+i)*32+l*2+1]&0xff>>(8-j))

}

}

delay(sdu*SPEED)

}

for(k=17k>jk--)

{

for(l=0l<16l++)

{

if(j>8)

{

dispram[l*2]=1<<(k-8)|(flash_word[(flash_heard+i)*32+l*2]&0xff>>(16-j))

}

else

{

dispram[l*2]=1<<(k-8)

dispram[l*2+1]=1<<k|(flash_word[(flash_heard+i)*32+l*2+1]&0xff>>(8-j))

}

}

delay(sdu*SPEED)

}

}

delay(state*SPEED)

}

}

/*******************跳动的米奇*********************/

void miqi_jump(void)

{uchar jump_i

while((receive[1]&0x0f)<2)

{

switch (abc/7280)//(receive[0]&0x0f)%9

{

case 0:for(jump_i=0jump_i<16jump_i++)

{

dispram[jump_i*2] = Bmp1[14][jump_i*2]<<1|Bmp1[14][jump_i*2+1]>>7

dispram[jump_i*2+1] = Bmp1[14][jump_i*2+1]<<1//左移

}break

case 1:for(jump_i=0jump_i<15jump_i++)

{dispram[0] = 0

dispram[1] = 0

dispram[jump_i*2+2] = Bmp1[14][jump_i*2]

dispram[jump_i*2+3] = Bmp1[14][jump_i*2+1]}

break//下移

case 2:for(jump_i=0jump_i<16jump_i++)

{

dispram[jump_i*2+1] = Bmp1[14][jump_i*2+1]>>1|Bmp1[14][jump_i*2]<<7

dispram[jump_i*2] = Bmp1[14][jump_i*2]>>1

}break//右移

case 3:for(jump_i=0jump_i<15jump_i++)

{dispram[30] = 0

dispram[31] = 0

dispram[jump_i*2] = Bmp1[14][jump_i*2+2]

dispram[jump_i*2+1] = Bmp1[14][jump_i*2+3]}

break//上移

case 4: for(jump_i=0jump_i<16jump_i++)

{

dispram[jump_i*2+2] = Bmp1[14][jump_i*2]<<1|Bmp1[14][jump_i*2+1]>>7

dispram[jump_i*2+3] = Bmp1[14][jump_i*2+1]<<1//左移

dispram[0] = 0

dispram[1] = 0

} break//下移

case 5: for(jump_i=0jump_i<16jump_i++)

{

dispram[jump_i*2+1] = Bmp1[14][jump_i*2+3]>>1|Bmp1[14][jump_i*2+2]<<7

dispram[jump_i*2] = Bmp1[14][jump_i*2+2]>>1

dispram[30] = 0

dispram[31] = 0

} break//上移

case 6: for(jump_i=0jump_i<16jump_i++)

{

dispram[jump_i*2+3] = Bmp1[14][jump_i*2+1]>>1|Bmp1[14][jump_i*2]<<7

dispram[jump_i*2+2] = Bmp1[14][jump_i*2]>>1

dispram[0] = 0

dispram[1] = 0

}

break

case 7: for(jump_i=0jump_i<16jump_i++)

{

dispram[jump_i*2] = Bmp1[14][jump_i*2+2]<<1|Bmp1[14][jump_i*2+3]>>7

dispram[jump_i*2+1] = Bmp1[14][jump_i*2+3]<<1//左移

dispram[30] = 0

dispram[31] = 0

} break

case 8:for(jump_i=0jump_i<32jump_i++)

dispram[jump_i] = Bmp1[14][jump_i]break

}

}

}

/********从wordsp的第OpenDheard个字开始开门效果显示number个字**********/

//开门效果

void Open_door(uchar wordsp[][32],uchar OpenDheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,w

for(w=0w<numberw++)

{

for(j=1j<9j++)

{

for(i=0i<16i++)

{

dispram[i*2]=dispram[i*2]&0xff<<j|wordsp[OpenDheard+w][2*i]&0xff>>(8-j)

dispram[i*2+1]=dispram[i*2+1]&0xff>>j|wordsp[OpenDheard+w][1+2*i]&0xff<<(8-j)

}

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/********从wordsp的第CloseDheard个字开始关门效果显示number个字**********/

//关门效果

void Close_door(uchar wordsp[][32],uchar CloseDheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,w

for(w=0w<numberw++)

{

for(j=1j<9j++)

{

for(i=0i<16i++)

{

dispram[i*2]=dispram[i*2]&0xff>>j|wordsp[CloseDheard+w][2*i]&0xff<<(8-j)

dispram[i*2+1]=dispram[i*2+1]&0xff<<j|wordsp[CloseDheard+w][1+2*i]&0xff>>(8-j)

}

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/********从wordsp的第Far_Awayheard个字开始两边拉开显示number个字**********/

//两边拉开

void Far_Away(uchar wordsp[][32],uchar Far_Awayheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,w

for(w=0w<numberw++)

{

for(j=1j<9j++)

{

for(i=0i<16i++)

{

dispram[i*2]=dispram[i*2]<<j|wordsp[Far_Awayheard+w][2*i]&0xff>>(8-j)

dispram[i*2+1]=dispram[i*2+1]>>j|wordsp[Far_Awayheard+w][1+2*i]&0xff<<(8-j)

}

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/********从wordsp的第Close_Toheard个字开始两边合拢显示number个字**********/

//两边合拢

void Close_To(uchar wordsp[][32],uchar Close_Toheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,w

for(w=0w<numberw++)

{

for(j=1j<9j++)

{

for(i=0i<16i++)

{

dispram[i*2]=dispram[i*2]&0xff>>j|wordsp[Close_Toheard+w][2*i]<<(8-j)

dispram[i*2+1]=dispram[i*2+1]&0xff<<j|wordsp[Close_Toheard+w][1+2*i]>>(8-j)

}

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/****************卷帘出显示number个字***************/

//卷帘出显示

void M_Words(uchar *wordsp,uchar MWheard,uchar number,uchar sdu,uchar state)

{register uchar i,w

for(w=0w<numberw++)

{

for(i=0i<32i++)

{

dispram[i]=wordsp[(MWheard+w)*32+i]

if(i%2)

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/************从UP_Pullp的第UP_Pullheard个字向上拉出number个字***************/

//向上拉出

void UP_Pull_Word(uchar UP_Pullp[][32],uchar UP_Pullheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,k

for(i=0i<numberi++)

{

for(j=0j<16j++)

{

for(k=0k<15-jk++)

{

dispram[k*2]=dispram[(k+1)*2]

dispram[k*2+1]=dispram[(k+1)*2+1]

}

dispram[30-2*j]=UP_Pullp[UP_Pullheard+i][(15-j)*2]

dispram[31-2*j]=UP_Pullp[UP_Pullheard+i][(15-j)*2+1]

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/*********从UPp的第UPheard个字向上滚屏number个字***************/

//向上滚屏

void UP_Run_Word(uchar UPp[][32],uchar UPheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,k

for(i=0i<numberi++)

{

for(j=0j<16j++)

{

for(k=0k<15k++)

{

dispram[k*2]=dispram[(k+1)*2]

dispram[k*2+1]=dispram[(k+1)*2+1]

}

dispram[30]=UPp[UPheard+i][j*2]

dispram[31]=UPp[UPheard+i][j*2+1]

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/*********从Down_Pullp的第Down_Pullheard个字向下拉出number个字***************/

//向下拉出

void Down_Pull_Word(uchar Down_Pullp[][32],uchar Down_Pullheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,k

for(i=0i<numberi++)

{

for(j=0j<16j++)

{

for(k=15k>jk--)

{

dispram[k*2]=dispram[(k-1)*2]

dispram[k*2+1]=dispram[(k-1)*2+1]

}

dispram[2*j]=Down_Pullp[Down_Pullheard+i][2*j]

dispram[2*j+1]=Down_Pullp[Down_Pullheard+i][2*j+1]

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/*********从Downp的第UPheard个字向下滚屏number个字***************/

//向下滚屏

void Down_Run_Word(uchar *Downp,uchar UPheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,k

for(i=0i<numberi++)

{

for(j=0j<16j++)

{

for(k=15k>0k--)

{

dispram[k*2]=dispram[(k-1)*2]

dispram[k*2+1]=dispram[(k-1)*2+1]

}

dispram[0]=Downp[(UPheard+i)*32+(15-j)*2]

dispram[1]=Downp[(UPheard+i)*32+(15-j)*2+1]

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/**********从LRp的第LRheard个字左移出显示number个字************/

//用左移出显示

void L_Removeout_Word(uchar *LRp,uchar LRheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,k,l

for(i=0i<numberi++)

{

for(j=0j<2j++)

for(k=0k<8k++)

{

for(l=0l<16l++)

{

dispram[l*2]=dispram[l*2]<<1|dispram[l*2+1]>>7

dispram[l*2+1]=dispram[l*2+1]<<1|LRp[(i+LRheard)*32+l*2+j]>>(7-k)

}

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/**********从L_Pullp的第L_Pullheard个字左拉出显示number个字************/

//左拉出显示

void L_Pull_Word(uchar *L_Pullp,uchar L_Pullheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,k,l

for(i=0i<numberi++)

{

for(j=0j<2j++)

for(k=0k<8k++)

{

for(l=0l<16l++)

{

if(j==0)

{

dispram[l*2]=dispram[l*2]<<1|dispram[l*2+1]>>7

dispram[l*2+1]=(dispram[l*2+1]&0xff<<(k+1))<<1|L_Pullp[(i+L_Pullheard)*32+l*2+1]&0xff>>(7-k)

}

else

{

dispram[l*2]=(dispram[l*2]&0xff<<(k+1))<<1|L_Pullp[(i+L_Pullheard)*32+l*2]&0xff>>(7-k)

dispram[l*2+1]=L_Pullp[(i+L_Pullheard)*32+l*2+1]

}

}

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/****************卷帘出黑屏***************/

void M_Black(void)

{register uchar i

for(i=0i<32i++)

{

dispram[i]=0x00

if(i%2)

delay(5*SPEED)

}

}

/**********从RRp的第RRheard个字右移出显示number个字************/

//右移出显示

void R_Removeout_Word(uchar *RRp,uchar RRheard,uchar number,uchar sdu,uchar state)

{register uchar i,j,k,l

for(i=0i<numberi++)

{

for(j=2j>0j--)

for(k=0k<8k++)

{

for(l=0l<16l++)

{

dispram[l*2+1]=dispram[l*2+1]>>1|dispram[l*2]<<7

dispram[l*2]=dispram[l*2]>>1|RRp[(i+RRheard)*32+l*2+j-1]<<(7-k)

}

delay(sdu*SPEED)

}

delay(state*TIME)

}

}

/**************随机跑动函数**************/

void radom_flash(uchar *Radom_p,uchar Radom_heard,uchar number,uchar sdu,uchar state)

{

switch ((receive[1]&0x0f)+(receive[0]&0x70)/16)

{

case 0: Open_door(Radom_p,Radom_heard,number,sdu,state)M_Black()break//开门

case 1: Close_door(Radom_p,Radom_heard,number,sdu,state)M_Black()break//关门

case 2: Far_Away(Radom_p,Radom_heard,number,sdu,state)M_Black()break//分开

case 3: Close_To(Radom_p,Radom_heard,number,sdu,state)M_Black()break//合拢

case 4: miqi_jump()

case 5: M_Words(Radom_p,Radom_heard,number,sdu,state)M_Black()break//卷帘

case 6: UP_Pull_Word(Radom_p,Radom_heard,number,sdu,state)break//上拉出

case 7: UP_Run_Word(Radom_p,Radom_heard,number,sdu,state)break//上滚屏

case 8: Down_Pull_Word(Radom_p,Radom_heard,number,sdu,state)break//下拉出

case 9: Down_Run_Word(Radom_p,Radom_heard,number,sdu,state)break

case 10: L_Removeout_Word(Radom_p,Radom_heard,number,sdu,state)break//左滚屏

case 11: L_Pull_Word(Radom_p,Radom_heard,number,sdu,state)break//左拉出

case 12: R_Removeout_Word(Radom_p,Radom_heard,number,sdu,state)break//右滚屏

case 13: flash(Radom_p,Radom_heard,number,3,state)break

case 14: flash_bai(Radom_p,Radom_heard,number,sdu,state)break

}

}

用C语言编写心形的方法:

#include<stdio.h> 

int n

void draw(int n)

{

int i,j

for (i=1-(n>>1)i<=ni++) 

if (i>=0) 

for (j=0j<ij++) printf("  ") 

for (j=1j<=2*(n-i)+1j++) printf(" *") 

printf("\n") 

else 

for (j=ij<0j++) printf("  ") 

for (j=1j<=n+2*i+1j++) printf(" *") 

for (j=1j<=-1-2*ij++) 前轿锋printf("  ") 

for (j=1j<=n+2*i+1j++) printf(" *") 

printf("\n") 

}

}

int main() 

printf("Please input the size (n>=4):") 

scanf("%d",&n) 

draw(n)

return 0 

}

扩展资料

C程序是由一组变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行慧晌代码段。我们可以把函数看成一个“黑帆衫盒子”,你只要将数据送进去就能得到结果,而函数内部究竟是如何工作的,外部程序是不知道的。

外部程序所知道的仅限于输入给函数什么以及函数输出什么。函数提供了编制程序的手段,使之容易读、写、理解、排除错误、修改和维护。

参考资料:百度百科--c语音

方法很简单,

sbit k=P1^0//选取一个I/O端口连接一个按键

unsigned char r//设置一个计罩笑铅数变量

void delay(uchar p)//12MHz@p微秒延时函数

{

unsigned char i,j

for(i=0i<pi++){

for(j=0j<50j++)

{}}

}

void key()//按键函数

{

if (k==0)//查询按键是否按下

{

delay(20) //等待按键连接稳定

if(k==0) //如果按键仍然是连接状态

{

r++//标志+1

if(r>1){r=0}//可以任意多种选择,这里只设定0、1两种状态

while(!k)//等待按键抬起

}

}

}

void set_out()//设置输出方式函数

{

key()//查询按键值

if(r==0){***心形显示***}

if(r==1){***星形物好显升告示***}

//if(r==?){***?形显示***}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8261546.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存