谢谢浦版,sprintf确实挺好用,不过,在使用中发现,因为我不知道输出的数组的准确长度,LCD_A24((i-2)*60,80,buffer,15,1,12);这句试了几个数字12-20好像都不对,导致显示乱码。又发现,LCD_H24((i-2)*60,102,buffer,15,1); 这样的语句却能正确显示数组的内容,不知何故。代码如下:
- //===========================================================
- // OLED 1.3" 彩色显示屏 240*240 实验程序
- // 驱动: ST7789
- // 基于: STC32G12K128芯片实验板编程 屠龙刀三核心实验板
- // 整理:编程: 浦晓明(浦江一水) For 国芯论坛 2024-06-28 PXM
- //===========================================================
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "STC32G.h"
- #include "LCD_7789.H"
- #include "PIC.H"
- #define u8 unsigned char
- char buffer[100];
- int i;
- unsigned cancode[4][6]=
- {
- {0x5f0,4,0xe4,0xff,0x00,0x00},
- {0x5f0,4,0x00,0x00,0x00,0x00},
- {0x3c0,4,0xa0,0xa0,0x03,0x00},
- {0x3c0,4,0x00,0x00,0x00,0x00},
- };
-
- u8 len =sizeof(cancode[0])/sizeof(cancode[0][0]);//二维数组列数 = sizeof(array[0])/sizeof(array[0][0]);
- //二维数组行数 = sizeof(array)/sizeof(array[0]);
-
-
- void Delay1ms(void) //@22.1184MHz
- { unsigned char data i, j;
- _nop_();_nop_();
- i = 22; j = 128;
- do
- { while (--j);
- } while (--i);
- }
- void Delayms(unsigned int count)
- { unsigned int i;
- for(i=0;i<count;i++)
- Delay1ms();
- }
- //主程序入口
- void main(void)
- {
- //IO端口初始化
- WTST = 0; //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快
- //EAXFR = 1; //扩展寄存器(XFR)访问使能
- CKCON = 0; //提高访问XRAM速度
- P0M1 = 0x00; P0M0 = 0x04; //设置为准双向口
- P1M1 = 0x00; P1M0 = 0x00; //设置为准双向口
- P2M1 = 0x00; P2M0 = 0x00; //设置为准双向口
- P3M1 = 0x00; P3M0 = 0x00; //设置为准双向口
- P4M1 = 0x00; P4M0 = 0x00; //设置为准双向口
- P5M1 = 0x00; P5M0 = 0x00; //设置为准双向口
- LCD_Init();
- LCD_CLS(1); //蓝色清屏
-
- while(1)
- {
-
- for(i=0;i<len;i++)
- {
- sprintf(buffer,"0x%02x",cancode[0][i]);
- if(i<1)
- {
- LCD_H24(0,50,buffer,15,1);
- }
- if(i>1)
- {
- LCD_A24((i-2)*60,80,buffer,15,1,12);
- LCD_H24((i-2)*60,102,buffer,15,1); //16点阵中西文混合显示字符串
- }
- }
-
- }
- }
-
复制代码 板子是屠龙刀板,屏是2.0寸ST7789,程序是在这个演示程序上略作改动。就图片中间那行,对应代码LCD_A24((i-2)*60,80,buffer,15,1,12);
|