【MM32F5270开发板试用】+ TFTLCD IO口方式驱动
本篇文章来自极术社区与灵动组织的MM32F5270开发板评测活动,更多开发板试用活动请关注极术社区网站。作者:小会
测试下使用开发板IO口方式驱动16位总线TFTLCD。
一、电路图
开发板上LCD接口部分电路图
转接板
硬件接口设计中间转接板,将开发板的接口定义转换成显示屏模块的接口。!
二、代码
st7789.c
#include "board_init.h"#include "hal_gpio.h"#include "hal_rcc.h"#include "st7789s.h"#include "delay.h"#include "font.h"uint16_t POINT_COLOR=0x0000; //»±ÊÑÕÉ«uint16_t BACK_COLOR=0xFFFF; //±³¾°É« _lcd_dev lcddev;static void ST7789_Reset(void){ LCD_SetRst(); delay_ms(1); LCD_ClrRst(); delay_ms(10); // Delayms 10ms // This delay time is necessary LCD_SetRst(); delay_ms(120); // Delayms 120 ms }void ST7789_Gpio_Writedat(uint16_t dat){ uint16_t temp_rpd, rpd; uint16_t temp_rpe, rpe; temp_rpd=GPIO_ReadOutData(GPIOD); rpd=((dat>>5)&0x700) | ((dat<>2)&0x03); temp_rpd= (temp_rpd&(~0xc703))|rpd; GPIO_WriteBits(GPIOD,temp_rpd); //printf("rpd=%04x\r\n",rpd); temp_rpe=temp_rpd=GPIO_ReadOutData(GPIOE); rpe=(dat<>8); ST7789_WriteData(xStart); ST7789_WriteData(xEnd>>8); ST7789_WriteData(xEnd); ST7789_WriteCommand(0x2b);ST7789_WriteData(yStart>>8); ST7789_WriteData(yStart); ST7789_WriteData(yEnd>>8); ST7789_WriteData(yEnd); ST7789_WriteCommand(0x2c); }void Lcd_SetBox1(uint16_t xStart, uint16_t xEnd, uint16_t yStart, uint16_t yEnd){ ST7789_WriteCommand(0x2a);ST7789_WriteData(xStart>>8); ST7789_WriteData(xStart); ST7789_WriteData(xEnd>>8); ST7789_WriteData(xEnd); ST7789_WriteCommand(0x2b);ST7789_WriteData(yStart>>8); ST7789_WriteData(yStart); ST7789_WriteData(yEnd>>8); ST7789_WriteData(yEnd); ST7789_WriteCommand(0x2c); }void LCD_WriteOneDot(uint16_t color){ ST7789_WriteData(color);}void LCD_Clear(uint16_t Color){ uint32_t i; Lcd_SetBox(0,0,320,240); for(i=0;i"~"//size:×ÖÌå´óС 12/16/24//mode:µþ¼Ó·½Ê½(1)»¹ÊǷǵþ¼Ó·½Ê½(0)void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t num, uint8_t size, uint8_t mode){ uint8_t temp,t1,t; uint8_t y0=y; uint8_t csize=(size/8+((size%8)?1:0))*(size/2); //µÃµ½×ÖÌåÒ»¸ö×Ö·û¶ÔÓ¦µãÕó¼¯ËùÕ¼µÄ×Ö½ÚÊý num=num-' ';//µÃµ½Æ«ÒƺóµÄÖµ£¨ASCII×Ö¿âÊÇ´Ó¿Õ¸ñ¿ªÊ¼È¡Ä££¬ËùÒÔ-' '¾ÍÊǶÔÓ¦×Ö·ûµÄ×ֿ⣩ for(t=0;t<csize;t++) { if(size==12)temp=asc2_1206[num][t]; //µ÷ÓÃ1206×ÖÌå else if(size==16)temp=asc2_1608[num][t]; //µ÷ÓÃ1608×ÖÌå else if(size==24)temp=asc2_2412[num][t]; //µ÷ÓÃ2412×ÖÌå else return; //ûÓеÄ×Ö¿â for(t1=0;t1<8;t1++) {if(temp&0x80)ST7789_SetPoint(x,y,POINT_COLOR); else if(mode==0)ST7789_SetPoint(x,y,BACK_COLOR); temp<=lcddev.height)return; //³¬ÇøÓòÁË if((y-y0)==size) { y=y0; x++; if(x>=lcddev.width)return; //³¬ÇøÓòÁË break; } } }} //ÏÔʾ×Ö·û´®//x,y:Æðµã×ø±ê//width,height:ÇøÓò´óС //size:×ÖÌå´óС//*p:×Ö·û´®ÆðʼµØÖ· void LCD_ShowString(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t size, uint8_t *p){ uint8_t x0=x; width+=x; height+=y; while((*p=' '))//ÅжÏÊDz»ÊÇ·Ç·¨×Ö·û! { if(x>=width){x=x0;y+=size;} if(y>=height)break;//Í˳ö LCD_ShowChar(x,y,*p,size,0); x+=size/2; p++; } }
st7789.h
#ifndef __ST7789S_H__#define __ST7789S_H__#include "board_init.h"typedef struct { uint16_t width; uint16_t height; uint16_t id; uint8_t dir; uint16_t wramcmd; uint16_t setxcmd; uint16_t setycmd; }_lcd_dev; extern _lcd_dev lcddev;extern uint16_t POINT_COLOR; extern uint16_t BACK_COLOR; #define BLACK 0x0000#define BLUE 0x001F#define RED 0xF800#define GREEN 0x07E0#define CYAN 0x07FF#define MAGENTA 0xF81F#define YELLOW 0xFFE0#define WHITE 0xFFFF #define BACKCOLOR 0xFFFF #define WORDCOLOR 0x0000/* Ƭѡ */#define LCD_SetCs() {GPIO_WriteBit(GPIOG, GPIO_PIN_12, 1u);}#define LCD_ClrCs() {GPIO_WriteBit(GPIOG, GPIO_PIN_12, 0u);}/* ¸´Î» */#define LCD_SetRst() {GPIO_WriteBit(GPIOG, GPIO_PIN_11, 1);}#define LCD_ClrRst() {GPIO_WriteBit(GPIOG, GPIO_PIN_11, 0);}/* /RD */#define LCD_SetRd() {GPIO_WriteBit(GPIOD, GPIO_PIN_4, 1);}#define LCD_ClrRd() {GPIO_WriteBit(GPIOD, GPIO_PIN_4, 0);}/* /WR */#define LCD_SetWr() {GPIO_WriteBit(GPIOD, GPIO_PIN_5, 1);}#define LCD_ClrWr() {GPIO_WriteBit(GPIOD, GPIO_PIN_5, 0);}/* BLA */#define LCD_BLA_ON() {GPIO_WriteBit(GPIOE, GPIO_PIN_3, 1);}#define LCD_BLA_OFF() {GPIO_WriteBit(GPIOE, GPIO_PIN_3, 0);}/* RS */#define LCD_SetRs() {GPIO_WriteBit(GPIOE, GPIO_PIN_2, 1);}#define LCD_ClrRs() {GPIO_WriteBit(GPIOE, GPIO_PIN_2, 0);}void init_st7789s(void);void LCD_Clear(uint16_t Color);void LCD_ShowString(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t size, uint8_t *p);#endif
main.c
/* * Copyright 2021 MindMotion Microelectronics Co., Ltd. * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */#include "board_init.h"#include "hal_flexcan.h"#include "hal_gpio.h"#include "led.h"#include "key.h"#include "delay.h"#include "flexcan.h"#include "st7789s.h"int main(void){ BOARD_Init(); delay_init(); init_led(); //init_key(); //init_flexcan1(); init_st7789s(); POINT_COLOR=RED; LCD_Clear(WHITE); printf("\r\nmm32f5270 test.\r\n"); LCD_ShowString(30,40,210,24,24,"MM32F5270"); LCD_ShowString(30,70,200,16,16,"TFTLCD TEST"); LCD_ShowString(30,90,200,16,16,"ST7789"); LCD_ShowString(30,110,200,16,16,"2022/09/01"); LCD_ShowString(30,150,210,24,24,"https://aijishu.com"); while(1) { GPIO_WriteBit(BOARD_LED0_GPIO_PORT, BOARD_LED0_GPIO_PIN, 1u); delay_ms(100); GPIO_WriteBit(BOARD_LED0_GPIO_PORT, BOARD_LED0_GPIO_PIN, 0u); delay_ms(100); }}
三、程序运行