51单片机基于74HC595级联驱动16X16LED点阵

电路图:

 

原理:

  首先Protues基础库件里是没有16X16的点阵的,需要从网上下载或者是自己DIY出来一个,我就是对着百度DIY出来的,建议大家有条件的话也尝试DIY一下,增强对点阵电路的了解。不想DIY的话就去下载吧,有时间我会把这套电路图和16x16设计的电路图放上来。

  本次实验是利用74HC595(位移寄存器的一种)级联,节省IO口。至于74HC959的原理自己百度。

  下面上代码(刚刚入坑单片机第四天,大佬勿喷):

  

 1 #include <reg51.h>
 2 //16X16点阵LED双74HC595联级(2X2个74HC595)驱动程序
 3 sbit baseDS_0 = P3^0;//0号74HC595串行数据输入口
 4 sbit baseSTCP_0 = P3^1;//0号74595 并行储存寄存器输出 上升沿触发
 5 sbit baseSHCP_0 = P3^2;//0号74HC595 位移寄存器(使0号74HC595的Qs口位移)
 6 
 7 sbit baseDS_1 = P3^4;//1号74HC595串行数据输入口
 8 sbit baseSTCP_1 = P3^5;//1号74595 并行储存寄存器输出 上升沿触发
 9 sbit baseSHCP_1 = P3^6;//0号74HC595 位移寄存器(使0号74HC595的Qs口位移)
10 typedef unsigned int u16;      //对数据类型进行声明定义
11 typedef unsigned char u8;
12 
13 code u16 LAB[16] = //扫描行数据16位二进制轮转
14                                     {
15                                     0X8000,0X4000,0X2000,0X1000,0X0800,0X0400,0X0200,0X0100,
16                                     0X0080,0X0040,0X0020,0X0010,0X0008,0X0004,0X0002,0X0001
17                                     };
18 code u16 inData[2][16] = {
19 {0x0000,0x0000,0x0000,0x000C,0x080C,0x080C,0x180C,0x3FFC,0x7FFC,0x000C,0x000C,0x000C,0x000C,0x0000,0x0000,0x0000},//1
20 {0x0022,0x0022,0x0024,0x7FA4,0x4928,0x4930,0x4920,0x7FFF,0x4920,0x4930,0x4928,0x7FA4,0x0024,0x0022,0x0022,0x0000},/*"果",0*/
21 };
22 //{0x0000,0x0000,0x0000,0x000C,0x080C,0x080C,0x180C,0x3FFC,0x7FFC,0x000C,0x000C,0x000C,0x000C,0x0000,0x0000,0x0000},/*"未命名文件",0*/
23 //{0x0022,0x0022,0x0024,0x7FA4,0x4928,0x4930,0x4920,0x7FFF,0x4920,0x4930,0x4928,0x7FA4,0x0024,0x0022,0x0022,0x0000},/*"果",0*/
24 void Hc595SendByte(char c,u16 dat)//操作74HC595函数 
25 {
26     u16 a;
27     if(!c){//sbit比较特殊 先这么玩
28             baseSHCP_0=0;
29             baseSTCP_0=0;
30             for(a=0;a<16;a++)
31             {
32                 baseDS_0=dat>>15;
33                 dat<<=1;
34                 baseSHCP_0=1;
35                 baseSHCP_0=0;    
36             }
37             baseSTCP_0=1;
38             baseSTCP_0=0;
39     }else{
40             baseSHCP_1=0;
41             baseSTCP_1=0;
42             for(a=0;a<16;a++)
43             {
44                 baseDS_1=dat>>15;
45                 dat<<=1;
46                 baseSHCP_1=1;
47                 baseSHCP_1=0;    
48             }
49             baseSTCP_1=1;
50             baseSTCP_1=0;
51     }
52 }
53 
54 void delay(unsigned int time)
55 {
56   unsigned int i,j;
57   for(i=0;i<time;i++)
58     for(j=0;j<121;j++);
59 }
60 
61 void main(void){
62     char i = 0;
63     while(1){
64         for(i=0;i<16;i++)
65         {
66             Hc595SendByte(1,LAB[i]);
67             Hc595SendByte(0,~inData[1][i]);    //发送段选数据
68             delay(1);           //延时
69         }
70     };
71 }

 

posted on 2018-12-13 18:25  踏雪留痕丶小布点  阅读(7502)  评论(0编辑  收藏  举报

导航