带RGB(红绿蓝)的16X16点阵仿真图如下:
16X16RGB点阵的单片机源程序如下:
- /*--------------------------------------
- 多个16*16LED显示演示程序
- MCU AT89C52 XAL 24MHz
- --------------------------------------*/
- //以下程序能实现多个16*16LED屏的多个字符显示,显示方式有整行上移、帘入帘出、左移、右移//
- #include "reg52.h"
- #define BLKN 6 //列锁存器数(=LED显示字数*2)
- #define TOTAL 102 //待显示字个数,本例共20个
- #define TOTAL0 99
- #define TOTAL1 96
- #define TOTAL2 33
- #define TOTAL3 128
- #define TOTAL4 15
- #define TOTAL5 84
- #define TOTAL6 54
- #define CONIO P1 //显示控制口
- sbit G=CONIO^7; //CONIO.7为154译码器显示允许控制信号端口,0时输出,1时输出全为高阻态.
- sbit CLK=CONIO^6; //CONIO.6为595输出锁存器时钟信号端,1时输出数据,从1到0时锁存输出数据.
- sbit SCLR=CONIO^5; //CONIO.5为595移位寄存器清零口,平时为1,为0时,输出全为0.
- unsigned char idata dispram[(BLKN/2)*32]={0}; //显示区缓存,四字共4*32单元
- //
- //**************45度No.1字模表******************//
- unsigned char code Bmp[][32]={
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- …………限于本文篇幅 余下代码请从51黑下载附件…………
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x66,0x64,0x99,0x99,0x66,0x66,0x99,0x99}//16第四水流
- };
- //**************笑脸字模表******************//
- unsigned char code Bmp3[][32]={
- {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- …………限于本文篇幅 余下代码请从51黑下载附件…………
- 0xFE,0x00,0xFE,0xC0,0xFC,0xF0,0xFC,0xFC,0xF8,0xFE,0xF8,0xFF,0xF0,0xFF,0xE0,0xFF},//5红绿蓝
- };
- //**************风扇4字模表******************//
- unsigned char code Bmp8[][32]={
- {0x1F,0xF8,0x0F,0xF0,0x07,0xE0,0x83,0xC1,0xC1,0x83,0xE1,0x87,0xF1,0x0F,0xFC,0x7F,
- …………限于本文篇幅 余下代码请从51黑下载附件…………
- 0xFE,0x00,0xFE,0xC0,0xFC,0xF0,0xFC,0xFC,0xF8,0xFE,0xF8,0xFF,0xF0,0xFF,0xE0,0xFF},//5一到七
- };
- //**************向上流动字体字模表******************//
- unsigned char code Bmp9[][32]={
- {0xFF,0x7F,0xFF,0x7F,0x03,0x7F,0xFA,0x01,0x7A,0xFB,0xB5,0xB7,0xD7,0xBF,0xEF,0xBF,
- …………限于本文篇幅 余下代码请从51黑下载附件…………
- 0x6F,0xED,0x67,0xCD,0xB3,0x9B,0xB8,0x3B,0xDF,0xF7,0xE7,0xCF,0xF8,0x3F,0xFF,0xFF}//:)28
- };
- //**************内帘出心型图字模表******************//
- unsigned char code Bmp10[][32]={
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- …………限于本文篇幅 余下代码请从51黑下载附件…………
- 0xF0,0x0F,0xF8,0x1F,0xFC,0x3F,0xFE,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,//红
- 0xFF,0xFF,0xC7,0xE3,0x81,0x81,0x0C,0x30,0x1E,0x78,0x3F,0xFC,0x3F,0xFC,0x1F,0xF8,
- 0x8F,0xF1,0xC7,0xE3,0xE3,0xC7,0xF1,0x8F,0xF8,0x1F,0xFC,0x3F,0xFE,0x7F,0xFF,0xFF,//绿蓝
- 0xFF,0xFF,0xC7,0xE3,0x81,0x81,0x0C,0x30,0x1E,0x78,0x3F,0xFC,0x3F,0xFC,0x1F,0xF8,
- 0x8F,0xF1,0xC7,0xE3,0xE3,0xC7,0xF1,0x8F,0xF8,0x1F,0xFC,0x3F,0xFE,0x7F,0xFF,0xFF,//绿蓝
- };
- //
- /***********延时函数(约1毫秒)************/
- void delay(unsigned int dt)
- {
- register unsigned char bt;
- for (; dt; dt--)
- for (bt=0; bt<255; bt++);
- }
- //
- /*****************主函数 *********************/
- void main(void)
- {
- register unsigned char i,j,k,l,q,w,a;
- //初始化
- SCON = 0x00; //串口工作模式0:移位寄存器方式
- TMOD = 0x01; //定时器T0工作方式1:16位方式
- TR0 = 1; //启动定时器T0
- CONIO = 0x3f; //CONIO端口初值
- IE = 0x82; //允许定时器T0中断
- //
- while (1)
- {
- //初始化黑屏
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=0xff;}
- }
- delay(1000);
- //45度显示No.1
- for (w=0;w<TOTAL*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp[q+w*BLKN/2][i];}
- }
- delay(150);
- }
- //45度显示No.1
- for (w=0;w<TOTAL0*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp0[q+w*BLKN/2][i];}
- }
- delay(150);
- }
- delay(1000);
- //显示海豚1
- for (w=0;w<TOTAL1*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp1[q+w*BLKN/2][i];}
- }
- delay(150);
- }
- //显示海豚2
- for (w=0;w<TOTAL1*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp2[q+w*BLKN/2][i];}
- }
- delay(150);
- }
- delay(1000);
- //显示笑脸
- for (a=0;a<3;a++)
- {
- for (w=0;w<TOTAL2*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp3[q+w*BLKN/2][i];}
- }
- delay(250);
- }
- }
- delay(1000);
- //外帘入图案
- for (w=0;w<TOTAL3*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp4[q+w*BLKN/2][i];}
- }
- delay(200);
- }
- delay(1000);
- //显示内帘出图案
- for (w=0;w<TOTAL6*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp10[q+w*BLKN/2][i];}
- }
- delay(150);
- }
- delay(1000);
- //显示风扇1
- for (a=0;a<3;a++)
- {
- for (w=0;w<TOTAL4*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp5[q+w*BLKN/2][i];}
- }
- delay(120);
- }
- }
- //显示风扇2
- for (a=0;a<3;a++)
- {
- for (w=0;w<TOTAL4*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp6[q+w*BLKN/2][i];}
- }
- delay(120);
- }
- }
- //显示风扇3
- for (a=0;a<3;a++)
- {
- for (w=0;w<TOTAL4*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp7[q+w*BLKN/2][i];}
- }
- delay(120);
- }
- }
- //显示风扇4
- for (a=0;a<3;a++)
- {
- for (w=0;w<TOTAL4*2/BLKN;w++)
- {
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=Bmp8[q+w*BLKN/2][i];}
- }
- delay(120);
- }
- }
- //初始化黑屏
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=0xff;}
- }
- //向上移动汉字
- for (i=0; i<TOTAL5*2/BLKN; i++)
- {
- for (j=0; j<16; j++)
- {
- for (k=0; k<15; k++)
- {
- for(q=0;q<BLKN/2;q++)
- {dispram[k*2+q*32] = dispram[(k+1)*2+q*32];dispram[k*2+1+q*32] = dispram[(k+1)*2+1+q*32];}
- }
- for(q=0;q<BLKN/2;q++)
- {dispram[30+q*32] = Bmp9[q+i*BLKN/2][j*2];dispram[31+q*32] = Bmp9[q+i*BLKN/2][j*2+1];}
- delay(80);
- }
- }
- delay(1000);
- //卷帘出黑屏
- for (i=0;i<32;i++)
- {
- for(q=0;q<BLKN/2;q++) {dispram[i+q*32]=0xff;}
- if (i%2) delay(100);
- }
- delay(1000);
- }
- }
- //主函数结束
- //
- /**********显示屏扫描(定时器T0中断)函数**********/
- void leddisplay(void) interrupt 1 using 1
- {
- register unsigned char m, n=BLKN;
- TH0 = 0xFc; //设定显示屏刷新率每秒62.5帧(16毫秒每帧)
- TL0 = 0x18;
- m = CONIO; //读取当前显示的行号
- m = ++m & 0x0f; //行号加1,屏蔽高4位
- do {
- n--;
- SBUF = dispram[m*2+(n/2)*30 + n]; //送显示数据
- while (!TI); TI = 0;
- }while (n); //完成一行数据的发送
- G = 1; //消隐(关闭显示)
- CONIO &= 0xf0; //行号端口清○
- CLK=1; //显示数据打入输出锁存器
- CONIO |= m; //写入行号
- CLK=0; //锁存显示数据
- G = 0; //打开显示
- }
- //
复制代码
所有资料51hei提供下载:
16X16RGB 仿真和程序.rar
(149.31 KB, 下载次数: 90)
|