跪求16*16点阵C程序,显示“科技改变生活”六字,由于刚刚学习单片机,程序最好有文字注明!谢谢!

2024-12-26 20:01:42
推荐回答(1个)
回答1:

#include
#define BLKN 2 //列锁存器
sbit G=P1^7; //P1.7为显示允许控制信号端口
sbit RRCLK=P1^6; //P1.6为输出锁存器时钟信号端
sbit SCLR=P1^5; //P1.5为移为寄存器清零端
void delay(unsigned int); //延时函数
unsigned char data dispram[32]; //显示缓存
unsigned char data huancun[32];

void main(void)
{ unsigned char code Cmp[][32]={

{0xff,0x07,0xc0,0x6f,0xed,0xef,0xf6,0xdf,0xc0,
0x01,0xdd,0xfd,0xbd,0xff,0xc0,0x03,
0xfb,0xff,0xf8,0x0f,0xf3,0xdf,0xf4,0xbf,0xef,
0x3f,0x9c,0xcf,0x73,0xf1,0xcf,0xfb},//爱
{0xf7,0xdf,0xf9,0xcf,0xfb,0xbf,0xc0,0x07,0xde,
0xf7,0xc0,0x07,0xde,0xf7,0xde,0xf7,
0xc0,0x07,0xde,0xf7,0xfe,0xff,0x00,0x01,0xfe,
0xff,0xfe,0xff,0xfe,0xff,0xfe,0xff},//单
{0xff,0xbf,0xef,0xbf,0xef,0xbf,0xef,0xbb,0xe0,
0x01,0xef,0xff,0xef,0xff,0xef,0xff,
0xe0,0x0f,0xef,0xef,0xef,0xef,0xef,0xef,0xdf,
0xef,0xdf,0xef,0xbf,0xef,0x7f,0xef},//片
{0xef,0xff,0xef,0x07,0xef,0x77,0x01,0x77,0xef,
0x77,0xef,0x77,0xc7,0x77,0xcb,0x77,
0xab,0x77,0xaf,0x77,0x6e,0xf7,0xee,0xf5,0xed,
0xf5,0xed,0xf5,0xeb,0xf9,0xef,0xff},//机
{0xf8,0x3f,0xe7,0xcf,0xdf,0xf7,0xbf,0xfb,0xb3,
0x9b,0x73,0x9d,0x7f,0xfd,0x7f,0xfd,
0x6f,0xed,0x67,0xcd,0xb3,0x9b,0xb8,0x3b,0xdf,
0xf7,0xe7,0xcf,0xf8,0x3f,0xff,0xff},//笑脸
{0xf9,0xbf,0xc7,0xaf,0xf7,0xb7,0xf7,0xb7,0xf7,
0xbf,0x00,0x01,0xf7,0xbf,0xf7,0xb7,
0xf1,0xd7,0xc7,0xcf,0x37,0xdf,0xf7,0xaf,0xf6,
0x6d,0xf7,0xf5,0xd7,0xf9,0xef,0xfd}};//我

unsigned char code Bmp[][32]={
{0xf9,0xbf,0xc7,0xaf,0xf7,0xb7,0xf7,0xb7,0xf7,
0xbf,0x00,0x01,0xf7,0xbf,0xf7,0xb7,
0xf1,0xd7,0xc7,0xcf,0x37,0xdf,0xf7,0xaf,0xf6,
0x6d,0xf7,0xf5,0xd7,0xf9,0xef,0xfd},//我
{0xff,0x07,0xc0,0x6f,0xed,0xef,0xf6,0xdf,0xc0,
0x01,0xdd,0xfd,0xbd,0xff,0xc0,0x03,
0xfb,0xff,0xf8,0x0f,0xf3,0xdf,0xf4,0xbf,0xef,
0x3f,0x9c,0xcf,0x73,0xf1,0xcf,0xfb},//爱
{0xf7,0xdf,0xf9,0xcf,0xfb,0xbf,0xc0,0x07,0xde,
0xf7,0xc0,0x07,0xde,0xf7,0xde,0xf7,
0xc0,0x07,0xde,0xf7,0xfe,0xff,0x00,0x01,0xfe,
0xff,0xfe,0xff,0xfe,0xff,0xfe,0xff},//单
{0xff,0xbf,0xef,0xbf,0xef,0xbf,0xef,0xbb,0xe0,
0x01,0xef,0xff,0xef,0xff,0xef,0xff,
0xe0,0x0f,0xef,0xef,0xef,0xef,0xef,0xef,0xdf,
0xef,0xdf,0xef,0xbf,0xef,0x7f,0xef},//片
{0xef,0xff,0xef,0x07,0xef,0x77,0x01,0x77,0xef,
0x77,0xef,0x77,0xc7,0x77,0xcb,0x77,
0xab,0x77,0xaf,0x77,0x6e,0xf7,0xee,0xf5,0xed,
0xf5,0xed,0xf5,0xeb,0xf9,0xef,0xff},//片
{0xf8,0x3f,0xe7,0xcf,0xdf,0xf7,0xbf,0xfb,0xb3,
0x9b,0x73,0x9d,0x7f,0xfd,0x7f,0xfd,
0x6f,0xed,0x67,0xcd,0xb3,0x9b,0xb8,0x3b,0xdf,
0xf7,0xe7,0xcf,0xf8,0x3f,0xff,0xff},//笑脸
};

register unsigned char i,j,k,m,l;

SCON=0x00; //串口工作模式0,移位寄存器方式
TMOD=0x01; //定时器T0工作方式1;16位方式
TR0=1; //启动定时器T0
P1=0x3f; //P1端口初值,允许接收,缓存,显示
IE=0x82; //允许定时器T0中断

while(1)
{
delay(1000);

for(i=0;i<32;i++) //显示效果:卷帘出
{
dispram[i]=Bmp[5][i];
huancun[i]=Cmp[4][i];
if(i%2)delay(70);
}

delay(100);
for(i=0;i<6;i++) //显示效果:上滚屏
{
for(j=0;j<16;j++)
{
for(k=0;k<15;k++)
{
huancun[k*BLKN]=huancun[(k+1)*BLKN];
huancun[k*BLKN+1]=huancun[(k+1)*BLKN+1];
dispram[k*BLKN]=dispram[(k+1)*BLKN];
dispram[k*BLKN+1]=dispram[(k+1)*BLKN+1];
}
huancun[30]=Bmp[i][j*BLKN];
huancun[31]=Bmp[i][j*BLKN+1];
dispram[30]=Bmp[i][j*BLKN];
dispram[31]=Bmp[i][j*BLKN+1];
delay(70);
}
}

delay(1000);
for(i=0;i<32;i++) //显示效果:卷帘出
{
dispram[i]=Bmp[5][i];
huancun[i]=Cmp[5][i];
if(i%2)delay(70);
}
for(i=0;i<6;i++) //显示效果,做跑马
{
for(j=0;j<2;j++)
for(k=1;k<9;k++)
{
for(l=0;l<16;l++)
{ huancun[l*BLKN]=huancun[l*BLKN]<<1|huancun[l*BLKN+1]>>7;
huancun[l*BLKN+1]=huancun[l*BLKN+1]<<1|Cmp[i][l*BLKN+j]>>(8-k);

dispram[l*BLKN]=dispram[l*BLKN]<<1|dispram[l*BLKN+1]>>7;
dispram[l*BLKN+1]=dispram[l*BLKN+1]<<1|Bmp[i][l*BLKN+j]>>(8-k);
}
delay(70);
}
}
delay(1000);
for(i=0;i<32;i++) //显示效果:卷帘出
{
dispram[i]=Bmp[5][i];
huancun[i]=Cmp[4][i];
if(i%2)delay(70);
}

for(i=1;i<7;i++) //显示效果:向下滚滚屏
{

for(j=16;j>0;j--)
{
for(k=15;k>0;k--)
{ huancun[k*BLKN]=huancun[(k-1)*BLKN];
huancun[k*BLKN+1]=huancun[(k-1)*BLKN+1];
dispram[k*BLKN]=dispram[(k-1)*BLKN];
dispram[k*BLKN+1]=dispram[(k-1)*BLKN+1];
}
huancun[0]=Bmp[i-1][(j-1)*BLKN];
huancun[1]=Bmp[i-1][(j-1)*BLKN+1];
dispram[0]=Bmp[i-1][(j-1)*BLKN];
dispram[1]=Bmp[i-1][(j-1)*BLKN+1];

delay(70);
}
}
delay(1000);
for(i=0;i<6;i++) //显示效果,又跑马
{
for(j=2;j>0;j--)
for(k=1;k<9;k++)
{
for(l=0;l<16;l++)
{
for(m=0;m<32;m++) //显示效果:卷帘出
{

dispram[m]=Bmp[5][m];

}
huancun[l*BLKN+1]=huancun[l*BLKN+1]>>1|huancun[l*BLKN]<<7;
huancun[l*BLKN]=huancun[l*BLKN]>>1|Bmp[i][l*BLKN+j-1]<<(8-k);
//dispram[l*BLKN+1]=dispram[l*BLKN+1]>>1|dispram[l*BLKN]<<7;
//dispram[l*BLKN]=dispram[l*BLKN]>>1|Bmp[i][l*BLKN+j-1]<<(8-k);
}
delay(70);
}
}

delay(1000);
for(i=0;i<32;i++) //显示效果:眷恋入
{
huancun[i]=0x00;
dispram[i]=0x00;

if(i%2)delay(70);
}
}
}
//延时函数
void delay(unsigned int dt)
{
register unsigned char bt;
for(;dt;dt--)
for(bt=0;bt<255;bt++);
}

//显示屏扫描(定时器T0中断)函数
void leddisplay(void)interrupt 1 using 1
{
register unsigned char i,j=BLKN;
TH0=0Xf8; //设定显示屏刷新率每秒62.5
TL0=0X30;
i=P1; //读取当前显示的行号
i=++i&0x0f; //行号加一,屏蔽高四位
do {

j--;
SBUF=huancun[i*BLKN+j]; //送显示数据
while(!TI);TI=0;
}while(j);j=2;
do {

j--;
SBUF=dispram[i*BLKN+j]; //送显示数据
while(!TI);TI=0;
}while(j);

//完成一行数据的发送
G=1; //消隐(关闭显示)
P1&=0xf0; //行号端口清零
RRCLK=1; //显示数据打入输出锁存器
P1|=i;
//写入行号
RRCLK=0; //所存显示数据
G=0;
//打开显示
}

你参考吧希望对你有帮助,行驱动也是74HC154,列是74HC595