16X16点阵驱动采用常见的74HC595+74HC138直接驱动,省去了MOS管器件。资料包里有程序、Proteus仿真图和点阵取模工具。
单片机源程序如下:
- /*
- GND:
- +5V:
- OE#:74HC138 Pin5 G2B,为H输出H
- G: 绿色数据,暂缺
- CLK: 74HC595 Pin11 SCK
- STCK:74HC595 Pin12 SCK
- LA LB LC LD:74138 ABC G2A(Pin4)
- R:74HC595 Pin14 SER 红色数据*/
- #include <reg52.h>
- #include <intrins.h>
- sbit LD=P0^0; //8
- sbit LC=P0^1; //4
- sbit LB=P0^2; //2
- sbit LA=P0^3; //1 LA必须为脉冲信号,内部有过流保护电路7404
- //sbit G=P0^6;
- sbit OE=P0^7;
- sbit RCK=P0^4; //12 ST_CP
- sbit CLK=P0^5; //11 SH_CP
- sbit DAT=P3^7; //14 DS
- unsigned char idata disp_ram[32]={0};
- unsigned char code Tab[]={//先左后右,再上至下 0亮1灭
- 0xE7,0xFC,0xEF,0xFC,0xC3,0xF1,0xC0,0x63,0xDC,0x7B,0x9F,0xF3,0xBF,0xF3,0x81,0xF7,
- 0xFC,0xE7,0xFC,0xE7,0xFE,0xE7,0xFE,0xEF,0xFE,0xCF,0x7C,0xCF,0x21,0xDF,0x83,0xDF,/*"51",0*/
-
- 0xEF,0xEF,0xF7,0xDF,0xFB,0xBF,0xC0,0x07,0xDE,0xF7,0xDE,0xF7,0xC0,0x07,0xDE,0xF7,
- 0xDE,0xF7,0xC0,0x07,0xFE,0xFF,0xFE,0xFF,0x00,0x01,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,/*"单",1*/
-
- 0xFF,0xFF,0xFF,0xDF,0xF7,0xDF,0xF7,0xDF,0xF7,0xDF,0xF7,0xDF,0xF0,0x01,0xF7,0xFF,
- 0xF7,0xFF,0xF7,0xFF,0xF0,0x0F,0xF7,0xEF,0xF7,0xEF,0xF7,0xEF,0xEF,0xEF,0xEF,0xEF,/*"片",2*/
- 0xFF,0xFF,0xF7,0xFF,0xF7,0x07,0xF7,0x77,0xF7,0x77,0x81,0x77,0xF7,0x77,0xE7,0x77,
- 0xE3,0x77,0xD5,0x77,0xD5,0x77,0xB7,0x77,0xF7,0x76,0xF7,0x76,0xF6,0xF6,0xF6,0xF8,/*"机",3*/
-
- 0xFC,0x3F,0xF8,0x1F,0xF8,0x1F,0xF8,0x1F,0xF8,0x1F,0x9C,0x39,0xC7,0xE3,0xE3,0xC7,
- 0xF1,0x8F,0xF1,0x8F,0xF1,0x8F,0xF1,0x8F,0xE1,0x87,0xC3,0xC3,0x87,0xE1,0x1F,0xF8,/*"logo",4*/
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,/*显示空白*/
- };
- /*********延时函数*********/
- void Delay(unsigned int t) //t*1ms
- {
- unsigned int i,j; //0-65535
- for(i=0;i<t;i++)
- for(j=0;j<120;j++);
- }
- void Send_16bit(unsigned char dat_L,unsigned char dat_R,unsigned char hang)
- {
- unsigned char i;
- OE=1; //关闭74HC138输出
- RCK=0;
- for(i=0;i<8;i++)
- {
- CLK=0;
- if(dat_L&0x80)
- DAT=1;
- else
- DAT=0;
- dat_L=dat_L<<1;
- CLK=1;
- }
- for(i=0;i<8;i++)
- {
- CLK=0;
- if(dat_R&0x80)
- DAT=1;
- else
- DAT=0;
- dat_R=dat_R<<1;
- CLK=1;
- }
- switch(hang)
- {
- case 0:LA=0;LB=0;LC=0;LD=0;break;
- case 1:LA=1;LB=0;LC=0;LD=0;break;
- case 2:LA=0;LB=1;LC=0;LD=0;break;
- case 3:LA=1;LB=1;LC=0;LD=0;break;
- case 4:LA=0;LB=0;LC=1;LD=0;break;
- case 5:LA=1;LB=0;LC=1;LD=0;break;
- case 6:LA=0;LB=1;LC=1;LD=0;break;
- case 7:LA=1;LB=1;LC=1;LD=0;break;
- case 8:LA=0;LB=0;LC=0;LD=1;break;
- case 9:LA=1;LB=0;LC=0;LD=1;break;
- case 10:LA=0;LB=1;LC=0;LD=1;break;
- case 11:LA=1;LB=1;LC=0;LD=1;break;
- case 12:LA=0;LB=0;LC=1;LD=1;break;
- case 13:LA=1;LB=0;LC=1;LD=1;break;
- case 14:LA=0;LB=1;LC=1;LD=1;break;
- case 15:LA=1;LB=1;LC=1;LD=1;break;
- }
- RCK=1;
- OE=0;Delay(1);OE=1; //调节延时控制LED亮度
- }
- void main()
- {
- unsigned char zi; //字符控制
- unsigned char h; //行数变量
- unsigned char i;
- while(1)
- { //滚动显示
- for(zi=0;zi<(16*5);zi++) //
- {
- for(i=0;i<15;i++)
- for(h=0;h<16;h++)
- {Send_16bit(~Tab[h*2+2*zi],~Tab[h*2+1+2*zi],h);}//~取反
- }
- //直接切换
- /*for(zi=0;zi<5;zi++)
- {
- for(i=0;i<100;i++)
- for(h=0;h<16;h++)
- {Send_16bit(~Tab[h*2+32*zi],~Tab[h*2+1+32*zi],h);}
- }*/
- }
- }
复制代码
所有资料51hei提供下载:
16X16点阵Proteus仿真 取模工具.rar
(824.16 KB, 下载次数: 135)
|