最近学了LED点阵,并用了三种方式显示字母组,分别为按键控制显示,自动变换显示,和滚动显示
第一种
#include"reg51.h"
#include typedef unsigned char u8; typedef unsigned int u16; sbit RCLK=P3^5; sbit SRCLK=P3^6; sbit SER=P3^4; #define GPIP_KEY P1 #define GPIO_DIG P0 u8 keyvalue; u8 code duan[16][8]={{0x00,0x42,0x7e,0x42,0x42,0x3c,0x00,0x00},//对字母编码 {0x00,0x11,0x12,0x14,0xF8,0x14,0x12,0x11}, {0x00,0x00,0x60,0x10,0x0E,0x10,0x60,0x00}, {0x18,0x24,0x22,0x11,0x22,0x24,0x18,0x00}, {0x00,0x42,0x7E,0x42,0x02,0x06,0x00,0x00}, {0x00,0x06,0x61,0x91,0x89,0x86,0x60,0x00}, {0x81,0xFF,0x81,0x60,0x18,0x86,0xFF,0x81}}; u8 code ledwei[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//扫描数组 void delay(u16 i) { while(i--); } void keydown() //按键函数 { u8 a; GPIP_KEY=0x0f; if(GPIP_KEY!=0x0f) { delay(1000); if(GPIP_KEY!=0x0f) { GPIP_KEY=0x0f; switch(GPIP_KEY) { case(0x07): keyvalue=0; break; case(0x0b): keyvalue=1; break; case(0x0d): keyvalue=2; break; case(0x0e): keyvalue=3; break; } GPIP_KEY=0xf0; switch(GPIP_KEY) { case(0x70): keyvalue=keyvalue; break; case(0xb0): keyvalue=keyvalue+4; break; case(0xd0): keyvalue=keyvalue+8; break; case(0xe0): keyvalue=keyvalue+12; break; } while((a<50)&&(GPIP_KEY!=0xf0)) { delay(1000); a++; } } } } void hc595sendbyte(u8 dat) //hc595模块定义 { u8 a; SRCLK=0; RCLK=0; for(a=0;a<8;a++) { SER=dat>>7; dat<<=1; SRCLK=1; _nop_(); _nop_(); SRCLK=0; } RCLK=1; _nop_(); _nop_(); SRCLK=0; } void main() { u8 i; while(1) { keydown(); for(i=0;i<8;i++) { P0=ledwei[i]; hc595sendbyte(duan[keyvalue][i]); delay(100); hc595sendbyte(0x00); //LED矩阵消影 } } } 第二种: #include"reg51.h" #include typedef unsigned char u8; typedef unsigned int u16; sbit RCLK=P3^5; sbit SRCLK=P3^6; sbit SER=P3^4; #define GPIP_KEY P1 #define GPIO_DIG P0 u8 keyvalue; u8 code duan[7][8]={{0x00,0x42,0x7e,0x42,0x42,0x3c,0x00,0x00},//字母段设置 {0x00,0x11,0x12,0x14,0xF8,0x14,0x12,0x11}, {0x00,0x00,0x60,0x10,0x0E,0x10,0x60,0x00}, {0x18,0x24,0x22,0x11,0x22,0x24,0x18,0x00}, {0x00,0x42,0x7E,0x42,0x02,0x06,0x00,0x00}, {0x00,0x06,0x61,0x91,0x89,0x86,0x60,0x00}, {0x81,0xFF,0x81,0x60,0x18,0x86,0xFF,0x81}}; u8 code ledwei[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//扫描段 void delay(u16 i) { while(i--); } void hc595sendbyte(u8 dat) //hc595模块设置 { u8 a; SRCLK=0; RCLK=0; for(a=0;a<8;a++) { SER=dat>>7; dat<<=1; SRCLK=1; _nop_(); _nop_(); SRCLK=0; } RCLK=1; _nop_(); _nop_(); SRCLK=0; } void main() { while(1) { u8 i,j,t=100; for(i=0;i<7;i++) { while(t--) { for(j=0;j<8;j++) { P0=ledwei[j]; hc595sendbyte(duan[i][j]); delay(100); hc595sendbyte(0x00);//LED矩阵消影 } } t=100; } hc595sendbyte(0x00); } } 第三种 #include"reg51.h" #include typedef unsigned char u8; typedef unsigned int u16; sbit RCLK=P3^5; sbit SRCLK=P3^6; sbit SER=P3^4; #define GPIP_KEY P1 #define GPIO_DIG P0 u8 keyvalue; u8 code duan[]={0x00,0x00,0x00,0x00,0x42,0x7E,0x42,0x00, //I 0x41,0x7F,0x41,0x01,0x01,0x03,0x00, //L 0x3C,0x42,0x42,0x42,0x3C,0x00, //O 0x70,0x0C,0x02,0x0C,0x70,0x00, //V 0x7F,0x49,0x49,0x49,0x49,0x00, //E 0x60,0x10,0x0E,0x10,0x60,0x00, //Y 0x3C,0x42,0x42,0x42,0x3C,0x00, //O 0x40,0x7C,0x42,0x01,0x01,0x42,0x7C,0x40 //U }; u8 code ledwei[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//扫描编码段 void delay(u16 i) { while(i--); } void hc595sendbyte(u8 dat)//hc595模块初始化 { u8 a; SRCLK=0; RCLK=0; for(a=0;a<8;a++) { SER=dat>>7; dat<<=1; SRCLK=1; _nop_(); _nop_(); SRCLK=0; } RCLK=1; _nop_(); _nop_(); SRCLK=0; } void main() { while(1) { u8 i,j,t=30,q=0; for(i=0;i<46;i++) { while(t--) { for(j=i;j<8+i;j++) { P0=ledwei[q++]; hc595sendbyte(duan[j]); delay(100); hc595sendbyte(0x00); //LED矩阵消影 } q=0; } t=30; } } }
上一篇:51例程---led点阵
下一篇:利用51单片机的LED点阵输出生日快乐
推荐阅读最新更新时间:2024-11-11 17:34
设计资源 培训 开发板 精华推荐
- 具有 9V 输出的 LT1424CN8-9 隔离式反激式开关稳压器的典型应用电路
- LDK130C12R 1.2V、300 mA 低静态电流极低噪声 LDO 的典型应用可调版本电路
- 数字2.1功放板
- VG7050ECN-EVB、VG7050ECN 评估板,通过 I2C 总线设置寄存器
- DI-152 - 3W、超宽范围工业输入电源
- 使用 Analog Devices 的 LT3420EDD 的参考设计
- ADA4610-1ARZ-R7等效前置放大光电二极管电路典型应用电路
- MC78M08BDTG 8V 电流升压稳压器的典型应用
- 使用 LTC2370IMS-16、16 位、2Msps、伪差分单极 SAR ADC 的典型应用
- LT6106 的典型应用 - 低成本、36V 高侧电流检测放大器