找回密码
 注册会员
搜索附件  
MCU资讯论坛 附件中心 单片机论坛 51单片机论坛 滚动数码管显示.rar

滚动数码管显示.rar

 

滚动数码管显示:
正在学习单片机,前几天看到一个用8255做的数码管滚动显示,就想要是用MAX7219做怎么做,搞了好一阵子,实在想不出什么好的办法了,就用了一个笨办法,就是建立每一帧的显示表,然后每一次显示一列,这是一个不得己的办法,占空间好大,但一时实在想不出什么好的办法来,下面是我的程序,各位路过的看看,热烈欢迎大家提意见,有什么办法,希望不吝帖出来 ,互相学习

#include<reg51.h>
#include<intrins.h>
#define uchar unsigned
sbit DIN=P2^0;
sbit CS =P2^1;
sbit CLK=P2^2;
uchar code tab[9][8]={
0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,1,
0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,1,2,
0x7f,0x7f,0x7f,0x7f,0x7f,1,2,3,
0x7f,0x7f,0x7f,0x7f,1,2,3,4,
0x7f,0x7f,0x7f,1,2,3,4,0x7f,
0x7f,0x7f,1,2,3,4,0x7f,0x7f,
0x7f,1,2,3,4,0x7f,0x7f,0x7f,
1,2,3,4,0x7f,0x7f,0x7f,0x7f,
0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,
};//帧表
void delayms(uchar ms)
{
uchar i;
while(ms--)
{for(i=0;i<120;i++);}
}
void write(uchar command,uchar dat)
{
uchar i;
CS=0;
for(i=0;i<8;i++)
{
CLK=0;
DIN=(bit)(command&0x80);
command<<=1;
_nop_();_nop_();
CLK=1;
_nop_();
CLK=0;
}
for(i=0;i<8;i++)
{
CLK=0;
DIN=(bit)(dat&0x80);
dat<<=1;
_nop_();_nop_();
CLK=1;
_nop_();
CLK=0;
}
CS=1;
}
void initial_7219()
{
write(0x09,0xff);
write(0x0a,0xf5);
write(0x0c,0x01);
write(0x0b,0x07);
}
main()
{
uchar i,j;
initial_7219();
while(1)
{
for(j=0;j<9;j++)
{
for(i=0;i<8;i++)
{
write(i+1,tab[j]);delayms(10);
}
}
}
}


QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-12-27 00:07 , Processed in 0.042251 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部