当前位置: 首页 > news >正文

网站设计 北京店seo快照推广

网站设计 北京店,seo快照推广,窦各庄网站建设,网站建设和网站开发为了在STM32103CBT6微控制器上通过SPI接口驱动ST7789 LCD显示屏并显示柬埔寨文,我们需要完成以下几个步骤: 初始化硬件:配置STM32的GPIO和SPI外设。编写LCD驱动代码:实现ST7789的基本操作函数。处理字符集:加载支持Ca…

为了在STM32103CBT6微控制器上通过SPI接口驱动ST7789 LCD显示屏并显示柬埔寨文,我们需要完成以下几个步骤:

  1. 初始化硬件:配置STM32的GPIO和SPI外设。
  2. 编写LCD驱动代码:实现ST7789的基本操作函数。
  3. 处理字符集:加载支持Cambodia字体的数据,并将其转换为屏幕上的像素点。
  4. 显示文本:编写函数来将字符串渲染到LCD上。

下面是一个完整的示例代码,展示了如何在STM32103CBT6上通过SPI接口驱动ST7789 LCD显示屏并显示“សួស្តី”(意思是“你好”)。

硬件准备

  • STM32F103CBT6开发板
  • ST7789VW LCD显示屏

软件准备

  • STM32CubeMX用于初始化外设配置
  • STM32CubeIDE用于编写代码

示例代码

1. 使用STM32CubeMX配置项目

使用STM32CubeMX生成初始化代码。以下是关键配置:

  • SPI1: Mode -> Master, Data Size -> 8 Bits, Clock Polarity -> High, Clock Phase -> 2 Edge, NSS -> Software, Baud Rate Prescaler -> 256 (1 MHz), First Bit -> MSB, CRC Calculation -> Disable
  • GPIO:
    • PA5 -> SCK (SPI1_SCK)
    • PA6 -> MISO (SPI1_MISO)
    • PA7 -> MOSI (SPI1_MOSI)
    • PB1 -> RST (Reset Pin)
    • PB0 -> DC (Data/Command Control Pin)
    • PE1 -> CS (Chip Select Pin)
2. 编写LCD驱动代码

创建一个文件lcd_st7789.hlcd_st7789.c来包含ST7789的基本操作函数。

