/******************************************************************************
MAX7219串行驱动LED数码管
移动显示0到9
******************************************************************************/
#include"reg51.h"
#include"intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit date=P2^0;
sbit load=P2^1;
sbit clk=P2^2;
uchar bdata bitmsb;
sbit m7 = bitmsb^7;
uchar code tab[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,//0到9
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};//0到9
uchar x,y,c;
void send(void) //送一个字节
{
uchar count;
bitmsb=x;
for(count=0;count { if(m7)
{ clk=0;
date=1;
_nop_();
clk=1;
}
else { clk=0;
date=0;
_nop_();
clk=1;
}
bitmsb }
}
void wr(void)
{
load=0;
send();
x=y;
send();
load=1;
}
void ready(void)
{
x=0xfb; //设置扫描限制
y=0x07;
wr();
x=0xf9; //译码模式
y=0x00;
wr();
x=0xfa; //亮度调节
y=0x0c;
wr();
x=0xfc; //关断模式
y=0x01;
wr();
}
void delay(uint i)
{
for(;i>0;i--);
}
void main(void)
{
uchar i;
uchar cout=0;
ready(); //初始化
c=1;
x=1;
while(1)
{
for(i=cout;i {
y=tab[i];
x=c;
wr();
c++;//因为X的值已经破坏了 所以要用到C变量来赋值
}
delay(40000);//延时
c=1;
cout+=1;
if(cout==18)
cout=0;
}
}