求51单片机8x8点阵的,各种流动效果代码,多谢

 我来答
百度网友28b23af
2012-03-10 · TA获得超过212个赞
知道小有建树答主
回答量:178
采纳率:0%
帮助的人:167万
展开全部
#include <REG51.H>

unsigned char code taba[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code tabb[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

void delay1(void)
{
unsigned char i,j,k;

for(k=10;k>0;k--)
for(i=20;i>0;i--)
for(j=248;j>0;j--);

}

void main(void)
{
unsigned char i,j;

while(1)
{
for(j=0;j<3;j++)//  //from left to right 3 time
{
for(i=0;i<8;i++)
{
P2=taba[i];
P0=0xff;
delay1();
}
}

for(j=0;j<3;j++)//  //from right to left 3 time
{
for(i=0;i<8;i++)
{
P2=taba[7-i];
P0=0xff;
delay1();
}
}

for(j=0;j<3;j++)//  //from top to bottom 3 time
{
for(i=0;i<8;i++)
{
P2=0x00;
P0=tabb[7-i];

delay1();
}
}

for(j=0;j<3;j++)//  //from bottom to top 3 time
{
for(i=0;i<8;i++)
{
P2=0x00;
P0=tabb[i];

delay1();
}
}
}
}

第二种:
/*****************************************************************************************
* *
* LED点阵实验(流动显示1 2 3 4 5 6 7 8 9) *
* 说明 通过P0 和 P2 作为点阵接口 *
*要求学员掌握 LED点阵的工作原理和 各点阵脚的定义及接法,具体接线请参考接线说明 *
*我们采用的LED点阵式是低功耗,在做实验时可以用单片机脚直接驱动 *
******************************************************************************************/

#include<reg51.h>

unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

unsigned char code digittab[18][8]={

{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0

{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1

{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2

{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3

{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4

{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5

{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6

{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7

{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8

{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00}, //9

{0x00,0x00,0x7F,0x48,0x48,0x30,0x00,0x00}, //P

{0x00,0x00,0x7F,0x48,0x4C,0x73,0x00,0x00}, //R

{0x00,0x00,0x7F,0x49,0x49,0x49,0x00,0x00}, //E

{0x00,0x00,0x3E,0x41,0x41,0x62,0x00,0x00}, //C

{0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00}, //H

{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00}, //I

{0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00}, //N

{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00} //中

};

unsigned int timecount;

unsigned char cnta;

unsigned char cntb;

void main(void)

{

TMOD=0x01;

TH0=(65536-3000)/256;

TL0=(65536-3000)%256;

TR0=1; //开启定时0
ET0=1;

EA=1; //开启中断

cntb=0;

while(1)

{ ;

}

}

/*************************************************
*
* 定时中断
********************************************************/
void t0(void) interrupt 1 using 0
{

TH0=(65536-3000)/256; //定时器高位装载数据
TL0=(65536-3000)%256; //定时器低位装载数据

if(cntb<18) //红色
{
P1=0xFF;
P2=tab[cnta];
P0=digittab[cntb][cnta];
}
else //绿色
{
P2=0xFF;
P1=tab[cnta];
P0=digittab[cntb-18][cnta];
}

if(++cnta>=8) cnta=0;
if(++timecount>=333)
{
timecount=0;
if(++cntb>=36)cntb=0;
}

}

别忘了采纳和给分,互利共赢啊!
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式