侧边栏壁纸
博主头像
塞塞哇 博主等级

开源创客

  • 累计撰写 38 篇文章
  • 累计创建 9 个标签
  • 累计收到 11 条评论

目 录CONTENT

文章目录

Noritake CU20029-TE200K Arduino驱动

塞塞蛙
2023-09-11 / 0 评论 / 0 点赞 / 438 阅读 / 0 字

VFD (Noritake CU20029-TE200K)Arduino ESP32驱动

前言

日本Noritake VFD荧光显示屏模块,这款模块具有:

20 x 2个字符的显示屏。

细点间距,每个字符15×16个点。

显示亚洲字体表:中文、韩语和日语。

CU20029-TE200K.jpg电气参数

供电为5V电压,最大5.25V。

短接TEST脚到GND可以开启测试模式。

采用RS232接口通讯,默认波特率38400。

bg1.jpg

硬件准备

通讯方式为RS232需要提供RS232转换芯片,或者购买RS232 TO TTL转换模块

连接方式:

  1. 5V连接到VCC

  2. GND连接到模块的GND引脚

  3. RS232串口通讯模块的TX引脚(发送引脚)连接到VFD模块的RX引脚

使用ESP32-C3开发板环境进行代码的编写。

首先在开始之请将RS232模块正确连接到ESP32中

这里我们使用Uart1初始化被连接的RS232模块

1. 初始化引脚

#define RS232_TX 19
#define RS232_RX 18

这里引脚是RS232模块连接到单片机的引脚

delay(500);
Serial1.begin(38400, SERIAL_8N1, RS232_RX, RS232_TX);

初始化Serial1作为串口发送工具

2. 工具类

新建文件 " te200k.h "

/*
 * @Description:
 * @Author: chenzedeng
 * @Date: 2023-08-20 18:46:07
 * @LastEditTime: 2023-08-20 21:51:19
 */
#ifndef __TE200K_H
#define __TE200K_H

#include <Arduino.h>

#define u8 uint8_t

#define TE_VFD_WRITE(b) Serial1.write(b)
#define TE_VFD_WRITE_S(s) Serial1.print(PSTR(s))

void te200k_init(void);

/**
 * The cursor moves to the specified X, Y position. 
*/
void te200k_cursor_set(u8 x, u8 y);

/**
 * Specifies cursor display ON/OFF. Blink time for block cursor depends on time
 * set in Blink screen command.
*/
void te200k_cursor_display(u8 enable);

/**
 * Display power ON/OFF.
*/
void te200k_display_power(u8 enable);

/**
 * Reverse character display setting ON/OFF
*/
void te200k_display_reverse(u8 enable);

/**
 * Set display brightness level.
 * @param level 1 (01h) – 4 (04h)
*/
void te200k_display_brightness(u8 level);

/**
 * Display is cleared and cursor moves to home position (left end of 1st line).
*/
void te200k_display_clear(void);

/**
 * Current line is cleared and cursor moves to left end of current line.
*/
void te200k_line_clear(void);

/**
 * Screen blink control.
 * @param level Definable area: n = 0 (00h) Screen blink cancel.
                Default: n = 0
                n = 1 (01h) – 255 (FFh) Screen blink display.
*/
void te200k_display_blink(u8 level);


void te200k_test(void);

#endif

新建文件 " te200k.cpp "

#include <te200k.h>

void asynchro_send(u8 buf) {
    // while (digitalRead(TE_VFD_DTR)) {
    // }
    TE_VFD_WRITE(buf);
}

void te200k_init(void) {
    pinMode(TE_VFD_DTR, INPUT);
    delay(1000);

    // Initialize display
    asynchro_send(0x1B);
    asynchro_send(0x40);

    // International font set
    // 1Bh 52h n
    asynchro_send(0x1B);
    asynchro_send(0x52);
    asynchro_send(0x08);

    // Character table type
    // 1Bh 74h n
    asynchro_send(0x1B);
    asynchro_send(0x74);
    asynchro_send(0x01);

    // Open Setting Simplified Chinese
    //- Open Support 1Fh 28h 67h 02h 1
    asynchro_send(0x1F);
    asynchro_send(0x28);
    asynchro_send(0x67);
    asynchro_send(0x02);
    asynchro_send(0x01);
    //- Set Type Simplified Chinese
    // 1Fh 28h 67h 03h n
    asynchro_send(0x1F);
    asynchro_send(0x28);
    asynchro_send(0x67);
    asynchro_send(0x03);
    asynchro_send(0x02);
    // 1Fh 28h 67h 0Fh n
    asynchro_send(0x1F);
    asynchro_send(0x28);
    asynchro_send(0x67);
    asynchro_send(0x0F);
    asynchro_send(0x02);

    te200k_cursor_set(1, 1);
    te200k_display_power(1);
    te200k_display_reverse(0);
    te200k_display_brightness(1);
    
    // te200k_display_blink(255);
}