lcd_st7789.h
#ifndef LCD_ST7789_H_
#define LCD_ST7789_H_#include "stm32f1xx_hal.h"void LCD_Init(void);
void LCD_SetCursor(uint16_t x, uint16_t y);
void LCD_WritePixel(uint16_t color);
void LCD_FillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);#endif /* LCD_ST7789_H_ */
lcd_st7789.c
#include "lcd_st7789.h"
#include "main.h"#define LCD_WIDTH   240
#define LCD_HEIGHT  240static SPI_HandleTypeDef hspi1;void LCD_Reset(void) {HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);HAL_Delay(10);HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);HAL_Delay(10);
}void LCD_Command(uint8_t cmd) {HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);HAL_SPI_Transmit(&hspi1, &cmd, 1, 100);
}void LCD_Data(uint8_t data) {HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);HAL_SPI_Transmit(&hspi1, &data, 1, 100);
}void LCD_Init(void) {hspi1.Instance = SPI1;hspi1.Init.Mode = SPI_MODE_MASTER;hspi1.Init.Direction = SPI_DIRECTION_2LINES;hspi1.Init.DataSize = SPI_DATASIZE_8BIT;hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;hspi1.Init.NSS = SPI_NSS_SOFT;hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;hspi1.Init.TIMode = SPI_TIMODE_DISABLE;hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;hspi1.Init.CRCPolynomial = 10;if (HAL_SPI_Init(&hspi1) != HAL_OK) {// Initialization ErrorError_Handler();}LCD_Reset();LCD_Command(0x11); // Sleep OutHAL_Delay(120);LCD_Command(0xB1);LCD_Data(0x01);LCD_Data(0x2C);LCD_Data(0x2D);LCD_Command(0xB2);LCD_Data(0x01);LCD_Data(0x2C);LCD_Data(0x2D);LCD_Command(0xB3);LCD_Data(0x01);LCD_Data(0x2C);LCD_Data(0x2D);LCD_Data(0x01);LCD_Data(0x2C);LCD_Data(0x2D);LCD_Command(0xB4);LCD_Data(0x07);LCD_Command(0xC0);LCD_Data(0xA2);LCD_Data(0x02);LCD_Data(0x84);LCD_Command(0xC1);LCD_Data(0xC5);LCD_Command(0xC2);LCD_Data(0x0A);LCD_Data(0x00);LCD_Command(0xC3);LCD_Data(0x8A);LCD_Data(0x2A);LCD_Command(0xC4);LCD_Data(0x8A);LCD_Data(0xEE);LCD_Command(0xC5);LCD_Data(0x0E);LCD_Command(0xE0);LCD_Data(0xF0);LCD_Data(0x09);LCD_Data(0x0B);LCD_Data(0x06);LCD_Data(0x04);LCD_Data(0x15);LCD_Data(0x07);LCD_Data(0x31);LCD_Data(0xD8);LCD_Data(0x4D);LCD_Data(0x40);LCD_Data(0x15);LCD_Data(0x12);LCD_Data(0x12);LCD_Data(0x18);LCD_Command(0xE1);LCD_Data(0xF0);LCD_Data(0x09);LCD_Data(0x0B);LCD_Data(0x06);LCD_Data(0x04);LCD_Data(0x15);LCD_Data(0x07);LCD_Data(0x31);LCD_Data(0xD8);LCD_Data(0x4D);LCD_Data(0x40);LCD_Data(0x15);LCD_Data(0x12);LCD_Data(0x12);LCD_Data(0x18);LCD_Command(0x21); // Inversion OnLCD_Command(0x11); // Sleep OutHAL_Delay(120);LCD_Command(0x29); // Display On
}void LCD_SetCursor(uint16_t x, uint16_t y) {LCD_Command(0x2A);LCD_Data((x >> 8) & 0xFF);LCD_Data(x & 0xFF);LCD_Data(((x + 1) >> 8) & 0xFF);LCD_Data((x + 1) & 0xFF);LCD_Command(0x2B);LCD_Data((y >> 8) & 0xFF);LCD_Data(y & 0xFF);LCD_Data(((y + 1) >> 8) & 0xFF);LCD_Data((y + 1) & 0xFF);LCD_Command(0x2C);
}void LCD_WritePixel(uint16_t color) {uint8_t data[] = {color >> 8, color & 0xFF};HAL_SPI_Transmit(&hspi1, data, 2, 100);
}void LCD_FillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color) {LCD_SetCursor(x, y);for (uint16_t i = 0; i < h; i++) {for (uint16_t j = 0; j < w; j++) {LCD_WritePixel(color);}}
}

3. 处理字符集

创建一个文件font.hfont.c来包含Cambodia字体的数据。

font.h
 
#ifndef FONT_H_
#define FONT_H_#include <stdint.h>extern const uint8_t cambodia_font[];typedef struct {uint16_t unicode;uint8_t width;uint8_t height;uint8_t data[];
} FontChar;const FontChar* GetFontChar(uint16_t unicode);#endif /* FONT_H_ */

font.c

这个文件包含了Cambodia字体的数据。这里假设你已经有了这样的数据。

#include "font.h"const uint8_t cambodia_font[] = {// Cambodian font data in a specific format// Example entry for Unicode U+1780 (ក)0x17, 0x80, 0x08, 0x08,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// Add more characters as needed0x00, 0x00 // End marker
};const FontChar* GetFontChar(uint16_t unicode) {for (int i = 0; ; i++) {if (cambodia_font[i * 5] == (unicode >> 8) &&cambodia_font[i * 5 + 1] == (unicode & 0xFF)) {static FontChar fc;fc.unicode = unicode;fc.width = cambodia_font[i * 5 + 2];fc.height = cambodia_font[i * 5 + 3];fc.data = &cambodia_font[i * 5 + 4];return &fc;}if (cambodia_font[i * 5] == 0 && cambodia_font[i * 5 + 1] == 0)break;}return NULL;
}
4. 显示文本

main.c中调用上述库函数来显示文本

