(备份)常用ASCII 8*8 点阵 以及查询显示字符的点阵

2024-08-31 21:44

本文主要是介绍(备份)常用ASCII 8*8 点阵 以及查询显示字符的点阵,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

图片b7fb10e5cc8840a9ab304b8bbddd0b49.jpg

 

#include "driver/spi_master.h"
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "string.h"
#include "driver/i2c.h"
#include "esp_rom_sys.h"
#include "sdkconfig.h"
#include <stdio.h>
#include "esp_system.h"
#include "esp_log.h"//------------------------------------------
#define I2C_MASTER_SCL_IO           14
#define I2C_MASTER_SDA_IO           26
#define I2C_MASTER_NUM              I2C_NUM_0
#define I2C_MASTER_FREQ_HZ          100000
#define I2C_MASTER_TX_BUF_DISABLE   0
#define I2C_MASTER_RX_BUF_DISABLE   0
#define DS3231_ADDRESS              0x68  // 68
//--------------------------------------
#define PIN_NUM_MOSI 2
#define PIN_NUM_CLK  15
#define PIN_NUM_CS   5
#define PIN_NUM_DC   19
#define PIN_NUM_RST  18//--------------------------------------------------------------------------void i2c_master_init()
{i2c_config_t conf = {.mode = I2C_MODE_MASTER,.sda_io_num = I2C_MASTER_SDA_IO,.sda_pullup_en = GPIO_PULLUP_ENABLE,.scl_io_num = I2C_MASTER_SCL_IO,.scl_pullup_en = GPIO_PULLUP_ENABLE,.master.clk_speed = I2C_MASTER_FREQ_HZ,};ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf));ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_NUM, conf.mode, 0, 0, 0));
}uint8_t dec_to_bcd(uint8_t val)
{return ((val / 10 * 16) + (val % 10));
}uint8_t bcd_to_dec(uint8_t val)
{return ((val / 16 * 10) + (val % 16));
}esp_err_t ds3231_set_time(uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t date, uint8_t month, uint8_t year)
{uint8_t time_data[7] = {dec_to_bcd(sec), dec_to_bcd(min), dec_to_bcd(hour), dec_to_bcd(day), dec_to_bcd(date), dec_to_bcd(month), dec_to_bcd(year)};i2c_cmd_handle_t cmd = i2c_cmd_link_create();i2c_master_start(cmd);i2c_master_write_byte(cmd, (DS3231_ADDRESS << 1) | I2C_MASTER_WRITE, true);i2c_master_write_byte(cmd, 0x00, true);i2c_master_write(cmd, time_data, sizeof(time_data), true);i2c_master_stop(cmd);esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_PERIOD_MS);i2c_cmd_link_delete(cmd);return ret;
}//---------------------------------------------------------------------------------
//-----------------------------------------------------------
spi_device_handle_t spi;void spi_init() {spi_bus_config_t buscfg = {.mosi_io_num = PIN_NUM_MOSI,.miso_io_num = -1,.sclk_io_num = PIN_NUM_CLK,.quadwp_io_num = -1,.quadhd_io_num = -1,.max_transfer_sz = 4096,};spi_bus_initialize(HSPI_HOST, &buscfg, 1);spi_device_interface_config_t devcfg = {.clock_speed_hz = 25 * 1000 * 1000,   // 10 MHz.mode = 0,                            // SPI mode 0.spics_io_num = PIN_NUM_CS,           // CS pin.queue_size = 7,};spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
}void st7735_send_cmd(uint8_t cmd) {gpio_set_level(PIN_NUM_DC, 0); // Command modespi_transaction_t t;memset(&t, 0, sizeof(t));t.length = 8;t.tx_buffer = &cmd;spi_device_transmit(spi, &t);
}void st7735_send_data(uint8_t data) {gpio_set_level(PIN_NUM_DC, 1); // Data modespi_transaction_t t;memset(&t, 0, sizeof(t));t.length = 8;t.tx_buffer = &data;spi_device_transmit(spi, &t);
}void st7735_reset() {gpio_set_level(PIN_NUM_RST, 0);vTaskDelay(1 / portTICK_PERIOD_MS);gpio_set_level(PIN_NUM_RST, 1);vTaskDelay(200 / portTICK_PERIOD_MS);
}void st7735_init() {// Reset the displayst7735_reset();// Initialization commands for ST7735Sst7735_send_cmd(0x01); // Software resetvTaskDelay(150 / portTICK_PERIOD_MS);st7735_send_cmd(0x11); // Sleep outvTaskDelay(120 / portTICK_PERIOD_MS);st7735_send_cmd(0xB1);st7735_send_data(0x01);st7735_send_data(0x2c);st7735_send_data(0x2D);st7735_send_cmd(0xB2);st7735_send_data(0x01);st7735_send_data(0x2c);st7735_send_data(0x2D);st7735_send_cmd(0xB3);st7735_send_data(0x01);st7735_send_data(0x2c);st7735_send_data(0x2D);st7735_send_data(0x01);st7735_send_data(0x2c);st7735_send_data(0x2D);st7735_send_cmd(0xB4);st7735_send_data(0x00);st7735_send_cmd(0xc0);st7735_send_data(0xa2);st7735_send_data(0x02);st7735_send_data(0x84);st7735_send_cmd(0xc1);st7735_send_data(0xc5);st7735_send_cmd(0xc2);st7735_send_data(0x0d);st7735_send_cmd(0xc3);st7735_send_data(0x8d);st7735_send_data(0x2a);st7735_send_cmd(0xc4);st7735_send_data(0x8d);st7735_send_data(0xee);st7735_send_cmd(0xc5);st7735_send_data(0x0e);st7735_send_cmd(0x36);st7735_send_data(0b01000000);   //40st7735_send_cmd(0xe0);st7735_send_data(0x0f);st7735_send_data(0x1a);st7735_send_data(0x0f);st7735_send_data(0x18);st7735_send_data(0x2f);st7735_send_data(0x28);st7735_send_data(0x20);st7735_send_data(0x22);st7735_send_data(0x1f);st7735_send_data(0x1b);st7735_send_data(0x23);st7735_send_data(0x37);st7735_send_data(0x00);st7735_send_data(0x07);st7735_send_data(0x02);st7735_send_data(0x10);st7735_send_cmd(0xe1);st7735_send_data(0x0f);st7735_send_data(0x1b);st7735_send_data(0x0f);st7735_send_data(0x17);st7735_send_data(0x33);st7735_send_data(0x2c);st7735_send_data(0x29);st7735_send_data(0x2e);st7735_send_data(0x30);st7735_send_data(0x30);st7735_send_data(0x39);st7735_send_data(0x3f);st7735_send_data(0x00);st7735_send_data(0x07);st7735_send_data(0x03);st7735_send_data(0x10);st7735_send_cmd(0x2a);st7735_send_data(0x00);st7735_send_data(0x00);st7735_send_data(0x00);st7735_send_data(127);st7735_send_cmd(0x2b);st7735_send_data(0x00);st7735_send_data(0x00);st7735_send_data(0x00);st7735_send_data(160);st7735_send_cmd(0xf0);st7735_send_data(0x01);st7735_send_cmd(0xf6);st7735_send_data(0x00);st7735_send_cmd(0x3a);st7735_send_data(0x05);st7735_send_cmd(0x29); // Display onvTaskDelay(100 / portTICK_PERIOD_MS);
}void qp(uint8_t xs, uint8_t xe,uint8_t ys,uint8_t ye) {// Set 列st7735_send_cmd(0x2A);st7735_send_data(0x00);st7735_send_data(xs);st7735_send_data(0x00);st7735_send_data(xe);// Set 行st7735_send_cmd(0x2B);st7735_send_data(0x00);st7735_send_data(ys);st7735_send_data(0x00);st7735_send_data(ye);// Write memoryst7735_send_cmd(0x2C);       
}void cls(){qp(0,127,0,159);                              // lcd  全屏刷成白屏for (uint16_t a = 0; a < 159; a++) {for(uint8_t b=0;b<127;b++){st7735_send_data(0xff);st7735_send_data(0xff);}}  }	uint8_t font[][8] ={ {0x1C, 0x22, 0x26, 0x2A, 0x32, 0x22, 0x1C, 0x00},   // '0'{0x04, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x0E, 0x00}, // 数字 '1'{0x0E, 0x11,  0x01,  0x06,   0x08, 0x10,  0x1F,  0x00 },  // 2 {0x1C, 0x22, 0x02, 0x1C, 0x02, 0x22, 0x1C, 0x00}, // '3'{0x08, 0x18, 0x28, 0x48, 0x7E, 0x08, 0x08, 0x00},  // '4'{0x3E, 0x20, 0x3E, 0x02, 0x02, 0x22, 0x1C, 0x00},  // '5'{0x1C, 0x22, 0x20, 0x3C, 0x22, 0x22, 0x1C, 0x00},  // '6'{0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00}, // '7'{0x1C, 0x22, 0x22, 0x1C, 0x22, 0x22, 0x1C, 0x00},  // '8'{0x1C, 0x22, 0x22, 0x1E, 0x02, 0x22, 0x1C, 0x00},  // '9'{0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00},  // :{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},         //空格//--------------{0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x00},    //中间短横线-{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},  //下横线_{ 0x00,0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30}, //逗号{    0x3C, 0x42, 0x02, 0x0C, 0x10, 0x10, 0x00,0x10},//问号{  0x10, 0x10, 0x10, 0x10, 0x10,0x00,0x10, 0x00},//感叹号{  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,0x18},//句号{   0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30},// 分号//-------------------{0x00,0x00, 0x3C, 0x02,  0x3E, 0x42, 0x3E, 0x00 },  //a{ 0x40, 0x40, 0x7C,  0x42,  0x42, 0x42,  0x7C,  0x00},//         {0x00, 0x00, 0x3E,  0x40,   0x40,   0x40,  0x3E,   0x00},//         {0x02, 0x02, 0x3E, 0x42, 0x42, 0x42, 0x3E, 0x00},//         {0x00, 0x00, 0x3C, 0x42, 0x7E, 0x40, 0x3C,  0x00},//         {0x1C, 0x22, 0x20, 0x7C, 0x20, 0x20, 0x20,  0x00},//         {0x00, 0x00, 0x3E, 0x42, 0x3E, 0x02, 0x3C, 0x00},//         {0x40, 0x40,  0x7C,  0x42, 0x42, 0x42, 0x42, 0x00},//         {0x00, 0x10,  0x00, 0x30, 0x10, 0x10,0x10, 0x00},//         {0x00, 0x08, 0x00, 0x08, 0x08, 0x48, 0x30, 0x00},//         {0x40, 0x44, 0x48,0x70,  0x48, 0x44,  0x42,  0x00},         {0x30, 0x10, 0x10, 0x10,   0x10, 0x10, 0x10, 0x00},//         {0x00, 0x00, 0x66, 0x5A,  0x42, 0x42, 0x42, 0x00},//         { 0x00,0x00, 0x7C, 0x42, 0x42, 0x42, 0x42, 0x00},//         {0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x3C,  0x00},//         {0x00, 0x00, 0x7C, 0x42, 0x42, 0x7C, 0x40, 0x40},//  *      {0x00, 0x00, 0x3E, 0x42, 0x42, 0x3E, 0x02, 0x02},//       * {0x00, 0x00,  0x7C, 0x42, 0x40, 0x40, 0x40,  0x00},//       {0x00, 0x00, 0x3C, 0x40, 0x3C,0x02, 0x7C,  0x00},//         {0x00,   0x10,0x7C, 0x10, 0x10, 0x12,  0x0C, 0x00},//       {0x00, 0x00,  0x42, 0x42, 0x42, 0x42, 0x3E,   0x00},//         { 0x00, 0x00,0x42, 0x42,   0x24, 0x24, 0x18, 0x00},//         {0x00, 0x00, 0x42, 0x42, 0x5A, 0x5A, 0x24,  0x00},//         {0x00, 0x00, 0x42, 0x24, 0x18, 0x24, 0x42, 0x00},//         {0x00, 0x00, 0x42, 0x42, 0x3E, 0x02, 0x3C, 0x00},//         {0x00, 0x00, 0x7E, 0x04, 0x18, 0x20, 0x7E, 0x00},//      z   
};char asc[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,':',0x20,'-','_',',','?','!','.',';','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',			 };void xs(uint8_t ls,uint8_t le,uint8_t hs,uint8_t he,uint8_t *ci,uint8_t ys){qp(127-le,127-ls,hs,he);for (uint16_t a = 0; a < 8; a++) {for(uint8_t b=0;b<8;b++){if((int)(((ci[a]>>b)&0b00000001))==1){   //如果像素点为1st7735_send_data(ys);st7735_send_data(0x00);}else{st7735_send_data(0xff);st7735_send_data(0xff); }}}}void  hxs(uint8_t lc,uint8_t hc,char *i,size_t cd,uint8_t ys){    //在一行中显示字符uint16_t len=(int)cd;for(uint8_t a=0;a<len;a++){uint8_t ls=lc;uint8_t le=ls+7;uint8_t hs=hc;     uint8_t he=hs+7;	int asc_len=(int)sizeof(asc);for(int n=0;n<asc_len;n++){if(memcmp(&i[a],&asc[n],1)==0){        //查表xs(ls,le,hs,he,&font[n][0],ys);lc=le;		                    //列自动加7,相当于光标后移一个字符break;}}					     }	  }
//=========================================================================================================	void app_main() {i2c_master_init();gpio_set_direction(PIN_NUM_DC, GPIO_MODE_OUTPUT);gpio_set_direction(PIN_NUM_RST, GPIO_MODE_OUTPUT);spi_init();st7735_init();                             //lcd 初始化后是花屏cls();uint8_t data[7];              // 0-255 无符号数组char i[8];                    //字符串数组for(;;){//  uint8_t  i[]={6,1,8,3,7,3,6,7,8,7,1,7};  i2c_cmd_handle_t cmd = i2c_cmd_link_create();i2c_master_start(cmd);i2c_master_write_byte(cmd, (DS3231_ADDRESS << 1) | I2C_MASTER_WRITE, true);i2c_master_write_byte(cmd, 0x00, true);i2c_master_start(cmd);i2c_master_write_byte(cmd, (DS3231_ADDRESS << 1) | I2C_MASTER_READ, true);i2c_master_read(cmd,data, sizeof(data), I2C_MASTER_LAST_NACK);i2c_master_stop(cmd);esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_PERIOD_MS);i2c_cmd_link_delete(cmd);if (ret == ESP_OK) {uint8_t so=data[2];                      //时uint8_t soh=(so>>4)&0b00001111;i[0]=soh+0x30;                       //转为ascii 字符uint8_t sol=so&0b00001111;i[1]=sol+0x30;                         //转为ascii 字符i[2]=':';uint8_t fo=data[1];                   //分uint8_t foh=(fo>>4)&0b00001111;i[3]=foh+0x30;uint8_t fol=fo&0b00001111;i[4]=fol+0x30;i[5]=':';uint8_t mo=data[0];                      //秒uint8_t moh=(mo>>4)&0b00001111;i[6]=moh+0x30;uint8_t mol=mo&0b00001111;i[7]=mol+0x30;hxs(65,2,i,sizeof(i),0xf8);char i2[]="1;42,5:7_8.?!7a bcde";hxs(0,50,i2,sizeof(i2),0xf8);vTaskDelay(pdMS_TO_TICKS(100));}}
}

 

 

这篇关于(备份)常用ASCII 8*8 点阵 以及查询显示字符的点阵的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1125070

相关文章

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

JS常用组件收集

收集了一些平时遇到的前端比较优秀的组件,方便以后开发的时候查找!!! 函数工具: Lodash 页面固定: stickUp、jQuery.Pin 轮播: unslider、swiper 开关: switch 复选框: icheck 气泡: grumble 隐藏元素: Headroom

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

常用的jdk下载地址

jdk下载地址 安装方式可以看之前的博客: mac安装jdk oracle 版本:https://www.oracle.com/java/technologies/downloads/ Eclipse Temurin版本:https://adoptium.net/zh-CN/temurin/releases/ 阿里版本: github:https://github.com/

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

30常用 Maven 命令

Maven 是一个强大的项目管理和构建工具,它广泛用于 Java 项目的依赖管理、构建流程和插件集成。Maven 的命令行工具提供了大量的命令来帮助开发人员管理项目的生命周期、依赖和插件。以下是 常用 Maven 命令的使用场景及其详细解释。 1. mvn clean 使用场景:清理项目的生成目录,通常用于删除项目中自动生成的文件(如 target/ 目录)。共性规律:清理操作

019、JOptionPane类的常用静态方法详解

目录 JOptionPane类的常用静态方法详解 1. showInputDialog()方法 1.1基本用法 1.2带有默认值的输入框 1.3带有选项的输入对话框 1.4自定义图标的输入对话框 2. showConfirmDialog()方法 2.1基本用法 2.2自定义按钮和图标 2.3带有自定义组件的确认对话框 3. showMessageDialog()方法 3.1

ural 1026. Questions and Answers 查询

1026. Questions and Answers Time limit: 2.0 second Memory limit: 64 MB Background The database of the Pentagon contains a top-secret information. We don’t know what the information is — you

工作常用指令与快捷键

Git提交代码 git fetch  git add .  git commit -m “desc”  git pull  git push Git查看当前分支 git symbolic-ref --short -q HEAD Git创建新的分支并切换 git checkout -b XXXXXXXXXXXXXX git push origin XXXXXXXXXXXXXX

Mybatis中的like查询

<if test="templateName != null and templateName != ''">AND template_name LIKE CONCAT('%',#{templateName,jdbcType=VARCHAR},'%')</if>