void te200k_cursor_set(u8 x, u8 y) {
    asynchro_send(0x1F);
    asynchro_send(0x24);
    asynchro_send(x);
    asynchro_send(y);
}

void te200k_cursor_display(u8 enable) {
    asynchro_send(0x1F);
    asynchro_send(0x43);
    asynchro_send(enable);
}

void te200k_display_power(u8 enable) {
    // 1Fh 28h 61h 40h n
    asynchro_send(0x1F);
    asynchro_send(0x28);
    asynchro_send(0x61);
    asynchro_send(0x40);
    asynchro_send(enable);
}

void te200k_display_reverse(u8 enable) {
    // 1Fh 72h n
    asynchro_send(0x1F);
    asynchro_send(0x72);
    asynchro_send(enable);
}

void te200k_display_brightness(u8 level) {
    // 1Fh 58h n
    asynchro_send(0x1F);
    asynchro_send(0x58);
    asynchro_send(level);
}

void te200k_display_blink(u8 level) {
    // 1Fh 45h n
    asynchro_send(0x1F);
    asynchro_send(0x45);
    asynchro_send(level);
}

void te200k_display_clear(void) {
    asynchro_send(0x0C);
}

void te200k_line_clear(void) {
    asynchro_send(0x18);
}

API 解释

首先在main文件中引入vfd工具头文件

在setup方法中调用: te200k_init() 方法

  1. te200k_display_brightness(u8 level); 设置亮度 等级 1~4

  2. void te200k_display_clear(void); 清空屏幕显示

  3. void te200k_line_clear(void); 清空当前行的显示可配和te200k_cursor_set方法使用

  4. void te200k_cursor_set(u8 x, u8 y); 光标移动到指定x和y上 默认左上角是1,1 从1开始

  5. 发送文字显示:TE_VFD_WRITE_S(s) s为内容可以是String

  6. 中文显示:发送中文需要将UTF-8转GB2312编码然后发送GB2312编码

3. 中文发送示例

使用查表法,在线转换工具:https://www.107000.com/T-Hex/

#define GB2312_LEN 4
const gb2312_decoder fonts[GB2312_LEN] = {
    {0xCEC2, "温"},
    {0xB6C8, "度"},
    {0xCAAA, "湿"},
    {0xA1E6, "℃"},
};

void convert_gb2312(const char* str, u8* buf) {
    memset(buf, 0, sizeof(buf));
    u8 index = 0;
    for (size_t i = 0; i < strlen(str); i++) {
        if ((str[i] & 0xE0) == 0xE0) {
            char cn1 = str[i++];
            char cn2 = str[i++];
            char cn3 = str[i];
            for (size_t j = 0; j < GB2312_LEN; j++) {
                gb2312_decoder font = fonts[j];
                if (cn1 == font.cn[0] && cn2 == font.cn[1] &&
                    cn3 == font.cn[2]) {
                    buf[index++] =
                        (uint8_t)((font.decoder >> 8) & 0xFF);  // 获取高8位
                    buf[index++] = (uint8_t)(font.decoder & 0xFF);  // 获取低8位
                    break;
                }
            }
        } else if (str[i] && str[i] != '\0') {
            buf[index++] = str[i];
        }
    }
    buf[index] = '\0';
}

使用方法:

void gui_print_cn(u8 x, u8 y, const char* str) { //要显示的X坐标和Y坐标,str为显示的内容
    if (x > MAX_X) {
        x = MAX_X;
    }
    if (y > MAX_Y) {
        y = MAX_Y;
    }
    te200k_cursor_set(x, y);
    u8 len = strlen(str);
    u8 buf[len];
    convert_gb2312(str, buf);
    for (size_t i = 0; i < len; i++) {
        if (!buf[i] || buf[i] == '\0') {
            break;
        }
        TE_VFD_WRITE(buf[i]);
    }
}

项目效果

cu20029-te200k-wx.jpg驱动板项目说明

  1. RX8025T高精度实时时钟

  2. AHT21 温湿度传感器

  3. 无源蜂鸣器

  4. 波轮开关

  5. Type-C立式供电接口

  6. ESP32-C3 MINI1 模块

  7. 5V供电,或12V供电可选 (跳线帽设置)

此项目有出售,如需要请联系博主(关于->交流群)!

0

评论区