led点阵8×8滚动显示原理_led点阵屏编程

LEDs

378人已加入

描述

  led点阵8×8滚动显示原理

  8X8点阵为例,它共由64个发光二极管组成,且每个发光二极管是放置在行线和列线的交叉点上,当对应的某一行置1电平,某一列置0电平,则相应的二极管就亮;如要将第一个点点亮,则9脚接高电平13脚接低电平,则第一个点就亮了;

  如果要将第一行点亮,则第9脚要接高电平,而(13、3、4、10、6、11、15、16)这些引脚接低电平,那么第一行就会点亮;如要将第一列点亮,则第13脚接低电平,而(9、14、8、12、1、7、2、5)接高电平,那么第一列就会点亮。

  在8X8点阵LED上显示柱形,让其先从左到右平滑移动三次,其次从右到左平滑移动三次,再次从上到下平滑移动三次,最后从下到上平滑移动三次,如此循环下去。

  8X8点阵LED工作原理说明 :8X8点阵共需要64个发光二极管组成,且每个发光二极管是放置在行线和列线的交叉点上,当对应的某一列置1电平,某一行置0电平,则相应的二极管就亮;因此要实现一根柱形的亮法,如图49所示,对应的一列为一根竖柱,或者对应的一行为一根横柱,因此实现柱的亮的方法如下所述:

  一根竖柱:对应的列置1,而行则采用扫描的方法来实现。

  一根横柱:对应的行置0,而列则采用扫描的方法来实现。

  led点阵屏编程

  点阵的显示原理是行扫描列发送字码,或者是列扫描行发送字码。当点阵屏大于16×16时,普通的32个I/O口的 单片机 是无法直接连接了,必须通过串行输入/输出寄存器或者锁存器等I/O口扩展,例如锁存器:74HC373、74HC273等;串行输入并行输出寄存器:74HC595、74HC164等;I/O口扩展芯片:8255、8155等。

  74HC273是8位数据/地址锁存器,D0~D7为数据出入端;Q0~Q7为数据输出端;WR为主清除端,低电平触发,将锁存数据清零;CLK是触发端,上升沿触发,即当CLK从低到高电平时,D0~D7的数据通过芯片输出到Q0~Q7,为0时将数据锁存。

  74HC273的测试程序如下:

  #include

  sbit CLK=P3^0 ;

  sbit MR=P3^1;

  #define uchar unsigned char

  #define uint unsigned int

  //数码管字型表,对应0,1,2,3,4,5,6,7,8,9//

  uchar Table[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

  void Delay(uint i )

  {

  uchar j;

  for(;i!=0;i--)

  {for(j=200;j!=0;j--) ;}

  }

  void main(void)

  {

  uchar N;

  MR=1;

  while(1)

  {

  for(N=0;N《10;N++)

  {

  CLK=0;

  Delay(300); //延时为了方便看到管脚电平变化

  P2=Table[N];

  CLK=1;

  Delay(300);

  }

  MR=!MR;

  }

  }

  测试效果如下

  利用74HC237连接的点阵如下图所示:

  显示扫描方式也可以分为行扫描和列扫描,行扫描时,U1先输出行码依次扫描第1至第8行,同时U3输出第1行的左半部分列码,U4再输出第1行右半部分列码;扫描完1至8行后U2扫描8至16行,同时U3、U4输出对应的列码,这样就可以显示了。这仅仅是为了说明74HC273的连接图,不是最好的点阵连接方式,大家可以自己优化电路图。

  

发光二极管

二、74HC164与8255连接的点阵示例

  图中8255的PA、PB输出端应加上拉电阻(300Ω~1KΩ)。ULN2803为增加驱动列能力。

  5288的地址:PA口为0000H、PB口为0100H、PK(控制)口为0300H。使用逐列扫描方式。

  

发光二极管

       以显示四个静态的“欠一个吻”为例,参考程序如下:

  #include

  #includeCC.h》

  #define PA8255 XBYTE[0X0000]

  #define PB8255 XBYTE[0X0100]

  #define PK8255 XBYTE[0X0300]

  #define uhar unsigned char

  uchar code Hzdot[]={

  0x80,0x40,0x40,0x40,0x20,0x20,0x18,0x20,0x0F,0x10,0x0A,0x0C,0x08,0x03,0xE8,0x00,

  0x08,0x03,0x08,0x0C,0x48,0x10,0x28,0x30,0x18,0x60,0x08,0x20,0x00,0x20,0x00,0x00,/*“欠”,0*/

  0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,

  0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xC0,0x00,0x80,0x00,0x00,0x00,/*“一”,1*/

  0x00,0x00,0x80,0x00,0x80,0x00,0x40,0x00,0x20,0x00,0x10,0x00,0x0C,0x00,0xE3,0x7F,

  0x04,0x00,0x08,0x00,0x10,0x00,0x20,0x00,0x60,0x00,0xC0,0x00,0x40,0x00,0x00,0x00,/*“个”,2*/

  0x00,0x00,0xFC,0x07,0x04,0x02,0x04,0x02,0xFC,0x03,0x40,0x48,0x30,0x44,0x0F,0x23,

  0xCA,0x10,0x38,0x0C,0x08,0x03,0xF8,0x40,0x08,0x80,0x08,0x60,0xF8,0x1F,0x00,0x00/*“吻”,3*/

  };

  uchar a,i,t,x[8]={0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff};

  char b;

  void main(void)

  {

  PK8255=0X80;

  while(1)

  {

  for(a=0;a《64;a++)

  {

  PA8255=0x00;

  PB8255=0x00;

  for(b=7;b》=0;b--)

  {

  SBUF=~x[b];

  while(!TI) ;TI=0;

  }

  PA8255=hzdot[2*a];

  PB8255=hzdot[2*a+1];

  for(i=0;i《8;i++)

  {

  if((x[7]&0x01)==0) goto LP;

  if((~x[i]!=0)&&((x[i]&0x01)!=0))

  x[i]=x[i]《《7|x[i]》》1;

  else if((~x[i]!=0)&&((x[i]&0x01)==0))

  {

  x[i]=0xff;

  x[i+1]=0x7f;

  break;

  }

  }

  }

  LP:x[0]=0x7f;x[7]=0xff;

  }

  }

  三、74HC595连接的点阵示例

  很多点阵都是使用74HC595连接的,74HC595是8位串行输入/输出或者并行输出移位寄存器,具有高阻关断三态输出功能。

  74HC595的功能表如下:

  

发光二极管

为了形象的演示74HC595的功能,编写如下测试程序:

  #include

  #define uint unsigned int

  #define uchar unsigned char

  sbit DS=P3^4; //74HC595的数据串行输入端口

  sbit ST=P3^7; //74HC595并行输出使能

  sbit SH=P3^6; //74HC595移位寄存器移位使能

  //测试串行传输数据:

  uchar code Test[]={0xFF,0x00,0xAA,0xCC,0xEE,};

  //******延时子程序******//

  void delay(uint a)

  {

  uint i,j;

  for(i=0;i for(j=0;j《4;j++);

  }

  void SendByte(uchar date)

  {

  uchar i;

  for(i=0;i《8;i++)

  {

  SH=0;

  ST=0;

  if(date&0x80) //将date最高位移到74HC595的移位寄存器

  DS=1;

  else

  DS=0;

  SH=1; //SH上升沿时移位

  ST=1; //ST上升沿时输出数据

  date=date《《1; //左移一位,将送出第二位数据

  delay(5000);

  }

  }

  //****主函数****//

  void main()

  {

  uchar i;

  while(1)

  {

  for(i=0;i《5;i++)

  SendByte(Test[i]);

  }

  }

  测试是依次输出0xFF,0x00,0xAA,0xCC,0xEE几个数据,在点阵显示程序中,是将数据全部送到74HC595的移位寄存器,再同时显示出来,并不是像下图所示一个一个流动显示,这个仅仅是测试数据的传输路径。

  

发光二极管

ORG 0000H

  LJMP STAR

  ORG 0BH

  LJMP INTT0

  STAR: MOV 20H,#00H

  MOV A,#0FFH

  MOV R7,#0

  MOV P1,A

  MOV P2,A

  MOV P3,A

  MOV P0,A

  CLR P1.6

  MOV TMOD,#01H

  MOV TH0,#0FEH

  MOV TL0,#18H

  MOV SCON,#0

  MOV IE,#82H

  MOV SP,#70H

  MOV R0,#0

  MAIN: LCALL DIS1

  MOV DPTR ,#TAB

  LCALL MOV DISP

  LJMP MAIN

  MOV DISP:MOV B,#00H

  DISLOOP: MOV R3,#07H

  DIS MOV : JNB 02H,AAA

  DEC DPH

  CLR 02

  AAA: MOV R2,#0

  MOV R1,B

  SETB TR0

  WAIT MOV :JBC 00H,DISMOV1

  AJMP WAIT MOV

  DIS MOV 1:DJNZ R3,DISMOV

  JNB 02H,BBB

  DEC DPH

  CLR 02

  BBB: INC B

  MOV A,B

  CJNE A,#0,CC1

  INC DPH

  INC R7

  CC0: INC B

  MOV A,B

  CJNE A,#0,CCC

  INC DPH

  INC R7

  CC1: INC B

  MOV A,B

  CJNE A,#0,CCC

  INC DPH

  INC R7

  CCC: MOV A,R1

  MOV OUT:CJNE R7,#3,DISLOOP

  MOV A,B

  CJNE A,#24,DISLOOP

  MOV R7,#0

  RET

  DIS1: MOV R3,#0AH

  CLR P1.3

  CLR P1.4

  CLR P1.5

  DIS11: MOV R2,#0

  MOV DPTR,#TAB

  MOV R1,#0H

  SETB TR0

  WAIT11:JBC 01H,DIS11

  AJMP WAIT11

  DIS111:DJNZ R3,DIS11

  RET

  INTT0: INC R0

  PUSH ACC

  MOV TH0,#0FEH

  MOV TL0,#18H

  JBC 00H,GOEND

  MOV A,R1

  MOV C A,@A+DPTR

  MOV SBUF,A

  WAIT: JBC TI,GO

  AJMP WAIT

  GO: INC R1

  CJNE R1,#0,AA

  INC DPH

  SETB 02H

  AA: MOV A,R1

  MOV C A,@A+DPTR

  MOV SBUF,A

  WAIT1: JBC TI,GO1

  AJMP WAIT1

  GO1: INC R1

  CJNE R1,#0,BB

  INC DPH

  SETB 02H

  BB: MOV A,R1

  MOV C A,@A+DPTR

  MOV SBUF,A

  WAIT2: JBC TI,GO2

  AJMP WAIT2

  GO2: CLR P1.3

  CLR P1.4

  CLR P1.5

  NOP

  SETB P1.6

  NOP

  NOP

  NOP

  NOP

  NOP

  NOP

  NOP

  NOP

  NOP

  NOP

  NOP

  CLR P1.6

  MOV A,R2

  ANL A,#7H

  ANL P1,#0F8H

  ORL P1,A

  P122: INC R2

  CJNE R2,#8,PAN1

  LJMP PAN1A

  PAN1: JC PAN1A

  CJNE R2,#10H,PAN2

  LJMP PAN1B

  PAN2: JC PAN1B

  CJNE R2,#018H,PAN3

  LJMP PAN1C

  PAN3: JC PAN1C

  AJMP PANT

  PAN1A: SETB P1.3

  AJMP PANT

  PAN1B: SETB P1.4

  AJMP PANT

  PAN1C: SETB P1.5

  PANT: INC R1

  CJNE R1,#0,CC

  INC DPH

  SETB 02H

  CC: MOV A,R2

  GO3: CJNE R2,#24,GO4

  SETB 00H

  GO4: POP ACC

  RETI

  GOEND: CLR TR0

  SETB 01H

  POP ACC

  RETI

  ORG 0A00H

  TAB:

  ;-- 逐行 顺向 --

  DB 000H,000H,000H,003H,0C0H,000H,004H,030H,000H,004H,010H,000H,008H,03FH,0FCH,008H;

  DB 000H,006H,010H,000H,002H,020H,000H,002H,020H,000H,002H,040H,083H,004H,041H,083H;

  DB 004H,041H,083H,008H,042H,083H,008H,03FH,001H,0F0H,001H,001H,080H,002H,000H,0C0H;

  DB 004H,000H,060H,008H,00CH,018H,030H,008H,004H,040H,01CH,002H,040H,026H,002H,040H;

  DB 043H,002H,021H,080H,0C4H,03EH,000H,03CH;“欠”,0

  DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H;

  DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,07FH,0FFH,0FCH,0C0H,000H;

  DB 006H,080H,000H,002H,080H,000H,002H,080H,000H,002H,0C0H,000H,006H,07FH,0FFH,0FCH;

  DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H;

  DB 000H,000H,000H,000H,000H,000H,000H,000H;“一”,1

  DB 000H,000H,000H,000H,07CH,000H,000H,083H,000H,001H,000H,080H,006H,000H,060H,008H;

  DB 000H,030H,030H,000H,00CH,040H,07EH,002H,080H,042H,001H,080H,082H,001H,081H,083H;

  DB 081H,046H,082H,0E2H,078H,082H,01CH,000H,082H,000H,000H,082H,000H,000H,082H,000H;

  DB 000H,082H,000H,000H,082H,000H,000H,082H,000H,000H,082H,000H,000H,082H,000H,000H;

  DB 082H,000H,000H,082H,000H,000H,07CH,000H;“个”,2

  DB 000H,000H,000H,000H,01CH,000H,000H,022H,000H,07FH,0C1H,000H,0C0H,081H,0F8H,080H;

  DB 080H,004H,080H,080H,002H,081H,000H,002H,08BH,000H,002H,08AH,002H,002H,08AH,022H;

  DB 042H,089H,044H,042H,088H,0C4H,042H,088H,088H,042H,089H,008H,082H,082H,010H,082H;

  DB 084H,020H,082H,084H,040H,082H,0C4H,083H,082H,07FH,084H,002H,001H,004H,004H,000H;

  DB 084H,004H,000H,04CH,00CH,000H,033H,0F8H;“吻”,3
责任编辑:YYX

  ……

  END

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分