赞
踩
按颜色:单色、双色、全彩
按像素:8*8、16*16等(大规模的LED点阵通常由很多个小点阵拼接而成。
LED点阵屏的显示原理:
直接接在I/O口的话,需要接一个三极管来缓冲一下,NPN型号上接VCC,下接限流电阻,低电平导通到阳极。高电平三极管截止不接通停止。PNP型号上接VCC,左边I/O口高电平给1三极管导通,给低电平0三极管截止.
注意:寄存器地址能够被8整除的才可以进行位操作,不可以被8整除的不可以进行位操作。
SER需要赋值在先,QH为高位,QH往前推位,把第八位取出来,即最高位。最高位若是从0开始那么最高位是7,用与和或进行相取。SERCLK上升沿移位,给高电平使他移位,单片机初始化以后所有的I/O口都为高电平,所以一上电以后要把它的值先赋予0,再在另一个函数74HC595中给高电平1使他上升移位。怎么输出?只需要给RCLK一个高电平,也需要初始化为低电平。
方法一和二,代码段中注释的为方法二
- #include <REGX52.H>
-
- sbit RCK=P3^5; //因为在51中RCLK已定义,所以重新定义一个为RCK
- sbit SCK=P3^6; //同理SRCLK
- sbit SER=P3^4; //SER
-
- void _74HC595_WriteByte(unsigned char Byte)
- {
- unsigned char i;
- for(i=0;i<8;i++)
- {
- SER=Byte&(0x80>>i);
- SCK=1;
- SCK=0;
- }
- RCK=1;
- RCK=0;
-
- // Byte&0x80; //如果第八位为1,&0x80=0x80;第八位为0,&0x80=0.
- // SER=Byte&0x80; //把Byte&0x80的值直接赋给SER.电平1高0低
- // SCK=1;
- // SCK=0; //清0.为下一次移位做准备。已经把Byte的最高位移进去了
- // SER=Byte&0x40; //次高位移进去了相当于第二位
- // SCK=1;
- // SCK=0;
- // SER=Byte&0x20; //第三位
- // SCK=1;
- // SCK=0;
- }
-
- void main()
- {
- SCK=0;
- RCK=0;
- _74HC595_WriteByte(0xAA); //一半1一半0
- while (1)
- {
- }
- }

- #include <REGX52.H>
- #include "Delay.h"
-
- sbit RCK=P3^5; //因为在51中RCLK已定义,所以重新定义一个为RCK
- sbit SCK=P3^6; //同理SRCLK
- sbit SER=P3^4; //SER
-
- #define __MATRIX_LED_PORT P0
-
- /**
- *@brief 74HC595写入一个字节
- *@param Byte要写入的字节
- *@retval 无
- */
-
- void _74HC595_WriteByte(unsigned char Byte)
- {
- unsigned char i;
- for(i=0;i<8;i++)
- {
- SER=Byte&(0x80>>i);
- SCK=1;
- SCK=0;
- }
- RCK=1;
- RCK=0;
-
- }
-
- /**
- *@brief LED点阵屏显示一列数据
- *@param Column 要选择的列,范围:0~7,0在最左边
- *@param Data 选择列显示的数据,高位在上,1为亮,0为灭
- *@retval 无
- */
-
- void MatrixLED_ShowColumn(unsigned char Column,Data) //列,段码
- {
- _74HC595_WriteByte(Data);
- // if (Column==0){P0=~0x80;} //方法一
- // if (Column==1){P0=~0x40;}
- __MATRIX_LED_PORT=~(0x80>>Column);
- Delay(1);
- __MATRIX_LED_PORT=0xFF;
- }
-
- void main()
- {
- SCK=0;
- RCK=0;
- while (1)
- {
- MatrixLED_ShowColumn(0,0x3C); //段选,位选,延时,位清零
- MatrixLED_ShowColumn(1,0x42);
- MatrixLED_ShowColumn(2,0xA9);
- MatrixLED_ShowColumn(3,0x85);
- MatrixLED_ShowColumn(4,0x85);
- MatrixLED_ShowColumn(5,0xA9);
- MatrixLED_ShowColumn(6,0x42);
- MatrixLED_ShowColumn(7,0x3C);
- }
- }

Delay.c
-
- void Delay(unsigned int xms)
- {
- unsigned char i, j;
- while(xms--)
- {
- i = 2;
- j = 239;
- do
- {
- while (--j);
- } while (--i);
- }
- }
-
Delay.h
- #ifndef __DELAY_H__
- #define __DELAY_H__
-
- void Delay(unsigned int xms);
-
- #endif
可以采用下面的软件进行自动取模:
链接:https://pan.baidu.com/s/1kGOitMYpuuNJNQBlrR386Q?pwd=5151
提取码:5151
文件解压密码为:51
代码如下:
- #include <REGX52.H>
- #include "Delay.h"
- #include "MatrixLED.h"
-
- unsigned char Animation[]={
- 0xFF,0x08,0x08,0x08,0xFF,0x00,0x0E,0x15,0x15,0x15,0x08,0x00,0x7E,0x01,0x02,0x00,
- 0x7E,0x01,0x02,0x00,0x0E,0x11,0x11,0x0E,0x00,0x7D,0x00,0x00,0x00,0x00,0x00,0x00,
- };
-
- void main()
- {
- unsigned char i,Offset=3,Count=0;
- MatrixLED_Init();
- while (1)
- {
- for (i=0;i<8;i++)
- {
- MatrixLED_ShowColumn(i,Animation[i+Offset]); //段选,位选,延时,位清零
-
- }
- Count++;
- if (Count>10)
- {
- Count=0;
- Offset++;
-
- }
- }
- }
-
- //"MatrixLED.c"
- #include <REGX52.H>
- #include "Delay.h"
-
- sbit RCK=P3^5; //因为在51中RCLK已定义,所以重新定义一个为RCK
- sbit SCK=P3^6; //同理SRCLK
- sbit SER=P3^4; //SER
-
- #define __MATRIX_LED_PORT P0
-
- /**
- *@brief 74HC595写入一个字节
- *@param Byte要写入的字节
- *@retval 无
- */
-
- void _74HC595_WriteByte(unsigned char Byte)
- {
- unsigned char i;
- for(i=0;i<8;i++)
- {
- SER=Byte&(0x80>>i);
- SCK=1;
- SCK=0;
- }
- RCK=1;
- RCK=0;
-
- }
-
- /**
- *@brief 点阵屏初始化
- *@param 无
- *@retval 无
- */
- void MatrixLED_Ini ()
- {
- SCK=0;
- RCK=0;
- }
-
- /**
- *@brief LED点阵屏显示一列数据
- *@param Column 要选择的列,范围:0~7,0在最左边
- *@param Data 选择列显示的数据,高位在上,1为亮,0为灭
- *@retval 无
- */
-
- void MatrixLED_ShowColumn(unsigned char Column,Data) //列,段码
- {
- _74HC595_WriteByte(Data);
- __MATRIX_LED_PORT=~(0x80>>Column);
- Delay(1);
- __MATRIX_LED_PORT=0xFF;
- }
- //"MatrixLED.h"
- #ifndef __MATRIX_LED_H_
- #define __MATRIX_LED_H_
-
- void MatrixLED_ShowColumn(unsigned char Column,Data);
- void MatrixLED_Ini ();
-
-
- #endif
-
- //"Delay.c"
- void Delay(unsigned int xms)
- {
- unsigned char i, j;
- while(xms--)
- {
- i = 2;
- j = 239;
- do
- {
- while (--j);
- } while (--i);
- }
- }
- //"Delay.h"
- #ifndef __DELAY_H__
- #define __DELAY_H__
-
- void Delay(unsigned int xms);
-
-
- #endif
-
-

74HC595
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。