兰博

[Hangshun Training Camp] LED dot matrix learning board based on HK32F103CBT6

 
Overview

【Introduction】

This project is a two-color LED dot matrix learning board based on HK32F103CBT6, which can complete the following functions:

1. Display text statically (the program has been completed )

2. Move the display to the left (the program is to be developed)

3. Dot matrix writing (program completed )

4. Grayscale display (program to be developed)

5. Dot matrix clock (program to be developed)

—————————————————————————————————————————————— ——————————

—————————————————————————————————————————————— ——————————

【hardware】

The overall structure of the hardware is shown in the figure:

The entire circuit structure is actually relatively simple. The main parts are the HK32 minimum system and LED dot matrix.

Let’s focus on the circuit of the LED dot matrix part:

The 16*32 lattice in this design is composed of 8 8*8 common anode lattice

LED dot matrix is ​​usually driven by dynamic row and column scanning, that is, it is displayed row by row in sequence. Due to the persistence of vision phenomenon of the human eye,

When the scanning speed is fast enough, the picture will appear to be still.

Line scanning circuits are usually implemented using decoders because only one line is selected at a time.

The number of rows of the dot matrix in this design is 16, so a 4-16 decoder needs to be used. However, in order to facilitate wiring, the 4-16 decoder is not used directly.

Instead, two 3-8 decoders are used in cascade, the specific model is 74HC1 3 8.

Since the effective output level of the 1 3 8 decoder is low level and the output capability is insufficient, PMOS needs to be used for inversion and current amplification:

In order to achieve global brightness adjustment, a PWM dimming circuit is also added:

The column driver of LED dot matrix usually uses the familiar 74HC595 serial-to-parallel chip, but this chip is not specially designed for LED dot matrix.

When the number of lights in each row is different, uneven brightness will occur, so here I switched to the MBI 5024 chip.

It can achieve 16 channels of programmable constant current output, with uniform brightness and good consistency. At the same time, it has its own reverse phase, which is very suitable for common anode lattice:

The rest of the circuits are common designs and will not be described in detail here.

—————————————————————————————————————————————— ——————————

—————————————————————————————————————————————— ——————————

【software】

1. Static display

As mentioned earlier, the driving of the LED dot matrix is ​​achieved through row and column scanning. The whole process is not complicated.

First, you need to create a two-dimensional array in the program as a display cache, corresponding to the rows and columns of the dot matrix.

When a certain row is scanned, the data of that row is sent out and displayed for a short period of time.

As long as the scanning speed is fast enough, the picture seen by the human eye is still.

The specific procedures are as follows:

void Display()
{    
    char i,j;
    EN = 1;            //
关显示
    for(i=0;i<16;i++)  //
行扫描循环  
    {    
        Scan(i);   //
行扫描
        for(j=0;j<2;j++)  //
列扫描循环,每次发送4字节数据
        {        
            SendByte(Red_Buff[i][j*2] ,Green_Buff[i][j*2]);
            SendByte(Red_Buff[i][j*2+1] ,Green_Buff[i][j*2+1]);
        }
        LT = 1;  //
发送时钟让数据移出
        LT = 0;
        
        EN = 0;  //
显示一小段时间
        delay_us(50);
        EN = 1;
    }    
}

The display effect is as follows:

——————————————————————————————————————————————

2. Dot matrix writing

The LED dot matrix writing display was actually a topic in an electric competition many years ago, and its implementation principle is not complicated.

When we put the Pen (this word is illegal in Chinese) on the dot matrix screen, we only need to detect the location of the Pen and then light up the LED at the corresponding location .

So, how can we detect the location of the Pen?

First, a special Pen is needed: when it detects a certain intensity of light, it outputs a signal.

The optical Pen circuit is shown in the figure below:

The photosensitive element uses 3DU5C photosensitive transistor, which has faster response speed. When there is no light, the non-inverting voltage of the comparator is higher than the inverting voltage, and the output is high level.

When the phototransistor detects that the LED is lit and turns on, the E pole changes from low level to high level, the comparator output polarity is reversed, and a signal is output to the microcontroller.

Detecting the location can be achieved by scanning:

First, light all the LEDs in the row row by row from top to bottom. If the light Pen outputs a signal when lighting a certain row, it means that the light Pen is in this row.

In this way, we know the Y -axis coordinate of the light Pen. At this time, we can light up the LEDs in this row one by one from left to right .

When the light Pen is detected, the X- axis coordinate is determined.

Scanning instructions GIF :

After obtaining the position of the light Pen in this way, then lighting the corresponding LED can realize LED dot matrix writing.

It should be noted that when scanning to obtain the position of the light Pen, many points will light up. If the scanning time is the same as the normal display time,

It is definitely impossible to distinguish which points are lit, so the ratio of scanning time and display time needs to be controlled in the program.

When the scanning time is much less than the display time, the brightness during scanning is not as good as during normal display, so that scanning and normal display can be distinguished.

The procedure for obtaining the coordinates of the light Pen is as follows:

u16 GetPos()
{
    u16 i=0,j=0;
    u16 pos=0x0000;
    
    LT = 1;
    SendByte(0xff, 0x00);  //一行红色全亮
    SendByte(0xff, 0x00);
    SendByte(0xff, 0x00);
    SendByte(0xff, 0x00);
    LT = 0;
    
    EN=0;     //行扫描之前先开显示
    while(i<16)
    {
        Scan(i);//扫描某一行
        delay_us(20);  //延时一小段时间
        if(PEN == 1) {PEN = 0; EN = 1; break ;}//扫描到了光Pen,关显示,退出行扫描
        i++;
    }
    if(i==16) {PEN = 0; EN=1; return 0xffff;}//16行都没有扫描到光Pen,关显示退出扫描
    
    EN=0;//列扫描之前先开显示
    while(j<32)
    {
        Scan_Col(j);
        delay_us(20);        //延时一段时间,不然检测不到
        if(PEN == 1)
        {
            delay_us(30);
            if(PEN == 1) {PEN = 0; EN = 1; break ;}//扫描到了光Pen,关显示,退出列扫描
        }
        j++;
    }
    if(j==32) {PEN = 0; EN=1; return 0xffff;}//32列都没有扫描到光Pen,关显示退出扫描
    EN = 1;//正常扫描结束之后,关显示
    pos = (i<<8) | j;//计算坐标
        
    return pos;
}

The actual writing effect is as follows:

The picture above demonstrates the light mode. If you accidentally write it wrong, you need to use the light mode. The principle is similar.

——————————————————————————————————————————————

3. To be continued.

Due to the limited time of this training camp, only two DEMO programs have been completed. The grayscale display and clock will be completed and updated later.

—————————————————————————————————————————————— ——————————

—————————————————————————————————————————————— ——————————

[actual photos]

—————————————————————————————————————————————— ——————————

—————————————————————————————————————————————— ——————————

【Source code】

See attachment for code

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-22 23:45:57

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

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号