16×16 dot matrix design based on AT89c51

Publisher:平和梦想Latest update time:2020-12-07 Source: 51heiKeywords:AT89c51  16×16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Four 8×8 dot matrices are used to form a 16×16 dot matrix. Two decoders are used. Only three characters are set (the character converter can be used to change the character). The buttons control left shift, right shift, pause, and start.


The microcontroller source program is as follows:

/************************************************

16x16 dot matrix Chinese character scrolling display

****************************************************/

#include

#define uchar unsigned char

#define uint unsigned int

sbit LA=P1^0; //138 decoder address selection pin

sbit LB=P1^1;

sbit LC=P1^2;

sbit LD=P1^3;

sbit k1=P3^6; //Start or pause button

sbit k2=P3^7; //Change direction button

bit fx=0; //Scroll direction

uint index=0; //column scan index


uchar code hztab[]={

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //space

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

   

    0x08,0x04,0x10,0x04,0x20,0x24,0x40,0x24,0xfc,0x24,0xa2,0x24,0x22,0xfd,0x22,0x26, //Old

    0x42,0x24,0x42,0x2c,0x42,0x14,0x82,0x24,0x1e,0x44,0x00,0x04,0x00,0x04,0x00,0x00,

   

    0x00,0x00,0xe1,0x3f,0x02,0x00,0x0c,0x00,0xf0,0xff,0x00,0x00,0x00,0x40,0xf8,0x47, // Division

    0x00,0x44,0x00,0x44,0xff,0x7f,0x10,0x44,0x08,0x44,0xf0,0x47,0x00,0x40,0x00,0x00,

   

    0x02,0x08,0x44,0x08,0xa8,0x0f,0x10,0xf8,0x68,0x08,0x86,0x0f,0x00,0x00,0x00,0x01, // OK

    0x02,0x41,0x01,0x41,0xfe,0x47,0x00,0x49,0x00,0x51,0x00,0x61,0x00,0x01,0x00,0x00,

   

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //space

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};


//==================Function declaration====================

void T0_Init(); //Timer 0 initialization

void delayus(uint us); //delay function

void keyscan(); //Key scan function


//====================Main program=====================

void main()

{

    uchar i,j;

    T0_Init(); //Timer 0 initialization

    while(1)

    {

        keyscan(); //key scan

        for(i=0;i<16;i++) //16 columns of dot matrix

        {

            LA=i&0x01; //Use cascade 138 for column selection

            LB=i&0x02;

            LC=i&0x04;

            LD=i&0x08;

            j=index+i; //Locate the column to be displayed

            P0=hztab[j*2+1]; //Send dot matrix data

            P2=hztab[j*2]; //two bytes in total

            delayus(100); //delay

            P0=P2=0x00; //Eliminate

        }

        delayus(100); //delay

    }

}


//=================Timer 0 Initialization=================

void T0_Init()

{

    TMOD=0x01; //Timer 0, working mode 1

    TH0=(65536-10000)/256; //initial value of constant

    TL0=(65536-10000)%256; //10ms timing

    ET0=1; //Enable timer 0 interrupt

    EA=1; // Enable general interrupt

    TR0=0; //Do not start timer 0 yet

}


//===============Timer interrupt 0 service program===============

void timer0() interrupt 1

{

    static uchar tick=0; //tick timer

    TH0=(65536-10000)/256; //Reload the initial value

    TL0=(65536-10000)%256; //10ms timing

    tick++; // count

    if(tick==5) //5 times

    {

        tick=0; //clear to 0

        if(fx==0)index=(index+1)%64; //If the direction is left, the scan line is increased by 1

        else index=(index-1+64)%64; //Otherwise the scan line is reduced by 1

    }

}


//===================Delay function====================

void delayus(uint us)

{

    while(us--);

}


//=================Key scanning function==================

void keyscan()

{

    if(k1==0) //Check if k1 is pressed

    {

        delayus(100); //delay to eliminate jitter

        if(k1==0) //Confirm that k1 is pressed

        {

            TR0=~TR0; //Timer start, stop and reverse

            while(k1==0); //Wait for the button to be released

        }

    }

    if(k2==0) //Check if k2 is pressed

    {

        delayus(100); //delay to eliminate jitter

        if(k2==0) //Confirm that k2 is pressed

        {

            fx=~fx; //Direction reversal

            while(k2==0); //Wait for the button to be released

        }

    }

}


Keywords:AT89c51  16×16 Reference address:16×16 dot matrix design based on AT89c51

Previous article:51 single chip microcomputer + 74LS160 frequency meter, the highest frequency can be measured is 10M
Next article:Single chip temperature measurement and control system + accuracy of 0.1℃ + 4-digit common anode digital tube display

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号