博士
最后登录1970-1-1
在线时间 小时
注册时间2020-4-29
|
本帖最后由 Yuhailong 于 2020-7-10 10:21 编辑
挑战者F429的RGB屏幕显示例程只能从一个方向显示字符串,我研究了一下,改动了一些代码,现在可以设置四种方向显示字符串
1.首先写了一个画点的函数,可以从四种不同的方向画点
- /**
- * [url=home.php?mod=space&uid=41770]@brief[/url] 在屏幕上面画点
- * @param Xpos: 横坐标.
- * @param Ypos: 纵坐标.
- * @param mode:显示方向
- * @param color:显示的颜色
- * @retval None
- */
- void LCD_DrawSome(uint16_t Xpos, uint16_t Ypos, uint8_t mode,uint32_t color)
- {
- uint32_t videoMemory;
- switch(mode)
- {
- case 0:
- videoMemory = CurrentFrameBuffer + (LCD_PIXEL_WIDTH - Ypos -1)*2 + (Xpos * LCD_PIXEL_WIDTH*2);
- *(__IO uint16_t*) (videoMemory) = color;
- break;
- case 1:
- videoMemory = CurrentFrameBuffer + Xpos *2 + (Ypos * LCD_PIXEL_WIDTH*2);
- *(__IO uint16_t*) (videoMemory) = color;
- break;
- case 2:
- videoMemory =(CurrentFrameBuffer + 480*800*2) - ((Xpos + 1)*2 + (Ypos * LCD_PIXEL_WIDTH*2));
- *(__IO uint16_t*) (videoMemory) = color;
- break;
- case 3:
- videoMemory =CurrentFrameBuffer + (480*800*2 - (Xpos*2*LCD_PIXEL_WIDTH + (LCD_PIXEL_WIDTH - Ypos)*2));
- *(__IO uint16_t*) (videoMemory) = color;
- break;
- }
- }
复制代码 2.然后将画点函数和显示字符串的函数结合一下,改动如下:
- /**
- * @brief Displays a maximum of 20 char on the LCD.
- * @param Line: the Line where to display the character shape .
- * This parameter can be one of the following values:
- * @arg Linex: where x can be 0..9
- * @param *ptr: pointer to string to display on LCD.
- * @retval None
- */
- void LCD_DisplayStringLine(uint16_t Line, uint8_t *ptr)
- {
- uint16_t refcolumn = 0;
- /* Send the string character by character on lCD */
- while ((refcolumn < LCD_PIXEL_WIDTH) && ((*ptr != 0) & (((refcolumn + LCD_Currentfonts->Width) & 0xFFFF) >= LCD_Currentfonts->Width)))
- {
- /* Display one character on LCD */
- LCD_DisplayChar(refcolumn,Line , *ptr);
- /* Decrement the column position by width */
- refcolumn += LCD_Currentfonts->Width;
- /* Point on the next character */
- ptr++;
- }
- }
复制代码- /**
- * @brief Draws a character on LCD.
- * @param Xpos: the Line where to display the character shape.
- * @param Ypos: start column address.
- * @param c: pointer to the character data.
- * @retval None
- */
- void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, const uint16_t *c)
- {
- uint32_t index = 0, counter = 0, xpos =0;
- uint32_t Xaddress = 0;
- xpos = Xpos;;
- Xaddress += Ypos ;
- for(index = 0; index < LCD_Currentfonts->Height; index++)
- {
- Xpos = xpos;
- for(counter = 0; counter < LCD_Currentfonts->Width; counter++)
- {
- if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> counter)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
- (((c[index] & (0x1 << counter)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
- {
- LCD_DrawSome(Xpos,Xaddress,SET_DIRECTION,CurrentBackColor);
- }
- else
- {
- LCD_DrawSome(Xpos,Xaddress,SET_DIRECTION,CurrentTextColor);
- }
- Xpos++;
- }
- Xaddress++;
- }
- }
复制代码 3.最后可以通过这个宏定义来设置显示方向
- //设置字符串显示方向,注意:超出屏幕的部分不会显示,
- #define SET_DIRECTION 0 //设置范围0-3,可以设置四种方向显示
复制代码 四种不同的显示效果如下:
#define SET_DIRECTION 0
#define SET_DIRECTION 1
#define SET_DIRECTION 2
#define SET_DIRECTION 3
最后附上源代码
19-LTDC—液晶显示英文(字库在内部FLASH).zip
(729.96 KB, 下载次数: 21)
|
|