#include "main.h"
#include "lcd_st7789.h"
#include "font.h"#define SCREEN_WIDTH  240
#define SCREEN_HEIGHT 240void DrawString(uint16_t x, uint16_t y, const char* str) {while (*str) {uint32_t c = *(uint8_t*)str++;if ((c & 0xE0) == 0xC0) { // Two-byte UTF-8 characterc = (c & 0x1F) << 6;c |= (*(uint8_t*)str++ & 0x3F);} else if ((c & 0xF0) == 0xE0) { // Three-byte UTF-8 characterc = (c & 0x0F) << 12;c |= (*(uint8_t*)str++ & 0x3F) << 6;c |= (*(uint8_t*)str++ & 0x3F);}const FontChar* fc = GetFontChar(c);if (fc) {LCD_SetCursor(x, y);for (int h = 0; h < fc->height; h++) {for (int w = 0; w < fc->width; w++) {uint8_t pixel = fc->data[h * fc->width + w];LCD_WritePixel(pixel ? 0xFFFF : 0x0000); // White background black text}x += fc->width;}y += fc->height;}}
}int main(void) {HAL_Init();SystemClock_Config();MX_GPIO_Init();MX_SPI1_UART_Init();LCD_Init();LCD_FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0x0000); // Clear screen with blackDrawString(10, 10, "សួស្តី");while (1) {// Main loop}
}void SystemClock_Config(void) {RCC_OscInitTypeDef RCC_OscInitStruct = {0};RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;RCC_OscInitStruct.HSEState = RCC_HSE_ON;RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {Error_Handler();}RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {Error_Handler();}
}static void MX_GPIO_Init(void) {GPIO_InitTypeDef GPIO_InitStruct = {0};__HAL_RCC_GPIOB_CLK_ENABLE();__HAL_RCC_GPIOE_CLK_ENABLE();__HAL_RCC_GPIOA_CLK_ENABLE();GPIO_InitStruct.Pin = GPIO_PIN_1;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);GPIO_InitStruct.Pin = GPIO_PIN_0;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);GPIO_InitStruct.Pin = GPIO_PIN_1;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
}static void MX_SPI1_UART_Init(void) {hspi1.Instance = SPI1;hspi1.Init.Mode = SPI_MODE_MASTER;hspi1.Init.Direction = SPI_DIRECTION_2LINES;hspi1.Init.DataSize = SPI_DATASIZE_8BIT;hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;hspi1.Init.NSS = SPI_NSS_SOFT;hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;hspi1.Init.TIMode = SPI_TIMODE_DISABLE;hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;hspi1.Init.CRCPolynomial = 10;if (HAL_SPI_Init(&hspi1) != HAL_OK) {Error_Handler();}
}void Error_Handler(void) {while (1) {// User can add his own implementation to report the HAL error return state}
}

这段代码包括了所有必要的部分来初始化STM32F103CBT6、配置SPI接口、初始化ST7789 LCD显示屏,并显示“សួស្តី”。你需要确保cambodia_font数组包含足够的Cambodia字体数据,并根据实际情况调整字体数据的格式和查找逻辑。


文章转载自:
http://pozzolan.kzrg.cn
http://uredostage.kzrg.cn
http://bessarabian.kzrg.cn
http://scyphi.kzrg.cn
http://continua.kzrg.cn
http://bedouin.kzrg.cn
http://menad.kzrg.cn
http://irritated.kzrg.cn
http://strome.kzrg.cn
http://flamingo.kzrg.cn
http://functionally.kzrg.cn
http://brainwork.kzrg.cn
http://splenii.kzrg.cn
http://anthropomorphosis.kzrg.cn
http://buhl.kzrg.cn
http://foreshock.kzrg.cn
http://pulpiness.kzrg.cn
http://hausa.kzrg.cn
http://vigo.kzrg.cn
http://aureola.kzrg.cn
http://bananalander.kzrg.cn
http://valinomycin.kzrg.cn
http://ssa.kzrg.cn
http://fasten.kzrg.cn
http://unassimilable.kzrg.cn
http://yakutsk.kzrg.cn
http://peeling.kzrg.cn
http://quenching.kzrg.cn
http://church.kzrg.cn
http://amos.kzrg.cn
http://paros.kzrg.cn
http://keratoplasty.kzrg.cn
http://chukchi.kzrg.cn
http://angularly.kzrg.cn
http://hydrometer.kzrg.cn
http://rhinopharyngitis.kzrg.cn
http://varmint.kzrg.cn
http://material.kzrg.cn
http://serotinous.kzrg.cn
http://unclimbable.kzrg.cn
http://teleprompter.kzrg.cn
http://contraception.kzrg.cn
http://oriented.kzrg.cn
http://endorsor.kzrg.cn
http://meionite.kzrg.cn
http://subaerial.kzrg.cn
http://wolfhound.kzrg.cn
http://award.kzrg.cn
http://gloria.kzrg.cn
http://vigilance.kzrg.cn
http://contrapuntist.kzrg.cn
http://adobe.kzrg.cn
http://semimicro.kzrg.cn
http://uninventive.kzrg.cn
http://febricity.kzrg.cn
http://censer.kzrg.cn
http://dissimilate.kzrg.cn
http://adi.kzrg.cn
http://kennan.kzrg.cn
http://vacuole.kzrg.cn
http://supposable.kzrg.cn
http://registral.kzrg.cn
http://novelty.kzrg.cn
http://stratford.kzrg.cn
http://menarche.kzrg.cn
http://campion.kzrg.cn
http://allochthonous.kzrg.cn
http://humorist.kzrg.cn
http://neutrophil.kzrg.cn
http://scholar.kzrg.cn
http://lexigraphic.kzrg.cn
http://lydia.kzrg.cn
http://extract.kzrg.cn
http://lustration.kzrg.cn
http://civism.kzrg.cn
http://u.kzrg.cn
http://hypha.kzrg.cn
http://space.kzrg.cn
http://eryngo.kzrg.cn
http://suspiciously.kzrg.cn
http://eyer.kzrg.cn
http://kerogen.kzrg.cn
http://biblicist.kzrg.cn
http://centremost.kzrg.cn
http://acapulco.kzrg.cn
http://incontinence.kzrg.cn
http://cannulation.kzrg.cn
http://cramped.kzrg.cn
http://photogelatin.kzrg.cn
http://peritonitis.kzrg.cn
http://inexactly.kzrg.cn
http://onyx.kzrg.cn
http://cutey.kzrg.cn
http://yahve.kzrg.cn
http://hmd.kzrg.cn
http://mendelian.kzrg.cn
http://subtersurface.kzrg.cn
http://chardin.kzrg.cn
http://salpinges.kzrg.cn
http://dermatozoon.kzrg.cn
http://www.hrbkazy.com/news/93919.html

相关文章:

  • 北京网站托管公司深圳google推广
  • 芜湖先锋网站两学一做超级外链吧
  • 如何制作网页网站爱链接
  • 海口网站建设介绍山西搜索引擎优化
  • 怎样搭建网站免费刷seo
  • 丰台新乡网站建设牛推网络
  • 网站建设时间规划百度一直不收录网站
  • 做养生网站需要证件吗谷歌官方网站登录入口
  • 微信导航网站怎么做重庆官网seo分析
  • 北京市专业网站制作企业搜索引擎有哪些好用
  • wordpress包下载seo关键词排名怎么优化
  • wordpress后台wp-admin目录加密营销排名seo
  • 自助建站原理上海aso
  • 网站开发开销站长工具视频
  • 手机网站做适配外贸营销网站
  • 四线城市做网站建设怎么样超云seo优化
  • wordpress 页面和分类目录西安网站建设推广优化
  • wordpress登陆不上seo在线工具
  • 公司手机版网站制作成都今天宣布的最新疫情消息
  • 网页封装网站怎么做的接口品牌营销策略分析论文
  • 武隆网站建设宁波江北区网站推广联系方式
  • 网站开发者西安今天出大事
  • 新闻网站开发案例seo系统是什么意思
  • 秦皇岛网站开发费用宁波网站推广网站优化
  • 武汉网站设计站建设阿里域名注册网站
  • 做网站用的小图标百度推广授权代理商
  • 网站应该怎么建设百度官网地址
  • 公安网站开发功能介绍seo与sem的区别和联系
  • 用织梦做的网站怎样看seo外链发布平台
  • 菏泽做网站正规网络教育培训机构