1、LED点阵介绍
LED点阵由多个LED小灯构成,以8*8LED点阵介绍,实物图和内部原理图如下。
图7-2左侧8个引脚为内部LED小灯阳极,上侧8个引脚为阴极。
2、点亮LED点阵
2.1 原理
点亮LED点阵与点亮LED小灯原理相似,根据LED点阵电路图分析即可,详细见第三章。
2.2 点亮全部LED点阵程序
利用定时器中断和数码管动态显示原理,就不进行说明,详细见第六章
3、取模软件简单介绍
取模软件可以将LED点阵图形的数据转换为程序中的数据。取模软件中黑色为LED熄灭,值为1,白色为LED点亮,值为0。如下图绘制了一个心形。
下面来说明取模软件参数的选取。
取模方式:根据LED点阵结构原理图,PO口控制的是一行,选择“横向取模”,控制的是一列,则选择“纵向取模”。
字节倒序:根据LED点阵结构原理图,若PO口左侧控制的是低位,右侧控制高位,勾选该选项,否则不勾选。
4、点阵动画显示
原理:对多张图片进行取模,利用程序算法切换图片形成动画。
4.1 横向左右移动(I ❤ U)动画程序
//LED点阵I love you 左右横向移动
#include sbit ADDR0 = P1^0; sbit ADDR1 = P1^1; sbit ADDR2 = P1^2; sbit ADDR3 = P1^3; sbit ENLED = P1^4; unsigned char code image[60][8]={ //图片字模表 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, //往左动画 {0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F}, //动画帧2 {0xFF,0x3F,0x7F,0x7F,0x7F,0x7F,0x7F,0x3F}, {0xFF,0x1F,0x3F,0x3F,0x3F,0x3F,0x3F,0x1F}, {0xFF,0x0F,0x9F,0x9F,0x9F,0x9F,0x9F,0x0F}, {0xFF,0x87,0xCF,0xCF,0xCF,0xCF,0xCF,0x87}, {0xFF,0xC3,0xE7,0xE7,0xE7,0xE7,0xE7,0xC3}, {0xFF,0xE1,0x73,0x73,0x73,0xF3,0xF3,0xE1}, {0xFF,0x70,0x39,0x39,0x39,0x79,0xF9,0xF0}, {0xFF,0x38,0x1C,0x1C,0x1C,0x3C,0x7C,0xF8}, {0xFF,0x9C,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0xF3,0xF3,0xE1}, {0xFF,0xC3,0xE7,0xE7,0xE7,0xE7,0xE7,0xC3}, {0xFF,0x87,0xCE,0xCE,0xCE,0xCF,0xCF,0x87}, {0xFF,0x0E,0x9C,0x9C,0x9C,0x9E,0x9F,0x0F}, {0xFF,0x1C,0x38,0x38,0x38,0x3C,0x3E,0x1F}, {0xFF,0x39,0x70,0x70,0x70,0x78,0x7C,0x3E}, {0xFF,0x73,0xE0,0xE0,0xE0,0xF0,0xF8,0x7C}, {0xFF,0xE6,0xC0,0xC0,0xC0,0xE0,0xF0,0xF9}, {0xFF,0xCC,0x80,0x80,0x80,0xC0,0xE1,0xF3}, {0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7}, {0xFF,0x33,0x01,0x01,0x01,0x03,0x87,0xCF}, {0xFF,0x67,0x03,0x03,0x03,0x07,0x0F,0x9F}, {0xFF,0xCE,0x06,0x06,0x06,0x0E,0x1E,0x3F}, {0xFF,0x9C,0x0C,0x0C,0x0C,0x1C,0x3C,0x7E}, {0xFF,0x39,0x19,0x19,0x19,0x39,0x78,0xFC}, {0xFF,0x73,0x33,0x33,0x33,0x73,0xF0,0xF8}, {0xFF,0xE6,0x66,0x66,0x66,0xE6,0xE0,0xF0}, {0xFF,0xCC,0xCC,0xCC,0xCC,0xCC,0xC0,0xE1}, {0xFF,0x99,0x99,0x99,0x99,0x99,0x81,0xC3}, {0xFF,0x33,0x33,0x33,0x33,0x33,0x03,0x87}, {0xFF,0x67,0x67,0x67,0x67,0x67,0x07,0x0F}, {0xFF,0xCF,0xCF,0xCF,0xCF,0xCF,0x0F,0x1F}, {0xFF,0x9F,0x9F,0x9F,0x9F,0x9F,0x1F,0x3F}, {0xFF,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x7F}, {0xFF,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0xFF}, //动画帧60 }; void main() { EA = 1;//使能总使能 ENLED = 0;//使能U4,选择点亮点阵 ADDR3 = 0; TMOD = 0x01;//为T0配置模式一 TH0 = 0xFC;//为T0赋值,定时1ms TL0 = 0x67; ET0 = 1; //使能T0中断 TR0 = 1; //开启T0 while(1); } void intertuptTimer0() interrupt 1 { static unsigned char i = 0;//动态扫描索引 static unsigned int tmr = 0;//250ms软件定时器 static unsigned char index = 0;//图片刷新索引 TH0 = 0xFC; //重新加载初值 TL0 = 0x67; //以下代码为点阵动态扫描刷新 P0 = 0xFF;//消除鬼影 switch(i) { case 0: ADDR2=0;ADDR1=0;ADDR0=0;i++;P0=image[index][0];break; case 1: ADDR2=0;ADDR1=0;ADDR0=1;i++;P0=image[index][1];break; case 2: ADDR2=0;ADDR1=1;ADDR0=0;i++;P0=image[index][2];break; case 3: ADDR2=0;ADDR1=1;ADDR0=1;i++;P0=image[index][3];break; case 4: ADDR2=1;ADDR1=0;ADDR0=0;i++;P0=image[index][4];break; case 5: ADDR2=1;ADDR1=0;ADDR0=1;i++;P0=image[index][5];break; case 6: ADDR2=1;ADDR1=1;ADDR0=0;i++;P0=image[index][6];break; case 7: ADDR2=1;ADDR1=1;ADDR0=1;i=0;P0=image[index][7];break; default:break; } //以下代码完成每250ms改变一帧图像 tmr++; if(tmr >= 250)//达到250ms改变一次图片索引 { tmr = 0; index++; if(index >= 60) //图片索引达60后归零 { index = 0; } } } 左右移动动画和上下移动动画,会因LED点阵原理图中是横向取模或纵向取模而显得难度不同,若LED点阵是横向取模,则上下移动动画容易实现(因不同图片字模数据是连续的),而左右移动动画不易实现(因不同图片字模数据是不连续的)。博主用的LED点阵为横向取模,上下移动动画程序就不展示了,上面展示了左右移动动画程序。 4.2 LED点阵动画9 - 0倒计时程序 //LED点阵动画9-0倒计时 #include sbit ADDR0 = P1^0; sbit ADDR1 = P1^1; sbit ADDR2 = P1^2; sbit ADDR3 = P1^3; sbit ENLED = P1^4; unsigned char code image[11][8]={ //图片字模表 {0xC3, 0x81, 0x99, 0x99, 0x99, 0x99, 0x81, 0xC3}, //数字0 {0xEF, 0xE7, 0xE3, 0xE7, 0xE7, 0xE7, 0xE7, 0xC3}, //数字1 {0xC3, 0x81, 0x9D, 0x87, 0xC3, 0xF9, 0xC1, 0x81}, //数字2 {0xC3, 0x81, 0x9D, 0xC7, 0xC7, 0x9D, 0x81, 0xC3}, //数字3 {0xCF, 0xC7, 0xC3, 0xC9, 0xC9, 0x81, 0xCF, 0xCF}, //数字4 {0x81, 0xC1, 0xF9, 0xC3, 0x87, 0x9D, 0x81, 0xC3}, //数字5 {0xC3, 0x81, 0xF9, 0xC1, 0x81, 0x99, 0x81, 0xC3}, //数字6 {0x81, 0x81, 0x9F, 0xCF, 0xCF, 0xE7, 0xE7, 0xE7}, //数字7 {0xC3, 0x81, 0x99, 0xC3, 0xC3, 0x99, 0x81, 0xC3}, //数字8 {0xC3, 0x81, 0x99, 0x81, 0x83, 0x9F, 0x83, 0xC1}, //数字9 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //全亮 }; void main() { EA = 1;//使能总使能 ENLED = 0;//使能U4,选择点亮点阵 ADDR3 = 0; TMOD = 0x01;//为T0配置模式一 TH0 = 0xFC;//为T0赋值,定时1ms TL0 = 0x67; ET0 = 1; //使能T0中断 TR0 = 1; //开启T0 while(1); } void intertuptTimer0() interrupt 1 { static unsigned char i = 0;//动态扫描索引 static unsigned int tmr = 0;//1s软件定时器 static signed char index = 9;//图片刷新索引 TH0 = 0xFC; //重新加载初值 TL0 = 0x67; //以下代码为点阵动态扫描刷新 P0 = 0xFF;//消除鬼影 switch(i) { case 0: ADDR2=0;ADDR1=0;ADDR0=0;i++;P0=image[index][0];break; case 1: ADDR2=0;ADDR1=0;ADDR0=1;i++;P0=image[index][1];break; case 2: ADDR2=0;ADDR1=1;ADDR0=0;i++;P0=image[index][2];break; case 3: ADDR2=0;ADDR1=1;ADDR0=1;i++;P0=image[index][3];break; case 4: ADDR2=1;ADDR1=0;ADDR0=0;i++;P0=image[index][4];break; case 5: ADDR2=1;ADDR1=0;ADDR0=1;i++;P0=image[index][5];break; case 6: ADDR2=1;ADDR1=1;ADDR0=0;i++;P0=image[index][6];break; case 7: ADDR2=1;ADDR1=1;ADDR0=1;i=0;P0=image[index][7];break; default:break; } //以下代码完成每1s改变一帧图像 tmr++; if(tmr >= 1000)//达到1s改变一次图片索引 { tmr = 0; index--; if(index < 0) //图片索引达-1后赋值为10 { index = 10; } } } 4.3 流水灯、数码管和LED点阵同时点亮程序 #include sbit ADDR0 = P1^0; sbit ADDR1 = P1^1; sbit ADDR2 = P1^2; sbit ADDR3 = P1^3; sbit ENLED = P1^4; void main() { EA = 1; //使能总中断 ENLED = 0; //使能U3,U4,因动态扫描,点亮数码管,ADDR0-3需动态变化 TMOD = 0x10;//配置T1为模式一 TH1 = 0xFE; //为T1赋0xFE33,定时0.5ms TL1 = 0x33; ET1 = 1; //使能T1中断 TR1 = 1;//开启定时器T1 while(1);//在语句中一直循环,直到定时器T1中断 } //以下为定时器T1的中断函数 void InterruptTimer1() interrupt 3 { static unsigned char i = 0; //动态扫描索引 TH1 = 0xFE; //为T1赋0xFE33,定时0.5ms TL1 = 0x33; //以下代码为LED小灯、数码管和LED点阵动态扫描 P0 = 0xff;//显示消隐 switch(i) { //点亮LED小灯部分 case 0: ADDR3=1;ADDR2=1;ADDR1=1;ADDR0=0;i++;P0=0;break; //数码管的动态扫描部分 case 1: ADDR3=1;ADDR2=0;ADDR1=0;ADDR0=0;i++;P0=0;break; case 2: ADDR3=1;ADDR2=0;ADDR1=0;ADDR0=1;i++;P0=0;break; case 3: ADDR3=1;ADDR2=0;ADDR1=1;ADDR0=0;i++;P0=0;break; case 4: ADDR3=1;ADDR2=0;ADDR1=1;ADDR0=1;i++;P0=0;break; case 5: ADDR3=1;ADDR2=1;ADDR1=0;ADDR0=0;i++;P0=0;break; case 6: ADDR3=1;ADDR2=1;ADDR1=0;ADDR0=1;i++;P0=0;break; //LED点阵的动态扫描部分 case 7: ADDR3=0;ADDR2=0;ADDR1=0;ADDR0=0;i++;P0=0;break; case 8: ADDR3=0;ADDR2=0;ADDR1=0;ADDR0=1;i++;P0=0;break; case 9: ADDR3=0;ADDR2=0;ADDR1=1;ADDR0=0;i++;P0=0;break; case 10: ADDR3=0;ADDR2=0;ADDR1=1;ADDR0=1;i++;P0=0;break; case 11: ADDR3=0;ADDR2=1;ADDR1=0;ADDR0=0;i++;P0=0;break; case 12: ADDR3=0;ADDR2=1;ADDR1=0;ADDR0=1;i++;P0=0;break; case 13: ADDR3=0;ADDR2=1;ADDR1=1;ADDR0=0;i++;P0=0;break; case 14: ADDR3=0;ADDR2=1;ADDR1=1;ADDR0=1;i=0;P0=0;break; default:break; } }
上一篇:【自学51单片机】8 -- 按键的学习,单片机最小系统
下一篇:keil中C51关键字code用法
推荐阅读最新更新时间:2024-11-22 13:45
设计资源 培训 开发板 精华推荐
- LTC3265EFE 低噪声 +7V/-2V 电源的典型应用电路来自一个单端 5V 输入电源(频率 = 200kHz)
- 具有 DCR 检测、非线性控制和 DCR 温度补偿的 LTC3867EUF 1.5V、15A 输出的典型应用电路
- 电流监控芯片MAX4080FAUA 验证板
- LTC3553 的典型应用 - 具有锂离子充电器、LDO 和降压稳压器的微功率 USB 电源管理器
- 2.5V 输出 ADR391B 微功耗、低噪声精密电压基准的典型应用
- LT3461ES6 3.3V 至 15V 升压转换器的典型应用电路
- 毕业设计-智能加湿器
- 使用 ON Semiconductor 的 FAN5612 的参考设计
- STM32CoreBoard—V1.0.0
- 【天津工业大学】差分放大电路测试仪 滕天淇