8x8 LED dot matrix based on 51 single chip microcomputer

Publisher:mlgb999Latest update time:2020-03-16 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I recently learned about LED dot matrix and used three methods to display letter groups, namely key control display, automatic change display, and scroll display.


The first

#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}, //Encode letters

                     {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}; //Scan array



void delay(u16 i)

{  

     while(i--);

}


void keydown() //key function

{   

 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 module definition

{

    u8 a;

SRCLK=0;

RCLK=0;

for(a=0;a<8;a++)

{

    SER=that>>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=barely[i];

  hc595sendbyte(duan[keyvalue][i]);

  delay(100);

  hc595sendbyte(0x00); //LED matrix shadow removal


}

}

}

Second type:

#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}, //letter segment setting

                     {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}; //Scan segment


void delay(u16 i)

{  

     while(i--);

}


void hc595sendbyte(u8 dat) //hc595 module settings

{

    u8 a;

    SRCLK=0;

    RCLK=0;

    for(a=0;a<8;a++)

    {

        SER=that>>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 matrix shadow elimination

          }


         }

         t=100; 


     }

     hc595sendbyte(0x00);


   }



The third


#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}; //Scan code segment


void delay(u16 i)

{  

     while(i--);

}


void hc595sendbyte(u8 dat)//hc595 module initialization

{

    u8 a;

SRCLK=0;

RCLK=0;

for(a=0;a<8;a++)

{

    SER=that>>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 matrix shadow removal

  }

  q=0;

 }

 t=30; 

}

}

}


Reference address:8x8 LED dot matrix based on 51 single chip microcomputer

Previous article:51 routines --- led dot matrix
Next article:Use the 51 single chip microcomputer's LED dot matrix to output Happy Birthday

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号