SPI 简介及特点 具有全双工、半双工和单工模式的主从操作。 16位宽度,独立的发送和接收缓冲区。 8位或16位数据帧格式。 低位在前或高位在前的数据位顺序。 软件和硬件NSS管理。 硬件CRC计算、发送和校验。 发送和接收支持DMA模式。 支持SPI四线功能的主机模式(只有SPI5) 。 串行外设接口(Serial Peripheral Interface,缩写为SPI) 提供了基于SPI协议的数据发送和接 收功能, 可以工作于主机或从机模式。 SPI接口支持具有硬件CRC计算和校验的全双工和单工 模式。 SPI5还支持SPI四线主机模式。
开发环境&参考文档 Keil-MDK 5.27.1.0 Windows11 固件库-GD32F4xx_Firmware_Library_V3.0.2 GD32F427xx_Datasheet_Rev1.2 GD32F4xx_User_Manual_Rev2.7_CN GD32F4xx 固件库使用指南_V1.0 代码部分 SPI 初始化配置 spi.h 文件 #ifndef _SPI_H_ #define _SPI_H_ #include “gd32f4xx.h” void SPI_Init(void); #endif spi.c 文件 #include “spi.h” void SPI_Init(void) { spi_parameter_struct spi_init_struct; rcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_GPIOD); rcu_periph_clock_enable(RCU_SPI0); /* GPIOC config, PC10(LCD_SPI_CLK), PC11(SPI0_MISO), PC12(LCD_SPI_MOSI) */ gpio_af_set(GPIOB, GPIO_AF_5,GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5); gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5); gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5); /* GPIOC config */ gpio_mode_set(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); gpio_bit_reset(GPIOD,GPIO_PIN_1); gpio_bit_set(GPIOD,GPIO_PIN_3); gpio_mode_set(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_0); gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0); gpio_bit_set(GPIOD,GPIO_PIN_0); /* SPI0 parameter config */ spi_init_struct.trans_mode = SPI_TRANSMODE_FULLDUPLEX; spi_init_struct.device_mode = SPI_MASTER; spi_init_struct.frame_size = SPI_FRAMESIZE_8BIT; spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_1EDGE; spi_init_struct.nss = SPI_NSS_SOFT; spi_init_struct.prescale = SPI_PSC_2; spi_init_struct.endian = SPI_ENDIAN_MSB; spi_init(SPI0, &spi_init_struct); /* set crc polynomial */ spi_crc_polynomial_set(SPI0, 7); spi_enable(SPI0); } LCD 初始化函数 lcd.h 文件 #ifndef __LCD_H #define __LCD_H #include “stdint.h” #define USE_HORIZONTAL 2 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏 //画笔颜色 #define WHITE 0xFFFF #define BLACK 0x0000 #define BLUE 0x001F #define BRED 0XF81F #define GRED 0XFFE0 #define GBLUE 0X07FF #define RED 0xF800 #define MAGENTA 0xF81F #define GREEN 0x07E0 #define CYAN 0x7FFF #define YELLOW 0xFFE0 #define BROWN 0XBC40 //棕色 #define BRRED 0XFC07 //棕红色 #define GRAY 0X8430 //灰色 //GUI颜色 #define DARKBLUE 0X01CF //深蓝色 #define LIGHTBLUE 0X7D7C //浅蓝色 #define GRAYBLUE 0X5458 //灰蓝色 //以上三色为PANEL的颜色 #define LIGHTGREEN 0X841F //浅绿色 #define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色 #define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色) #define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色) #if USE_HORIZONTAL==0||USE_HORIZONTAL==1 #define LCD_W 80 #define LCD_H 160 #else #define LCD_W 160 #define LCD_H 80 #endif #define OLED_CMD 0 //写命令 #define OLED_DATA 1 //写数据 extern uint16_t BACK_COLOR; //背景色 /* tft cs */ #define LCD_CS_SET ((uint32_t)(GPIO_BOP(GPIOD) = GPIO_PIN_1)) #define LCD_CS_CLR ((uint32_t)(GPIO_BC(GPIOD) = GPIO_PIN_1)) /*tft rs/dc */ #define LCD_RS_SET ((uint32_t)(GPIO_BOP(GPIOD) = GPIO_PIN_2)) #define LCD_RS_CLR ((uint32_t)(GPIO_BC(GPIOD) = GPIO_PIN_2)) /*tft rst */ #define LCD_RST_SET ((uint32_t)(GPIO_BOP(GPIOD) = GPIO_PIN_3)) #define LCD_RST_CLR ((uint32_t)(GPIO_BC(GPIOD) = GPIO_PIN_3)) void LCD_WR_DATA8(uint8_t data); void LCD_WR_DATA(uint16_t data); void LCD_WR_REG(uint8_t data); void LCD_Address_Set(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2); void LCD_Init(void); void LCD_Clear(uint16_t Color); void LCD_ShowChinese(uint16_t x,uint16_t y,uint8_t index,uint8_t size,uint16_t color); void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color); void LCD_DrawPoint_big(uint16_t x,uint16_t y,uint16_t color); void LCD_Fill(uint16_t xsta,uint16_t ysta,uint16_t xend,uint16_t yend,uint16_t color); void LCD_DrawLine(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color); void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,uint16_t color); void Draw_Circle(uint16_t x0,uint16_t y0,uint8_t r,uint16_t color); void LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint8_t mode,uint16_t color); void LCD_ShowString(uint16_t x,uint16_t y,const uint8_t *p,uint16_t color); uint32_t mypow(uint8_t m,uint8_t n); void LCD_ShowNum(uint16_t x,uint16_t y,uint16_t num,uint8_t len,uint16_t color); void LCD_ShowNum1(uint16_t x,uint16_t y,float num,uint8_t len,uint16_t color); void LCD_ShowPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2); #endif lcd.c 文件 #include “lcd.h” #include “oledfont.h” #include “bmp.h” #include “spi.h” #include “systick.h” uint16_t BACK_COLOR=LGRAY; //背景色 #define OLED_Dly 5 void OLED_Delay(uint32_t Num) { while(Num) { Num--; } } /****************************************************************************** 函数说明:LCD串行数据写入函数 入口数据:dat 要写入的串行数据 返回值: 无 ******************************************************************************/ static uint8_t spi_write_byte(uint32_t spi_periph,uint8_t byte) { while(RESET == (SPI_STAT(spi_periph)&SPI_FLAG_TBE)); SPI_DATA(spi_periph) = byte; while(RESET == (SPI_STAT(spi_periph)&SPI_FLAG_RBNE)); return(SPI_DATA(spi_periph)); } /****************************************************************************** 函数说明:LCD写入数据 入口数据:dat 写入的数据 返回值: 无 ******************************************************************************/ void LCD_WR_DATA8(uint8_t data) { LCD_RS_SET; spi_write_byte(SPI0,data); } /****************************************************************************** 函数说明:LCD写入数据 入口数据:dat 写入的数据 返回值: 无 ******************************************************************************/ void LCD_WR_DATA(uint16_t data) { LCD_WR_DATA8(data》》8); LCD_WR_DATA8(data); } /****************************************************************************** 函数说明:LCD写入命令 入口数据:dat 写入的命令 返回值: 无 ******************************************************************************/ void LCD_WR_REG(uint8_t data) { LCD_RS_CLR; spi_write_byte(SPI0,data); } /****************************************************************************** 函数说明:设置起始和结束地址 入口数据:x1,x2 设置列的起始和结束地址 y1,y2 设置行的起始和结束地址 返回值: 无 ******************************************************************************/ void LCD_Address_Set(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2) { if(USE_HORIZONTAL==0) { LCD_WR_REG(0x2a);//列地址设置 LCD_WR_DATA(x1+26); LCD_WR_DATA(x2+26); LCD_WR_REG(0x2b);//行地址设置 LCD_WR_DATA(y1+1); LCD_WR_DATA(y2+1); LCD_WR_REG(0x2c);//储存器写 } else if(USE_HORIZONTAL==1) { LCD_WR_REG(0x2a);//列地址设置 LCD_WR_DATA(x1+26); LCD_WR_DATA(x2+26); LCD_WR_REG(0x2b);//行地址设置 LCD_WR_DATA(y1+1); LCD_WR_DATA(y2+1); LCD_WR_REG(0x2c);//储存器写 } else if(USE_HORIZONTAL==2) { LCD_WR_REG(0x2a);//列地址设置 LCD_WR_DATA(x1+1); LCD_WR_DATA(x2+1); LCD_WR_REG(0x2b);//行地址设置 LCD_WR_DATA(y1+26); LCD_WR_DATA(y2+26); LCD_WR_REG(0x2c);//储存器写 } else { LCD_WR_REG(0x2a);//列地址设置 LCD_WR_DATA(x1+1); LCD_WR_DATA(x2+1); LCD_WR_REG(0x2b);//行地址设置 LCD_WR_DATA(y1+26); LCD_WR_DATA(y2+26); LCD_WR_REG(0x2c);//储存器写 } } /****************************************************************************** 函数说明:LCD初始化函数 入口数据:无 返回值: 无 ******************************************************************************/ void LCD_Init(void) { // HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET); // HAL_Delay(200); // HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_SET); // HAL_Delay(200); LCD_WR_REG(0x11); delay_1ms(100); LCD_WR_REG(0x21); LCD_WR_REG(0xB1); LCD_WR_DATA8(0x05); LCD_WR_DATA8(0x3A); LCD_WR_DATA8(0x3A); LCD_WR_REG(0xB2); LCD_WR_DATA8(0x05); LCD_WR_DATA8(0x3A); LCD_WR_DATA8(0x3A); LCD_WR_REG(0xB3); LCD_WR_DATA8(0x05); LCD_WR_DATA8(0x3A); LCD_WR_DATA8(0x3A); LCD_WR_DATA8(0x05); LCD_WR_DATA8(0x3A); LCD_WR_DATA8(0x3A); LCD_WR_REG(0xB4); LCD_WR_DATA8(0x03); LCD_WR_REG(0xC0); LCD_WR_DATA8(0x62); LCD_WR_DATA8(0x02); LCD_WR_DATA8(0x04); LCD_WR_REG(0xC1); LCD_WR_DATA8(0xC0); LCD_WR_REG(0xC2); LCD_WR_DATA8(0x0D); LCD_WR_DATA8(0x00); LCD_WR_REG(0xC3); LCD_WR_DATA8(0x8D); LCD_WR_DATA8(0x6A); LCD_WR_REG(0xC4); LCD_WR_DATA8(0x8D); LCD_WR_DATA8(0xEE); LCD_WR_REG(0xC5); /*VCOM*/ LCD_WR_DATA8(0x0E); LCD_WR_REG(0xE0); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x02); LCD_WR_DATA8(0x03); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x02); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x0A); LCD_WR_DATA8(0x12); LCD_WR_DATA8(0x27); LCD_WR_DATA8(0x37); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x0D); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x10); LCD_WR_REG(0xE1); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x03); LCD_WR_DATA8(0x03); LCD_WR_DATA8(0x0F); LCD_WR_DATA8(0x06); LCD_WR_DATA8(0x02); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x0A); LCD_WR_DATA8(0x13); LCD_WR_DATA8(0x26); LCD_WR_DATA8(0x36); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x0D); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x10); LCD_WR_REG(0x3A); LCD_WR_DATA8(0x05); LCD_WR_REG(0x36); if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x08); else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC8); else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x78); else LCD_WR_DATA8(0xA8); LCD_WR_REG(0x29); } /****************************************************************************** 函数说明:LCD清屏函数 入口数据:无 返回值: 无 ******************************************************************************/ void LCD_Clear(uint16_t Color) { uint16_t i,j; LCD_Address_Set(0,0,LCD_W-1,LCD_H-1); for(i=0;i《LCD_W;i++) { for (j=0;j《LCD_H;j++) { LCD_WR_DATA(Color); } } } /****************************************************************************** 函数说明:LCD显示汉字 入口数据:x,y 起始坐标 index 汉字的序号 size 字号 返回值: 无 ******************************************************************************/ void LCD_ShowChinese(uint16_t x,uint16_t y,uint8_t index,uint8_t size,uint16_t color) { uint8_t i,j; uint8_t *temp,size1; if(size==16){temp=Hzk16;}//选择字号 if(size==32){temp=Hzk32;} LCD_Address_Set(x,y,x+size-1,y+size-1); //设置一个汉字的区域 size1=size*size/8;//一个汉字所占的字节 temp+=index*size1;//写入的起始位置 for(j=0;j《size1;j++) { for(i=0;i《8;i++) { if((*temp&(1《《i))!=0)//从数据的低位开始读 { LCD_WR_DATA(color);//点亮 } else { LCD_WR_DATA(BACK_COLOR);//不点亮 } } temp++; } } /****************************************************************************** 函数说明:LCD显示汉字 入口数据:x,y 起始坐标 返回值: 无 ******************************************************************************/ void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color) { LCD_Address_Set(x,y,x,y);//设置光标位置 LCD_WR_DATA(color); } /****************************************************************************** 函数说明:LCD画一个大的点 入口数据:x,y 起始坐标 返回值: 无 ******************************************************************************/ void LCD_DrawPoint_big(uint16_t x,uint16_t y,uint16_t color) { LCD_Fill(x-1,y-1,x+1,y+1,color); } /****************************************************************************** 函数说明:在指定区域填充颜色 入口数据:xsta,ysta 起始坐标 xend,yend 终止坐标 返回值: 无 ******************************************************************************/ void LCD_Fill(uint16_t xsta,uint16_t ysta,uint16_t xend,uint16_t yend,uint16_t color) { uint16_t i,j; LCD_Address_Set(xsta,ysta,xend,yend); //设置光标位置 for(i=ysta;i《=yend;i++) { for(j=xsta;j《=xend;j++)LCD_WR_DATA(color);//设置光标位置 } } /****************************************************************************** 函数说明:画线 入口数据:x1,y1 起始坐标 x2,y2 终止坐标 返回值: 无 ******************************************************************************/ void LCD_DrawLine(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color) { uint16_t t; int xerr=0,yerr=0,delta_x,delta_y,distance; int incx,incy,uRow,uCol; delta_x=x2-x1; //计算坐标增量 delta_y=y2-y1; uRow=x1;//画线起点坐标 uCol=y1; if(delta_x》0)incx=1; //设置单步方向 else if (delta_x==0)incx=0;//垂直线 else {incx=-1;delta_x=-delta_x;} if(delta_y》0)incy=1; else if (delta_y==0)incy=0;//水平线 else {incy=-1;delta_y=-delta_x;} if(delta_x》delta_y)distance=delta_x; //选取基本增量坐标轴 else distance=delta_y; for(t=0;t《distance+1;t++) { LCD_DrawPoint(uRow,uCol,color);//画点 xerr+=delta_x; yerr+=delta_y; if(xerr》distance) { xerr-=distance; uRow+=incx; } if(yerr》distance) { yerr-=distance; uCol+=incy; } } } /****************************************************************************** 函数说明:画矩形 入口数据:x1,y1 起始坐标 x2,y2 终止坐标 返回值: 无 ******************************************************************************/ void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,uint16_t color) { LCD_DrawLine(x1,y1,x2,y1,color); LCD_DrawLine(x1,y1,x1,y2,color); LCD_DrawLine(x1,y2,x2,y2,color); LCD_DrawLine(x2,y1,x2,y2,color); } /****************************************************************************** 函数说明:画圆 入口数据:x0,y0 圆心坐标 r 半径 返回值: 无 ******************************************************************************/ void Draw_Circle(uint16_t x0,uint16_t y0,uint8_t r,uint16_t color) { int a,b; a=0;b=r; while(a《=b) { LCD_DrawPoint(x0-b,y0-a,color); //3 LCD_DrawPoint(x0+b,y0-a,color); //0 LCD_DrawPoint(x0-a,y0+b,color); //1 LCD_DrawPoint(x0-a,y0-b,color); //2 LCD_DrawPoint(x0+b,y0+a,color); //4 LCD_DrawPoint(x0+a,y0-b,color); //5 LCD_DrawPoint(x0+a,y0+b,color); //6 LCD_DrawPoint(x0-b,y0+a,color); //7 a++; if((a*a+b*b)》(r*r))//判断要画的点是否过远 { b--; } } } /****************************************************************************** 函数说明:显示字符 入口数据:x,y 起点坐标 num 要显示的字符 mode 1叠加方式 0非叠加方式 返回值: 无 ******************************************************************************/ void LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint8_t mode,uint16_t color) { uint8_t temp; uint8_t pos,t; uint16_t x0=x; if(x》LCD_W-16||y》LCD_H-16)return; //设置窗口 num=num-‘ ’;//得到偏移后的值 LCD_Address_Set(x,y,x+8-1,y+16-1); //设置光标位置 if(!mode) //非叠加方式 { for(pos=0;pos《16;pos++) { temp=asc2_1608[(uint16_t)num*16+pos]; //调用1608字体 for(t=0;t《8;t++) { if(temp&0x01)LCD_WR_DATA(color); else LCD_WR_DATA(BACK_COLOR); temp》》=1; x++; } x=x0; y++; } }else//叠加方式 { for(pos=0;pos《16;pos++) { temp=asc2_1608[(uint16_t)num*16+pos]; //调用1608字体 for(t=0;t《8;t++) { if(temp&0x01)LCD_DrawPoint(x+t,y+pos,color);//画一个点 temp》》=1; } } } } /****************************************************************************** 函数说明:显示字符串 入口数据:x,y 起点坐标 *p 字符串起始地址 返回值: 无 ******************************************************************************/ void LCD_ShowString(uint16_t x,uint16_t y,const uint8_t *p,uint16_t color) { while(*p!=‘ ’) { if(x》LCD_W-16){x=0;y+=16;} if(y》LCD_H-16){y=x=0;LCD_Clear(RED);} LCD_ShowChar(x,y,*p,0,color); x+=8; p++; } } /****************************************************************************** 函数说明:显示数字 入口数据:m底数,n指数 返回值: 无 ******************************************************************************/ uint32_t mypow(uint8_t m,uint8_t n) { uint32_t result=1; while(n--)result*=m; return result; } /****************************************************************************** 函数说明:显示数字 入口数据:x,y 起点坐标 num 要显示的数字 len 要显示的数字个数 返回值: 无 ******************************************************************************/ void LCD_ShowNum(uint16_t x,uint16_t y,uint16_t num,uint8_t len,uint16_t color) { uint8_t t,temp; uint8_t enshow=0; for(t=0;t《len;t++) { temp=(num/mypow(10,len-t-1))%10; if(enshow==0&&t《(len-1)) { if(temp==0) { LCD_ShowChar(x+8*t,y,‘ ’,0,color); continue; }else enshow=1; } LCD_ShowChar(x+8*t,y,temp+48,0,color); } } /****************************************************************************** 函数说明:显示小数 入口数据:x,y 起点坐标 num 要显示的小数 len 要显示的数字个数 返回值: 无 ******************************************************************************/ void LCD_ShowNum1(uint16_t x,uint16_t y,float num,uint8_t len,uint16_t color) { uint8_t t,temp; uint16_t num1; num1=num*100; for(t=0;t《len;t++) { temp=(num1/mypow(10,len-t-1))%10; if(t==(len-2)) { LCD_ShowChar(x+8*(len-2),y,‘。’,0,color); t++; len+=1; } LCD_ShowChar(x+8*t,y,temp+48,0,color); } } /****************************************************************************** 函数说明:显示40x40图片 入口数据:x,y 起点坐标 返回值: 无 ******************************************************************************/ void LCD_ShowPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2) { int i; LCD_Address_Set(x1,y1,x2,y2); for(i=0;i《1600;i++) { LCD_WR_DATA8(image[i*2+1]); LCD_WR_DATA8(image[i*2]); } } 字库文件 oledfont.h 文件 $\color{red}{注意:不要遗漏该文件,或者自己制作字库!!!}$ #ifndef __OLEDFONT_H #define __OLEDFONT_H //常用ASCII表 //偏移量32 //ASCII字符集 //偏移量32 //大小:12*6 #include “stdint.h” /************************************6*8的点阵************************************/ /****************************************32*32的点阵************************************/ uint8_t Hzk32[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00, 0x00,0x70,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x60,0x00,0x00, 0x00,0x60,0x30,0x00,0x00,0xE0,0xFF,0x00,0xE0,0x7F,0xE0,0x01,0xE0,0x21,0xE0,0x00, 0x40,0x20,0x60,0x00,0xC0,0x20,0x60,0x00,0xC0,0xF8,0x73,0x00,0xC0,0x3E,0x30,0x00, 0x80,0x20,0x30,0x00,0x80,0x20,0x10,0x00,0x80,0x20,0x1E,0x00,0x80,0xFF,0x0F,0x00, 0x80,0x21,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x04, 0x00,0x60,0x00,0x04,0x00,0x60,0x00,0x0C,0x00,0xC0,0x01,0x0F,0x00,0x80,0xFF,0x07, 0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*“电”,0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x81,0xFF,0x00,0x00,0xFF,0x07,0x00, 0x00,0x03,0x00,0x00,0x00,0x03,0x07,0x00,0x00,0x03,0x0E,0x00,0x00,0x03,0x06,0x00, 0x00,0x03,0x06,0x00,0x00,0x03,0x06,0x00,0x00,0x03,0x06,0x00,0x00,0x01,0xFE,0x00, 0x80,0xE1,0x3F,0x00,0x80,0x01,0x06,0x00,0x80,0x01,0x46,0x00,0x80,0x00,0xC6,0x01, 0xC0,0x00,0x86,0x01,0xC0,0x00,0x06,0x01,0x60,0x00,0x06,0x00,0x60,0x00,0x06,0x0F, 0x30,0xC0,0xFF,0x1F,0x10,0xFF,0x03,0x00,0x08,0x00,0x00,0x00,0x04,0x00,0x00,0x00, 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*“压”,1*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00, 0x00,0x00,0x0E,0x00,0x00,0x00,0x0C,0x00,0xC0,0x00,0x08,0x00,0xC0,0x01,0x80,0x00, 0x80,0x03,0xF8,0x03,0x00,0xC0,0x3F,0x00,0x00,0xF0,0x03,0x00,0x00,0x00,0x07,0x00, 0x08,0x00,0x73,0x00,0x38,0x80,0xE1,0x00,0x30,0xC0,0xF0,0x01,0x20,0xE0,0x8F,0x01, 0x00,0xF0,0x01,0x00,0x00,0x31,0x10,0x00,0x80,0x00,0x60,0x00,0x80,0x10,0x63,0x00, 0xC0,0x70,0x23,0x00,0x40,0x30,0x22,0x00,0x60,0x30,0x22,0x20,0x60,0x30,0x22,0x20, 0x70,0x10,0x22,0x20,0x38,0x18,0x62,0x20,0x30,0x08,0xE3,0x30,0x20,0x0C,0xC2,0x3F, 0x00,0x03,0x00,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*“流”,2*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x1F,0x00,0x00,0xF0,0x0C,0xF0,0x03, 0x60,0x84,0x8F,0x03,0x60,0x86,0x81,0x03,0x60,0x02,0x81,0x01,0x60,0x06,0x81,0x01, 0x60,0x06,0x81,0x01,0x60,0x04,0x9F,0x01,0x60,0x0C,0x81,0x01,0x60,0x0F,0x81,0x01, 0x60,0x0E,0x81,0x01,0x60,0x08,0x81,0x01,0x60,0x00,0xBF,0x01,0x60,0x00,0x81,0x01, 0x60,0x00,0x81,0x01,0x60,0x00,0x81,0x01,0x60,0x00,0x81,0x01,0x60,0x00,0x81,0x1D, 0x60,0x00,0xFF,0x7F,0x60,0xFC,0x07,0x00,0x60,0x00,0x00,0x00,0x60,0x00,0x00,0x00, 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*“阻”,3*/}; const uint8_t asc2_1608[1520]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x18,0x18,0x00,0x00, 0x00,0x48,0x6C,0x24,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x24,0x24,0x24,0x7F,0x12,0x12,0x12,0x7F,0x12,0x12,0x12,0x00,0x00, 0x00,0x00,0x08,0x1C,0x2A,0x2A,0x0A,0x0C,0x18,0x28,0x28,0x2A,0x2A,0x1C,0x08,0x08, 0x00,0x00,0x00,0x22,0x25,0x15,0x15,0x15,0x2A,0x58,0x54,0x54,0x54,0x22,0x00,0x00, 0x00,0x00,0x00,0x0C,0x12,0x12,0x12,0x0A,0x76,0x25,0x29,0x11,0x91,0x6E,0x00,0x00, 0x00,0x06,0x06,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00, 0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00, 0x00,0x00,0x00,0x00,0x08,0x08,0x6B,0x1C,0x1C,0x6B,0x08,0x08,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x08,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x04,0x03, 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,0x06,0x06,0x00,0x00, 0x00,0x00,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x02,0x00, 0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00, 0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, 0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00, 0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00, 0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00, 0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00, 0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00, 0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00, 0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00, 0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x04, 0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00, 0x00,0x00,0x00,0x3C,0x42,0x42,0x46,0x40,0x20,0x10,0x10,0x00,0x18,0x18,0x00,0x00, 0x00,0x00,0x00,0x1C,0x22,0x5A,0x55,0x55,0x55,0x55,0x2D,0x42,0x22,0x1C,0x00,0x00, 0x00,0x00,0x00,0x08,0x08,0x18,0x14,0x14,0x24,0x3C,0x22,0x42,0x42,0xE7,0x00,0x00, 0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x1E,0x22,0x42,0x42,0x42,0x22,0x1F,0x00,0x00, 0x00,0x00,0x00,0x7C,0x42,0x42,0x01,0x01,0x01,0x01,0x01,0x42,0x22,0x1C,0x00,0x00, 0x00,0x00,0x00,0x1F,0x22,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1F,0x00,0x00, 0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x42,0x42,0x3F,0x00,0x00, 0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x02,0x02,0x07,0x00,0x00, 0x00,0x00,0x00,0x3C,0x22,0x22,0x01,0x01,0x01,0x71,0x21,0x22,0x22,0x1C,0x00,0x00, 0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00, 0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, 0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x11,0x0F, 0x00,0x00,0x00,0x77,0x22,0x12,0x0A,0x0E,0x0A,0x12,0x12,0x22,0x22,0x77,0x00,0x00, 0x00,0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x7F,0x00,0x00, 0x00,0x00,0x00,0x77,0x36,0x36,0x36,0x36,0x2A,0x2A,0x2A,0x2A,0x2A,0x6B,0x00,0x00, 0x00,0x00,0x00,0xE3,0x46,0x46,0x4A,0x4A,0x52,0x52,0x52,0x62,0x62,0x47,0x00,0x00, 0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x22,0x1C,0x00,0x00, 0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x3E,0x02,0x02,0x02,0x02,0x07,0x00,0x00, 0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x4D,0x53,0x32,0x1C,0x60,0x00, 0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x3E,0x12,0x12,0x22,0x22,0x42,0xC7,0x00,0x00, 0x00,0x00,0x00,0x7C,0x42,0x42,0x02,0x04,0x18,0x20,0x40,0x42,0x42,0x3E,0x00,0x00, 0x00,0x00,0x00,0x7F,0x49,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00, 0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00, 0x00,0x00,0x00,0xE7,0x42,0x42,0x22,0x24,0x24,0x14,0x14,0x18,0x08,0x08,0x00,0x00, 0x00,0x00,0x00,0x6B,0x49,0x49,0x49,0x49,0x55,0x55,0x36,0x22,0x22,0x22,0x00,0x00, 0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00, 0x00,0x00,0x00,0x77,0x22,0x22,0x14,0x14,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00, 0x00,0x00,0x00,0x7E,0x21,0x20,0x10,0x10,0x08,0x04,0x04,0x42,0x42,0x3F,0x00,0x00, 0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00, 0x00,0x00,0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x10,0x20,0x20,0x20,0x40,0x40, 0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00, 0x00,0x38,0x44,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,0xFF, 0x00,0x06,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x78,0x44,0x42,0x42,0xFC,0x00,0x00, 0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x26,0x1A,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x02,0x02,0x02,0x44,0x38,0x00,0x00, 0x00,0x00,0x00,0x60,0x40,0x40,0x40,0x78,0x44,0x42,0x42,0x42,0x64,0xD8,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x02,0x02,0x42,0x3C,0x00,0x00, 0x00,0x00,0x00,0xF0,0x88,0x08,0x08,0x7E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x22,0x22,0x1C,0x02,0x3C,0x42,0x42,0x3C, 0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00, 0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, 0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x1E, 0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x72,0x12,0x0A,0x16,0x12,0x22,0x77,0x00,0x00, 0x00,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x92,0x92,0x92,0x92,0x92,0xB7,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3B,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x26,0x42,0x42,0x42,0x22,0x1E,0x02,0x07, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x44,0x42,0x42,0x42,0x44,0x78,0x40,0xE0, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x4C,0x04,0x04,0x04,0x04,0x1F,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x42,0x02,0x3C,0x40,0x42,0x3E,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x3E,0x08,0x08,0x08,0x08,0x08,0x30,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x42,0x42,0x42,0x42,0x62,0xDC,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x08,0x08,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEB,0x49,0x49,0x55,0x55,0x22,0x22,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x18,0x08,0x08,0x07, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x22,0x10,0x08,0x08,0x44,0x7E,0x00,0x00, 0x00,0xC0,0x20,0x20,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x20,0x20,0xC0,0x00, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x00,0x06,0x08,0x08,0x08,0x08,0x08,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x06,0x00, 0x0C,0x32,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; uint8_t Hzk16[]={ 0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xFC,0x1F,0x84,0x10,0x84,0x10,0x84,0x10, 0x84,0x10,0x84,0x10,0xFC,0x1F,0x84,0x10,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,/*“中”,0*/ 0xF8,0x0F,0x08,0x08,0xF8,0x0F,0x08,0x08,0xF8,0x0F,0x80,0x00,0xFF,0x7F,0x00,0x00, 0xF8,0x0F,0x08,0x08,0x08,0x08,0xF8,0x0F,0x80,0x00,0x84,0x10,0xA2,0x20,0x40,0x00,/*“景”,1*/ 0x00,0x00,0xFE,0x3F,0x02,0x20,0xF2,0x27,0x02,0x20,0x02,0x20,0xFA,0x2F,0x22,0x21, 0x22,0x21,0x22,0x21,0x12,0x29,0x12,0x29,0x0A,0x2E,0x02,0x20,0xFE,0x3F,0x02,0x20,/*“园”,2*/ 0x80,0x00,0x80,0x00,0x80,0x00,0xFC,0x1F,0x84,0x10,0x84,0x10,0x84,0x10,0xFC,0x1F, 0x84,0x10,0x84,0x10,0x84,0x10,0xFC,0x1F,0x84,0x50,0x80,0x40,0x80,0x40,0x00,0x7F,/*“电”,3*/ 0x00,0x00,0xFE,0x1F,0x00,0x08,0x00,0x04,0x00,0x02,0x80,0x01,0x80,0x00,0xFF,0x7F, 0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xA0,0x00,0x40,0x00,/*“子”,4*/ 0x10,0x08,0xB8,0x08,0x0F,0x09,0x08,0x09,0x08,0x08,0xBF,0x08,0x08,0x09,0x1C,0x09, 0x2C,0x08,0x0A,0x78,0xCA,0x0F,0x09,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,/*“科”,5*/ 0x08,0x04,0x08,0x04,0x08,0x04,0xC8,0x7F,0x3F,0x04,0x08,0x04,0x08,0x04,0xA8,0x3F, 0x18,0x21,0x0C,0x11,0x0B,0x12,0x08,0x0A,0x08,0x04,0x08,0x0A,0x8A,0x11,0x64,0x60,/*“技”,6*/ }; #endif main.c 文件 #include “gd32f4xx.h” #include “systick.h” #include 《stdio.h》 #include “gpio.h” #include “uart.h” #include “spi.h” #include “lcd.h” int main(void) { systick_config(); //配置系统时钟 GPIO_Init(); USART_Init(); SPI_Init(); LCD_Init(); //初始化LCD LCD_Clear(WHITE); BACK_COLOR=LGRAY; USART_TransmitString(“这是一个串口测试rn”); printf(“串口重定向测试rn”); while(1) { gpio_bit_toggle(GPIOC, GPIO_PIN_6); //反转PC6 delay_1ms(100); LCD_ShowChinese(0,0,0,32,RED); //电 LCD_ShowChinese(32,0,1,32,RED); //压 LCD_ShowChinese(0,48,0,32,MAGENTA); //电 LCD_ShowChinese(31,48,2,32,MAGENTA); //流 LCD_ShowChinese(96,0,0,32,BLUE); //电 LCD_ShowChinese(128,0,3,32,BLUE); //阻 } }
显示效果 |