谁能给我个51单片机的8*8流动显示LED的程序
想研究研究,求个程序,最好是能有字流动显示的,程序里最好有注释,要不理解太费劲了邮箱1023819740@qq.com...
想研究研究,求个程序,最好是能有字流动显示的,程序里最好有注释,要不理解太费劲了
邮箱1023819740@qq.com 展开
邮箱1023819740@qq.com 展开
2个回答
展开全部
这是我前几天写的:
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit SH_cp=P2^0;
sbit ST_cp=P2^1;
sbit DS=P2^2;
uchar huancun[8]; //显示缓存
uchar code dis[22][8]={ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //缓冲区
{0x00,0x12,0x12,0x12,0x1e,0x12,0x12,0x12}, //"H"
{0x00,0x22,0x22,0x14,0x08,0x08,0x08,0x08}, //"Y"
{0x00,0x0e,0x04,0x04,0x04,0x04,0x24,0x18}, //"J"
{0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x00}, //":"
{0x00,0x0e,0x04,0x04,0x04,0x04,0x04,0x0e}, //"I"
{0x00,0x36,0x49,0x41,0x41,0x22,0x14,0x08}, //"心"
{0x00,0x24,0x24,0x24,0x24,0x24,0x24,0x18}, //"U"
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //缓冲区
{0x00,0x1e,0x10,0x1c,0x02,0x02,0x12,0x0c}, //"5"
{0x00,0x0c,0x12,0x02,0x04,0x08,0x10,0x1e}, //"2"
{0x00,0x0c,0x12,0x12,0x12,0x12,0x12,0x0c}, //"0"
{0x00,0x08,0x18,0x08,0x08,0x08,0x08,0x08}, //"1"
{0x00,0x18,0x24,0x04,0x08,0x04,0x24,0x18}, //"3"
{0x00,0x08,0x18,0x08,0x08,0x08,0x08,0x08}, //"1"
{0x00,0x04,0x0c,0x14,0x24,0x3e,0x04,0x04}, //"4"
{0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00}, //"-"
{0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00}, //"-"
{0x00,0x22,0x2a,0x2a,0x2a,0x2a,0x2a,0x14}, //"W"
{0x00,0x22,0x2a,0x2a,0x2a,0x2a,0x2a,0x14}, //"W"
{0x00,0x1c,0x12,0x12,0x1c,0x10,0x10,0x10}, //"P"
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} //缓冲区
};
uchar count=0,like=0,love=0;
void init_T0(); //定时器T0初始化
void init_dis(); //显示初始化
void write_595(uchar data1); //向595写一字节数据
void delay(uchar n); //n*1ms
void hccl(); //显示缓存全左移一位处理
void main()
{ uchar i;
init_dis();
init_T0();
while(1)
{ for(i=0;i<8;i++)
{ P1=i;
write_595(huancun[i]);
delay(2);
write_595(0);
}
}
}
void init_T0() //定时器T0初始化
{ TMOD=0x01;
TH0=0x4c;
TL0=0x00; //50ms
EA=1;
ET0=1;
TR0=1;
}
void init_dis() //显示初始化
{ uchar i;
for(i=0;i<8;i++)
{ huancun[i]=dis[0][i]; //将缓冲区的数据写入显示缓存
}
}
void time0()interrupt 1
{ count++;
if(count==3)
{ count=0;
like++;
hccl();
if(like==8) //左移1位8次 即一字符完全移动8位
{ like=0;
love++; //换下一个字符
if(love==21) //显示完4个字符 包括缓冲区
{ love=0;
}
}
}
TH0=0x4c;
TL0=0x00; //50ms
}
void write_595(uchar data1) //向595写一字节数据
{ uchar j;
ST_cp=0;
for(j=0;j<8;j++)
{ SH_cp=0;
if(data1&0x80) DS=1;
else DS=0;
SH_cp=1;
data1<<=1;
}
ST_cp=1;
}
void delay(uchar n) //n*1ms
{
uchar a,b,c;
for(c=n;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
void hccl() //显示缓存全左移一位处理
{ uchar k;
for(k=0;k<8;k++)
{ huancun[k]=(huancun[k]<<1)|(dis[love+1][k]>>(8-like));
}
}
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit SH_cp=P2^0;
sbit ST_cp=P2^1;
sbit DS=P2^2;
uchar huancun[8]; //显示缓存
uchar code dis[22][8]={ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //缓冲区
{0x00,0x12,0x12,0x12,0x1e,0x12,0x12,0x12}, //"H"
{0x00,0x22,0x22,0x14,0x08,0x08,0x08,0x08}, //"Y"
{0x00,0x0e,0x04,0x04,0x04,0x04,0x24,0x18}, //"J"
{0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x00}, //":"
{0x00,0x0e,0x04,0x04,0x04,0x04,0x04,0x0e}, //"I"
{0x00,0x36,0x49,0x41,0x41,0x22,0x14,0x08}, //"心"
{0x00,0x24,0x24,0x24,0x24,0x24,0x24,0x18}, //"U"
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //缓冲区
{0x00,0x1e,0x10,0x1c,0x02,0x02,0x12,0x0c}, //"5"
{0x00,0x0c,0x12,0x02,0x04,0x08,0x10,0x1e}, //"2"
{0x00,0x0c,0x12,0x12,0x12,0x12,0x12,0x0c}, //"0"
{0x00,0x08,0x18,0x08,0x08,0x08,0x08,0x08}, //"1"
{0x00,0x18,0x24,0x04,0x08,0x04,0x24,0x18}, //"3"
{0x00,0x08,0x18,0x08,0x08,0x08,0x08,0x08}, //"1"
{0x00,0x04,0x0c,0x14,0x24,0x3e,0x04,0x04}, //"4"
{0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00}, //"-"
{0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00}, //"-"
{0x00,0x22,0x2a,0x2a,0x2a,0x2a,0x2a,0x14}, //"W"
{0x00,0x22,0x2a,0x2a,0x2a,0x2a,0x2a,0x14}, //"W"
{0x00,0x1c,0x12,0x12,0x1c,0x10,0x10,0x10}, //"P"
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} //缓冲区
};
uchar count=0,like=0,love=0;
void init_T0(); //定时器T0初始化
void init_dis(); //显示初始化
void write_595(uchar data1); //向595写一字节数据
void delay(uchar n); //n*1ms
void hccl(); //显示缓存全左移一位处理
void main()
{ uchar i;
init_dis();
init_T0();
while(1)
{ for(i=0;i<8;i++)
{ P1=i;
write_595(huancun[i]);
delay(2);
write_595(0);
}
}
}
void init_T0() //定时器T0初始化
{ TMOD=0x01;
TH0=0x4c;
TL0=0x00; //50ms
EA=1;
ET0=1;
TR0=1;
}
void init_dis() //显示初始化
{ uchar i;
for(i=0;i<8;i++)
{ huancun[i]=dis[0][i]; //将缓冲区的数据写入显示缓存
}
}
void time0()interrupt 1
{ count++;
if(count==3)
{ count=0;
like++;
hccl();
if(like==8) //左移1位8次 即一字符完全移动8位
{ like=0;
love++; //换下一个字符
if(love==21) //显示完4个字符 包括缓冲区
{ love=0;
}
}
}
TH0=0x4c;
TL0=0x00; //50ms
}
void write_595(uchar data1) //向595写一字节数据
{ uchar j;
ST_cp=0;
for(j=0;j<8;j++)
{ SH_cp=0;
if(data1&0x80) DS=1;
else DS=0;
SH_cp=1;
data1<<=1;
}
ST_cp=1;
}
void delay(uchar n) //n*1ms
{
uchar a,b,c;
for(c=n;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
void hccl() //显示缓存全左移一位处理
{ uchar k;
for(k=0;k<8;k++)
{ huancun[k]=(huancun[k]<<1)|(dis[love+1][k]>>(8-like));
}
}
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
STM32是一种由意法半导体(STMicroelectronics)公司设计和生产的单片机系列,广泛用于嵌入式系统、物联网(IoT)设备、汽车电子、工业自动化等领域。STM32具有以下优点:1. 低功耗:STM32单片机通常具有较低的功耗,...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询