本帖最后由 及辰 于 2024-5-3 21:27 编辑
本次活动是在B站UP主:安信可科技发布的视频了解到的。
【祖传点灯】安信可Ai-M61-32S环境配置+点灯+TFTLCD屏幕点亮
十分感谢安信可科技提供的机会,感谢园长选中!点个屏幕
1、编译环境搭建
默认已安装VSCode和Git,如未安装好,可以去官网下载默认安装或者百度寻找一个教程。
1.1 克隆 AiPi-Open-Kits 仓库
在win图标上右键,弹出窗口点终端打开CMD控制台。
新建一个文件夹用来存放下载的编译文件,此处新建文件夹地址为:D:\software\AIM6132S,可以自己创建一个属于自己的文件夹。在CMD终端输入cd D:\software\AIM6132S,回车进入新建文件夹。
在CMD终端输入cd D:\software\AIM6132S\AiPi-Open-Kits,进入AiPi-Open-Kits文件夹。在CMD终端输入git submodule init,回车等待后(这里等待时间有点长)输入git submodule update 执行子模块更新。可以对比查看是否正常。(对比下看是否有报错)
1.2 克隆 aithinker_Ai-M6X_SDK 仓库
在CMD终端输入 git clone https://gitee.com/Ai-Thinker-Open/aithinker_Ai-M6X_SDK.git,回车克隆 aithinker_Ai-M6X_SDK 仓库
在CMD终端输入cd D:\software\AIM6132S\AiPi-Open-Kits\aithinker_Ai-M6X_SDK,回车进入文件夹;在CMD终端输入git submodule init,回车等待后(这里等待时间有点长)输入git submodule update 执行子模块更新。可以对比查看是否正常。(对比下看是否有报错)
1.3 配置 GCC 编译链
在CMD终端输入 git clone https://gitee.com/bouffalolab/toolchain_gcc_t-head_windows.git拉取 toolchain_gcc_t-head_windows 仓库
检查下D:\software\AIM6132S\AiPi-Open-Kits\aithinker_Ai-M6X_SDK\toolchain_gcc_t-head_windows 、 D:\software\AIM6132S\AiPi-Open-Kits\aithinker_Ai-M6X_SDK\toolchain 、 D:\software\AIM6132S\AiPi-Open-Kits\aithinker_Ai-M6X_SDK\tools三个文件夹,看下是否都有文件
1.4 添加系统环境变量
在桌面-此电脑(右键)-属性(点击)-高级系统设置(点击)-环境变量(点击)-系统变量/path(双击)-新建(点击),在下面加入三个地址(这里的地址根据最开始自己设置的文件夹修改,此处对应的地址如下图
上图为本电脑的三个地址,添加成功后点击确定。(这个地址只要对的,理论上在任何位置都可以)
1.5 验证
在CMD终端输入 make -v回车后输入riscv64-unknown-elf-gcc -v,可以对比下下图,确认环境是否配置成功
2、RGB点灯
2.1 代码修改
将参考代码复制一份(这里选中的是AiPi-Open-Kits\AiPi-Eyes-DU),粘贴到自己存放代码的文件夹内(改名为test_one)
用记事本打开 Makefile 文件,修改 BL_SDK_BASE 路径
上图地址改成最开始自己设置的地址,一定要改不然会报错。
用记事本或者VSCode打开main.c,修改代码如下
- #include "bflb_mtimer.h"
- #include "bflb_pwm_v2.h"
- #include "bflb_clock.h"
- #include "bflb_gpio.h"
- #include "board.h"
- struct bflb_device_s *pwm;
- struct bflb_device_s *gpio;
- int main(void)
- {
- int i;
- board_init();
- pwm = bflb_device_get_by_name("pwm_v2_0");
- gpio = bflb_device_get_by_name("gpio");
- /*初始化RGB灯,IO15、12、14,对应蓝灯、红灯、绿灯*/
- bflb_gpio_init(gpio, GPIO_PIN_15, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- bflb_gpio_init(gpio, GPIO_PIN_12, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- bflb_gpio_init(gpio, GPIO_PIN_14, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
-
- /* period = .XCLK / .clk_div / .period = 40MHz / 40 / 1000 = 1KHz */
- struct bflb_pwm_v2_config_s cfg = {
- .clk_source = BFLB_SYSTEM_XCLK,
- .clk_div = 40,
- .period = 1000,
- };
-
- /*初始化PWM输出*/
- bflb_pwm_v2_init(pwm, &cfg);
- bflb_pwm_v2_start(pwm);
- /*功能实现,红、绿、蓝灯依次呼吸循环亮灭*/
- while (1) {
- //红灯呼吸亮灭
- bflb_pwm_v2_channel_positive_start(pwm, PWM_CH0);
- for(i=100;i>0;i--)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH0, i, 100);
-
- bflb_mtimer_delay_ms(10);
- }
- for(i=1;i<100;i++)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH0, i, 100);
- bflb_mtimer_delay_ms(10);
- }
- bflb_pwm_v2_channel_positive_stop(pwm, PWM_CH0);
- //绿灯呼吸亮灭
- bflb_pwm_v2_channel_positive_start(pwm, PWM_CH2);
- for(i=100;i>0;i--)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH2, i, 100);
- bflb_mtimer_delay_ms(10);
- }
- for(i=1;i<100;i++)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH2, i, 100);
- bflb_mtimer_delay_ms(10);
- }
- bflb_pwm_v2_channel_positive_stop(pwm, PWM_CH2);
- //蓝灯循环亮灭
- bflb_pwm_v2_channel_positive_start(pwm, PWM_CH3);
- for(i=100;i>0;i--)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH3, i, 100);
- bflb_mtimer_delay_ms(10);
- }
- for(i=1;i<100;i++)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH3, i, 100);
- bflb_mtimer_delay_ms(10);
- }
- bflb_pwm_v2_channel_positive_stop(pwm, PWM_CH3);
- }
- }
复制代码如果在VSCode中打开的文件,则在文件夹名称上右键,点击在集成终端中打开,输入make clean ,然后输入make,如果结果如图,则编译成功;
如果用记事本修改的文件,则在目录下打开终端,或者打开终端再cd进文件夹,输入make clean ,然后输入make,如果结果如图,则编译成功。
在桌面-此电脑(右键)-查看更多选项(点击)-管理(点击)-设备管理器(点击)-端口(点击)查看COM口是第几个,如图为COM4
在刚才输入make的地方输入 make flash CHIP=bl616 COMX=COM4,这里的COM4改成自己的COM口,在烧录之前先按下IO2,再按下EN,松开EN,回车烧录,烧录成功如图,然后松开IO2,点击一下EN就可以成功运行了。
成功点灯
2、点亮屏幕
将上文中的make.c中的代码改为如下:
- #include "bflb_mtimer.h"
- #include "bflb_clock.h"
- #include "bflb_spi.h"
- #include "bflb_gpio.h"
- #include "board.h"
- #define CS_PIN GPIO_PIN_12
- #define DC_PIN GPIO_PIN_27
- #define RES_PIN GPIO_PIN_26
- #define BLK_PIN GPIO_PIN_28
- #define MOSI_PIN GPIO_PIN_19
- #define MISO_PIN GPIO_PIN_18
- #define CLK_PIN GPIO_PIN_13
- #define FREQUARY 50
- #define u8 unsigned char
- #define u16 unsigned short
- #define u32 unsigned int
- #define LCD_CASET 0x2A
- #define LCD_RASET 0x2B
- #define LCD_RAMWR 0x2C
- #define LCD_MADCTL 0x36 //定义帧内存的读写扫描方向
- #define TFT_CS_Reset bflb_gpio_reset(gpio, CS_PIN);
- #define TFT_CS_Set bflb_gpio_set(gpio, CS_PIN);
- #define TFT_DC_Reset bflb_gpio_reset(gpio, DC_PIN); //cmd
- #define TFT_DC_Set bflb_gpio_set(gpio, DC_PIN); //data
- #define TFT_RES_Reset bflb_gpio_reset(gpio, RES_PIN);
- #define TFT_RES_Set bflb_gpio_set(gpio, RES_PIN);
- #define TFT_BLK_Reset bflb_gpio_reset(gpio, BLK_PIN);
- #define TFT_BLK_Set bflb_gpio_set(gpio, BLK_PIN);
- struct bflb_device_s *spi0;
- struct bflb_device_s *gpio;
- #define USE_ONCHIP_FLASH_FONT 1
- const unsigned char asc16[] =
- {
- #if USE_ONCHIP_FLASH_FONT
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //" "
- 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, //"!"
- 0x00, 0x00, 0x6C, 0x6C, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, //"""
- 0x00, 0x24, 0x24, 0x24, 0x24, 0xFE, 0x48, 0x48, 0x48, 0x48, 0xFC, 0x90, 0x90, 0x90, 0x90, 0x00, //"#"
- 0x00, 0x10, 0x3C, 0x54, 0x92, 0x90, 0x50, 0x38, 0x14, 0x12, 0x12, 0x92, 0x54, 0x78, 0x10, 0x00, //"$"
- 0x00, 0x00, 0x22, 0x5C, 0x94, 0xA8, 0x48, 0x10, 0x10, 0x24, 0x2A, 0x52, 0x54, 0x88, 0x00, 0x00, //"%"
- 0x00, 0x00, 0x30, 0x48, 0x48, 0x50, 0x20, 0x6E, 0x54, 0x94, 0x8C, 0x88, 0x8A, 0x74, 0x00, 0x00, //"&"
- 0x00, 0x00, 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //"'"
- 0x00, 0x04, 0x08, 0x10, 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x10, 0x08, 0x04, 0x00, //"("
- 0x00, 0x80, 0x40, 0x20, 0x20, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x40, 0x80, 0x00, //")"
- 0x00, 0x00, 0x00, 0x00, 0x10, 0x54, 0x38, 0x10, 0x38, 0x54, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, //"*"
- 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0xFE, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, //"+"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x20, 0x00, //","
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //"-"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, //"."
- 0x00, 0x00, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, //"/"
- 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00, //"0"
- 0x00, 0x00, 0x10, 0x70, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7C, 0x00, 0x00, //"1"
- 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x04, 0x08, 0x10, 0x20, 0x40, 0x82, 0x84, 0xFC, 0x00, 0x00, //"2"
- 0x00, 0x00, 0x38, 0x44, 0x82, 0x02, 0x04, 0x38, 0x04, 0x02, 0x02, 0x82, 0x44, 0x38, 0x00, 0x00, //"3"
- 0x00, 0x00, 0x04, 0x0C, 0x14, 0x14, 0x24, 0x24, 0x44, 0x44, 0xFE, 0x04, 0x04, 0x0E, 0x00, 0x00, //"4"
- 0x00, 0x00, 0xFC, 0x80, 0x80, 0x80, 0xB8, 0xC4, 0x82, 0x02, 0x02, 0x82, 0x84, 0x78, 0x00, 0x00, //"5"
- 0x00, 0x00, 0x3C, 0x42, 0x82, 0x80, 0xB8, 0xC4, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00, //"6"
- 0x00, 0x00, 0x7E, 0x42, 0x82, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, //"7"
- 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x44, 0x38, 0x44, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00, //"8"
- 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x46, 0x3A, 0x02, 0x82, 0x44, 0x38, 0x00, 0x00, //"9"
- 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, //":"
- 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00, //";"
- 0x00, 0x00, 0x00, 0x00, 0x06, 0x18, 0x60, 0x80, 0x60, 0x18, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, //"<"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //"="
- 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, 0x0C, 0x02, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, //">"
- 0x00, 0x38, 0x44, 0x82, 0x82, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, //"?"
- 0x00, 0x00, 0x38, 0x44, 0x82, 0x9A, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x96, 0x80, 0x42, 0x3C, 0x00, //"@"
- 0x00, 0x00, 0x10, 0x10, 0x10, 0x28, 0x28, 0x28, 0x44, 0x44, 0x7C, 0x44, 0x44, 0xEE, 0x00, 0x00, //"A"
- 0x00, 0x00, 0xFC, 0x42, 0x42, 0x42, 0x42, 0x7C, 0x42, 0x42, 0x42, 0x42, 0x42, 0xFC, 0x00, 0x00, //"B"
- 0x00, 0x00, 0x3C, 0x44, 0x82, 0x80, 0x80, 0x80, 0x80, 0x80, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00, //"C"
- 0x00, 0x00, 0xF8, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x44, 0xF8, 0x00, 0x00, //"D"
- 0x00, 0x00, 0xFC, 0x44, 0x42, 0x40, 0x44, 0x7C, 0x44, 0x40, 0x40, 0x42, 0x44, 0xFC, 0x00, 0x00, //"E"
- 0x00, 0x00, 0xFC, 0x44, 0x42, 0x40, 0x44, 0x7C, 0x44, 0x40, 0x40, 0x40, 0x40, 0xF0, 0x00, 0x00, //"F"
- 0x00, 0x00, 0x34, 0x4C, 0x82, 0x80, 0x80, 0x80, 0x8E, 0x84, 0x84, 0x84, 0x4C, 0x34, 0x00, 0x00, //"G"
- 0x00, 0x00, 0xEE, 0x44, 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x44, 0x44, 0xEE, 0x00, 0x00, //"H"
- 0x00, 0x00, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7C, 0x00, 0x00, //"I"
- 0x00, 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x88, 0x70, 0x00, 0x00, //"J"
- 0x00, 0x00, 0xEE, 0x44, 0x48, 0x48, 0x50, 0x60, 0x50, 0x48, 0x48, 0x44, 0x44, 0xEE, 0x00, 0x00, //"K"
- 0x00, 0x00, 0xE0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x42, 0x44, 0xFC, 0x00, 0x00, //"L"
- 0x00, 0x00, 0xC6, 0x44, 0x6C, 0x6C, 0x6C, 0x54, 0x54, 0x54, 0x44, 0x44, 0x44, 0xEE, 0x00, 0x00, //"M"
- 0x00, 0x00, 0xCE, 0x44, 0x64, 0x64, 0x64, 0x54, 0x54, 0x4C, 0x4C, 0x4C, 0x44, 0xE4, 0x00, 0x00, //"N"
- 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00, //"O"
- 0x00, 0x00, 0xF8, 0x44, 0x42, 0x42, 0x42, 0x44, 0x78, 0x40, 0x40, 0x40, 0x40, 0xE0, 0x00, 0x00, //"P"
- 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0xBA, 0x44, 0x3C, 0x02, 0x00, //"Q"
- 0x00, 0x00, 0xF0, 0x48, 0x44, 0x44, 0x44, 0x48, 0x70, 0x48, 0x44, 0x44, 0x44, 0xE6, 0x00, 0x00, //"R"
- 0x00, 0x00, 0x3C, 0x44, 0x82, 0x80, 0x40, 0x30, 0x0C, 0x02, 0x02, 0x82, 0x44, 0x78, 0x00, 0x00, //"S"
- 0x00, 0x00, 0x7C, 0x54, 0x92, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, //"T"
- 0x00, 0x00, 0xEE, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, //"U"
- 0x00, 0x00, 0xEE, 0x44, 0x44, 0x44, 0x44, 0x28, 0x28, 0x28, 0x28, 0x10, 0x10, 0x10, 0x00, 0x00, //"V"
- 0x00, 0x00, 0xEE, 0x44, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, //"W"
- 0x00, 0x00, 0xEE, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x28, 0x28, 0x44, 0x44, 0xEE, 0x00, 0x00, //"X"
- 0x00, 0x00, 0xEE, 0x44, 0x44, 0x28, 0x28, 0x28, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, //"Y"
- 0x00, 0x00, 0x7E, 0x44, 0x84, 0x08, 0x08, 0x10, 0x20, 0x20, 0x40, 0x82, 0x84, 0xFC, 0x00, 0x00, //"Z"
- 0x00, 0x1C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1C, 0x00, //"["
- 0x00, 0x00, 0xEE, 0x44, 0x54, 0x54, 0xFE, 0x54, 0x54, 0x54, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, //""
- 0x00, 0x70, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x70, 0x00, //"]"
- 0x00, 0x30, 0x48, 0x84, 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, 0xFE, 0x00, //"_"
- 0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //"`"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x84, 0x04, 0x7C, 0x84, 0x84, 0x8C, 0x76, 0x00, 0x00, //"a"
- 0x00, 0x00, 0xC0, 0x40, 0x40, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x64, 0x58, 0x00, 0x00, //"b"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x80, 0x80, 0x80, 0x80, 0x44, 0x38, 0x00, 0x00, //"c"
- 0x00, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x34, 0x4C, 0x84, 0x84, 0x84, 0x84, 0x4C, 0x36, 0x00, 0x00, //"d"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x84, 0x84, 0xFC, 0x80, 0x80, 0x84, 0x78, 0x00, 0x00, //"e"
- 0x00, 0x00, 0x18, 0x24, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, //"f"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3A, 0x44, 0x44, 0x78, 0x80, 0x7C, 0x82, 0x82, 0x7C, 0x00, //"g"
- 0x00, 0x00, 0xC0, 0x40, 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x44, 0x44, 0x44, 0xEE, 0x00, 0x00, //"h"
- 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, //"i"
- 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x90, 0x60, 0x00, //"j"
- 0x00, 0x00, 0xC0, 0x40, 0x40, 0x40, 0x5C, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0xEE, 0x00, 0x00, //"k"
- 0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0x39, 0x00, 0x00, //"l"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAC, 0xD2, 0x92, 0x92, 0x92, 0x92, 0x92, 0xD6, 0x00, 0x00, //"m"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0xE4, 0x44, 0x44, 0x44, 0x44, 0x44, 0xEE, 0x00, 0x00, //"n"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00, //"o"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x64, 0x42, 0x42, 0x42, 0x64, 0x58, 0x40, 0xE0, 0x00, //"p"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x4C, 0x84, 0x84, 0x84, 0x4C, 0x34, 0x04, 0x0E, 0x00, //"q"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00, //"r"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x88, 0x84, 0x60, 0x18, 0x84, 0x44, 0x78, 0x00, 0x00, //"s"
- 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x20, 0x20, 0x20, 0x24, 0x18, 0x00, 0x00, //"t"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC6, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3A, 0x00, 0x00, //"u"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x44, 0x44, 0x28, 0x28, 0x28, 0x10, 0x10, 0x00, 0x00, //"v"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x44, 0x44, 0x54, 0x54, 0x28, 0x28, 0x28, 0x00, 0x00, //"w"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x44, 0x28, 0x10, 0x10, 0x28, 0x44, 0xEE, 0x00, 0x00, //"x"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0xA0, 0xC0, 0x00, //"y"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x44, 0x88, 0x10, 0x20, 0x42, 0x84, 0xFC, 0x00, 0x00, //"z"
- 0x00, 0x0C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x60, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0C, 0x00, //"{"
- 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, //"|"
- 0x00, 0xC0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x18, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xC0, 0x00, //"}"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //"~"
- #endif
- 0x00, };
- struct typFNT_GB162
- {
- unsigned char Index[3];
- unsigned char Msk[32];
- };
- #define HANZI_num 12
- const struct typFNT_GB162 hanzi[] =
- {
- #if USE_ONCHIP_FLASH_FONT
- "感", 0x00,0x28,0x00,0x24,0x3F,0xFE,0x20,0x20,0x2F,0xA4,0x20,0x24,0x2F,0xA8,0x28,0x98,0x28,0x92,0x4F,0xAA,0x40,0x46,0x80,0x82,0x01,0x00,0x48,0x84,0x48,0x12,0x87,0xF2,//感0
- "谢", 0x01,0x08,0x42,0x08,0x27,0x88,0x24,0x88,0x07,0xBE,0x04,0x88,0xE7,0x88,0x24,0xC8,0x24,0xA8,0x2F,0xA8,0x21,0x88,0x2A,0x88,0x34,0x88,0x28,0x88,0x02,0xA8,0x01,0x10,//谢1
- "安", 0x02,0x00,0x01,0x00,0x3F,0xFC,0x20,0x04,0x42,0x08,0x02,0x00,0x02,0x00,0xFF,0xFE,0x04,0x20,0x08,0x20,0x18,0x40,0x06,0x40,0x01,0x80,0x02,0x60,0x0C,0x10,0x70,0x08,//安2
- "信", 0x08,0x40,0x08,0x20,0x0B,0xFE,0x10,0x00,0x10,0x00,0x31,0xFC,0x30,0x00,0x50,0x00,0x91,0xFC,0x10,0x00,0x10,0x00,0x11,0xFC,0x11,0x04,0x11,0x04,0x11,0xFC,0x11,0x04,//信3
- "可", 0x00,0x00,0x7F,0xFE,0x00,0x10,0x00,0x10,0x1F,0x10,0x11,0x10,0x11,0x10,0x11,0x10,0x11,0x10,0x11,0x10,0x1F,0x10,0x11,0x10,0x00,0x10,0x00,0x10,0x00,0x50,0x00,0x20,//可4
- "赠", 0x00,0x88,0x7C,0x48,0x44,0x50,0x55,0xFC,0x55,0x24,0x55,0xAC,0x55,0x74,0x55,0x24,0x55,0xFC,0x54,0x00,0x54,0xF8,0x10,0x88,0x28,0xF8,0x24,0x88,0x44,0xF8,0x80,0x88,//赠5
- "送", 0x02,0x08,0x21,0x08,0x11,0x10,0x17,0xFC,0x00,0x40,0x00,0x40,0xF0,0x40,0x17,0xFE,0x10,0x40,0x10,0xA0,0x10,0x90,0x11,0x08,0x12,0x08,0x28,0x00,0x47,0xFE,0x00,0x00,//送6
- "开", 0x00,0x00,0x7F,0xFC,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xFF,0xFE,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0x10,0x20,0x10,0x20,0x20,0x20,0x40,0x20,//开7
- "发", 0x01,0x00,0x11,0x10,0x11,0x08,0x22,0x00,0x3F,0xFC,0x02,0x00,0x04,0x00,0x07,0xF8,0x0A,0x08,0x09,0x08,0x11,0x10,0x10,0xA0,0x20,0x40,0x40,0xA0,0x03,0x18,0x1C,0x06,//发8
- "板", 0x10,0x08,0x10,0x1C,0x11,0xE0,0x11,0x00,0xFD,0x00,0x11,0xFC,0x31,0x44,0x39,0x44,0x55,0x44,0x55,0x28,0x91,0x28,0x11,0x10,0x11,0x10,0x12,0x28,0x12,0x44,0x14,0x82,//板9
- "%", 0x00, 0x00, 0x00, 0x44, 0xA4, 0xA8, 0xA8, 0xB0, 0x54, 0x1A, 0x2A, 0x2A, 0x4A, 0x44, 0x00, 0x00,/*"%",0*/ //新增加的要放在这个“%前面,不然会报错”
- #endif
- 0x00, };
- void spi_init();
- void Lcd_init();
- void Lcd_reset();
- void Lcd_WriteCmd(u8 data);
- void Lcd_WriteData(u8 data);
- void set_background(u16 color);
- void set_frame_size(u16 x_start, u16 x_end, u16 y_start, u16 y_end);
- void Show_Ch_GBK16(u16 x, u16 y, u16 fc, u16 bc, u8 *s);
- void set_scan_direction(u8 data)
- {
- Lcd_WriteCmd(LCD_MADCTL);
- Lcd_WriteData(data);
- }
- void Show_Ch_GBK16(u16 x, u16 y, u16 fc, u16 bc, u8 *s)
- {
- u8 i, j;
- u16 k, x0;
- u16 index = 0;
- x0 = x;
- while (*(s + index))
- {
- if ((*(s + index)) < 128)
- {
- k = *(s + index);
- if (k == 13)
- {
- x = x0;
- y += 16;
- }
- else
- {
- if (k > 32)
- k -= 32;
- else
- k = 0;
- set_frame_size (x, x + 8, y, y + 16);
- TFT_DC_Set;
- TFT_CS_Reset;
- for (i = 0; i < 16; i++)
- {
- for (j = 0; j < 8; j++)
- {
- if (asc16[k * 16 + i] & (0x80 >> j))
- {
- bflb_spi_poll_send(spi0,fc >> 8);
- bflb_spi_poll_send(spi0,fc);
- }
- else
- {
- bflb_spi_poll_send(spi0,bc >> 8);
- bflb_spi_poll_send(spi0,bc);
- }
- }
- }
- TFT_CS_Set;
- x += 8;
- }
- index++;
- }
- else
- {
- for (k=0;k<HANZI_num;k++)
- {
- if ((hanzi[k].Index[0]==*(s))&&(hanzi[k].Index[1]==*(s+1))&&(hanzi[k].Index[2]==*(s+2)))
- {
- set_frame_size (x, x + 16, y, y + 16);
- TFT_DC_Set;
- TFT_CS_Reset;
- for(i=0;i<16;i++)
- {
- for(j=0;j<8;j++)
- {
- if(hanzi[k].Msk[i*2]&(0x80>>j))
- {
- bflb_spi_poll_send(spi0,fc >> 8);
- bflb_spi_poll_send(spi0,fc);
- }
- else
- {
- bflb_spi_poll_send(spi0,bc >> 8);
- bflb_spi_poll_send(spi0,bc);
- }
- }
- for(j=0;j<8;j++)
- {
- if(hanzi[k].Msk[i*2+1]&(0x80>>j))
- {
- bflb_spi_poll_send(spi0,fc >> 8);
- bflb_spi_poll_send(spi0,fc);
- }
- else
- {
- bflb_spi_poll_send(spi0,bc >> 8);
- bflb_spi_poll_send(spi0,bc);
- }
- }
- }
- TFT_CS_Set;
- }
- }
- s+=3;x+=16;
- }
- }
- }
- void spi_init()
- {
- gpio = bflb_device_get_by_name("gpio");
- /* spi mosi */
- bflb_gpio_init(gpio, MOSI_PIN, GPIO_FUNC_SPI0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- /* spi miso */
- bflb_gpio_init(gpio, MISO_PIN, GPIO_FUNC_SPI0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- /* spi cs */
- bflb_gpio_init(gpio, CS_PIN, GPIO_FUNC_SPI0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- /* spi clk */
- bflb_gpio_init(gpio, CLK_PIN, GPIO_FUNC_SPI0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
- //res
- bflb_gpio_init(gpio, RES_PIN, GPIO_OUTPUT | GPIO_PULLUP);
- // dc
- bflb_gpio_init(gpio, DC_PIN, GPIO_OUTPUT | GPIO_PULLUP);
- // blk
- bflb_gpio_init(gpio, BLK_PIN, GPIO_OUTPUT | GPIO_PULLUP);
- struct bflb_spi_config_s spi_cfg =
- {
- .freq = FREQUARY * 1000 * 1000,
- .role = SPI_ROLE_MASTER,
- .mode = SPI_MODE3,
- .data_width = SPI_DATA_WIDTH_8BIT,
- .bit_order = SPI_BIT_MSB,
- .byte_order = SPI_BYTE_LSB,
- .tx_fifo_threshold = 0,
- .rx_fifo_threshold = 0,
- };
- spi0 = bflb_device_get_by_name("spi0");
- bflb_spi_init(spi0, &spi_cfg);
- bflb_spi_feature_control(spi0, SPI_CMD_SET_CS_INTERVAL, 0);
- }
- void set_frame_size(u16 x_start, u16 x_end, u16 y_start, u16 y_end)
- {
- x_end-=1;
- y_end-=1;
- Lcd_WriteCmd(LCD_CASET);
- Lcd_WriteData(x_start>>8);
- Lcd_WriteData(x_start);
- Lcd_WriteData(x_end>>8);
- Lcd_WriteData(x_end);
- Lcd_WriteCmd(LCD_RASET);
- Lcd_WriteData(y_start>>8);
- Lcd_WriteData(y_start);
- Lcd_WriteData(y_end>>8);
- Lcd_WriteData(y_end);
- Lcd_WriteCmd(LCD_RAMWR);
- }
- void set_background(u16 color)
- {
- u8 i,j;
- set_frame_size(0,0xA0,0x00,0x80);
- TFT_DC_Set;
- TFT_CS_Reset;
- for(i = 0; i < 128; i ++)
- {
- for(j = 0; j < 160; j ++)
- {
- bflb_spi_poll_send(spi0,color >> 8);
- bflb_spi_poll_send(spi0,color);
- }
- }
- TFT_CS_Set;
- }
- void Lcd_WriteCmd(u8 data)
- {
- TFT_DC_Reset;
- TFT_CS_Reset;
- bflb_spi_poll_send(spi0,data);
- TFT_CS_Set;
- }
- void Lcd_WriteData(u8 data)
- {
- TFT_DC_Set;
- TFT_CS_Reset;
- bflb_spi_poll_send(spi0,data);
- TFT_CS_Set;
- }
- void Lcd_reset()
- {
- TFT_RES_Set;
- bflb_mtimer_delay_ms(60);
- TFT_RES_Reset;
- bflb_mtimer_delay_ms(120);
- TFT_RES_Set;
- bflb_mtimer_delay_ms(60);
- }
- void Lcd_init()
- {
- spi_init();
- Lcd_reset();
- TFT_BLK_Set;
- bflb_mtimer_delay_ms(60);
- Lcd_WriteCmd(0x11);//Sleep exit
- bflb_mtimer_delay_ms(120);
-
- //ST7735R Frame Rate
- Lcd_WriteCmd(0xB1);
- Lcd_WriteData(0x01);
- Lcd_WriteData(0x2C);
- Lcd_WriteData(0x2D);
- Lcd_WriteCmd(0xB2);
- Lcd_WriteData(0x01);
- Lcd_WriteData(0x2C);
- Lcd_WriteData(0x2D);
- Lcd_WriteCmd(0xB3);
- Lcd_WriteData(0x01);
- Lcd_WriteData(0x2C);
- Lcd_WriteData(0x2D);
- Lcd_WriteData(0x01);
- Lcd_WriteData(0x2C);
- Lcd_WriteData(0x2D);
- Lcd_WriteCmd(0xB4); //Column inversion
- Lcd_WriteData(0x07);
-
- //ST7735R Power Sequence
- Lcd_WriteCmd(0xC0);
- Lcd_WriteData(0xA2);
- Lcd_WriteData(0x02);
- Lcd_WriteData(0x84);
- Lcd_WriteCmd(0xC1);
- Lcd_WriteData(0xC5);
- Lcd_WriteCmd(0xC2);
- Lcd_WriteData(0x0A);
- Lcd_WriteData(0x00);
- Lcd_WriteCmd(0xC3);
- Lcd_WriteData(0x8A);
- Lcd_WriteData(0x2A);
- Lcd_WriteCmd(0xC4);
- Lcd_WriteData(0x8A);
- Lcd_WriteData(0xEE);
- Lcd_WriteCmd(0xC5); //VCOM
- Lcd_WriteData(0x0E);
- Lcd_WriteCmd(0x36); //MX, MY, RGB mode
- Lcd_WriteData(0xC0);
-
- //ST7735R Gamma Sequence
- Lcd_WriteCmd(0xe0);
- Lcd_WriteData(0x0f);
- Lcd_WriteData(0x1a);
- Lcd_WriteData(0x0f);
- Lcd_WriteData(0x18);
- Lcd_WriteData(0x2f);
- Lcd_WriteData(0x28);
- Lcd_WriteData(0x20);
- Lcd_WriteData(0x22);
- Lcd_WriteData(0x1f);
- Lcd_WriteData(0x1b);
- Lcd_WriteData(0x23);
- Lcd_WriteData(0x37);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x07);
- Lcd_WriteData(0x02);
- Lcd_WriteData(0x10);
- Lcd_WriteCmd(0xe1);
- Lcd_WriteData(0x0f);
- Lcd_WriteData(0x1b);
- Lcd_WriteData(0x0f);
- Lcd_WriteData(0x17);
- Lcd_WriteData(0x33);
- Lcd_WriteData(0x2c);
- Lcd_WriteData(0x29);
- Lcd_WriteData(0x2e);
- Lcd_WriteData(0x30);
- Lcd_WriteData(0x30);
- Lcd_WriteData(0x39);
- Lcd_WriteData(0x3f);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x07);
- Lcd_WriteData(0x03);
- Lcd_WriteData(0x10);
- Lcd_WriteCmd(0x2a);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x7f);
- Lcd_WriteCmd(0x2b);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x9f);
-
- Lcd_WriteCmd(0xF0); //Enable test command
- Lcd_WriteData(0x01);
- Lcd_WriteCmd(0xF6); //Disable ram power save mode
- Lcd_WriteData(0x00);
-
- Lcd_WriteCmd(0x3A); //65k mode
- Lcd_WriteData(0x05);
-
- Lcd_WriteCmd(0x29);//Display on
- }
- int main(void)
- {
- int i;
- board_init();
- Lcd_init();
- set_scan_direction (0xA0);
- set_background(0x0000);
- Show_Ch_GBK16(0,0,0xffff,0x0000,"Hello Word!");
- Show_Ch_GBK16(0,20,0xffff,0x0000,"感谢安信可");
- Show_Ch_GBK16(0,40,0xffff,0x0000,"赠送开发板!");
- while (1)
- {
- }
- return 0;
- }
复制代码按照上文进行编译,烧录,杜邦线接线图如下:
运行成功
完结撒花!!!! B站视频链接:【【祖传点灯】安信可赠送核心板】 https://www.bilibili.com/video/B ... 4ba122b163c354a4880
参考链接: 【LCD】使用M61-32s 驱动 SPI1.3寸屏幕 - 小安派S1&M61教程合集 - 物联网开发者社区-安信可论坛 - Powered by Discuz! (ai-thinker.com)
零基础搭建小安派Windows 开发环境 - 小安派S1&M61教程合集 - 物联网开发者社区-安信可论坛 - Powered by Discuz! (ai-thinker.com)
【祖传点灯】安信可Ai-M61-32S环境搭建&点灯 - 板子申请专区 - 物联网开发者社区-安信可论坛 - Powered by Discuz! (ai-thinker.com) |