📄 led.c
字号:
#include<reg51.h>
sbit SCLK=P1^5;
sbit Din=P1^6;
sbit RCLK=P1^7;
#define uchar unsigned char
uchar movbuf[20];
uchar idata disbuf[20]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uchar xdata display[8][20]={{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xe7,0xff,0xf7,0xff,0xe7,0xff,0xe7,0xff,0xf7,0xff,0xc3,0xff,0xe7,0xff,0xc3,0xff,0xe7,0xff,0xe7,0xff},
{0xdb,0xff,0xe7,0xff,0xdb,0xff,0xdb,0xff,0xe7,0xff,0xdf,0xff,0xdf,0xff,0xfb,0xff,0xdb,0xff,0xdb,0xff},
{0xdb,0xff,0xf7,0xff,0xfb,0xff,0xf7,0xff,0xd7,0xff,0xe7,0xff,0xc7,0xff,0xf7,0xff,0xe7,0xff,0xdb,0xff},
{0xdb,0xff,0xf7,0xff,0xf7,0xff,0xf7,0xff,0xd7,0xff,0xfb,0xff,0xdb,0xff,0xef,0xff,0xdb,0xff,0xe3,0xff},
{0xdb,0xff,0xf7,0xff,0xef,0xff,0xdb,0xff,0xc3,0xff,0xdb,0xff,0xdb,0xff,0xef,0xff,0xdb,0xff,0xfb,0xff},
{0xe7,0xff,0xe3,0xff,0xc3,0xff,0xe7,0xff,0xf7,0xff,0xe7,0xff,0xe7,0xff,0xef,0xff,0xe7,0xff,0xe7,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}};
void DATA_out(uchar dat);
void leftmove(void);
void delay(void);
void main()
{
uchar i,j;
uchar temp=0x80;
while(1)
{
for(i=0;i<8;i++)
{ DATA_out(temp);
for(j=0;j<4;j++)
{DATA_out(display[i][j]);
}
RCLK=0;
RCLK=1;
temp>>=1;
if(temp==0)
temp=0x80;
}
}
leftmove();
}
void DATA_out(uchar dat)
{ uchar i=0;
for(i=0;i<8;i++)
{ Din=(bit)(dat&0x01);
SCLK=0;
SCLK=1;
dat=dat>>1;
}
}
void leftmove()
{ uchar i,j;
uchar A=0;
for(i=0;i<8;i++)
{ for(j=0;j<20;j=j+2)
{ movbuf[j]=display[i][j];
A=movbuf[j]&0x80;
if(A) disbuf[j]|=0x01;
movbuf[j]<<=1;
}
for(j=0;j<18;j++)
movbuf[j]|=disbuf[j+2];
movbuf[18]|=disbuf[0];
for(j=0;j<20;j=j+2)
display[i][j]=movbuf[j];
for(j=0;j<20;j=j+2)
disbuf[j]=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -