LCD屏填充纯色

Posted suzkfly

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LCD屏填充纯色相关的知识,希望对你有一定的参考价值。

  废话不说,直接上代码:

  lcd.c

 1 #include "lcd.h"
 2 
 3 static int PEN_COLOR = LCD_RED;     /* 定义画笔(前景)颜色 */
 4 static int BK_COLOR  = LCD_BLACK;   /* 定义背景颜色 */
 5 
 6 /**
 7  * rief LCD初始化
 8  */
 9 void lcd_init (void)
10 {
11     GPICON = 0;
12     GPICON |= 0xaaaaaaaa;
13     GPJCON = 0;
14     GPJCON |= 0xaaaaaa;
15 
16     MIFPCON &= ~(0x1<<3);
17     SPCON &= ~0x3;
18     SPCON |= 0x1;
19 
20     VIDCON0 = (14<<6) | (0x1<<4) | (0x3);
21     VIDCON1 = (0x1<6) | (0x1<<5);
22 
23     VIDTCON0 = (1<<16) | (1<<8) | (9);
24     VIDTCON1 = (1<<16) | (1<<8) | (40);
25 
26     VIDTCON2 = ((LCD_HEIGHT - 1) << 11) | (LCD_WIDTH - 1);
27     WINCON0 = (0xb<<2) | (0x1);
28 
29     VIDOSD0A = 0;
30     VIDOSD0B = ((LCD_WIDTH - 1) << 11) | ((LCD_HEIGHT - 1));
31 
32     VIDOSD0C = LCD_WIDTH * LCD_HEIGHT;
33 
34     VIDW00ADD0B0 = SHOW_BUF;
35 }
36 
37 /**
38  * rief 设置画笔颜色
39  */
40 void set_pen_color (int color)
41 {
42     PEN_COLOR = color;
43 }
44 
45 /**
46  * rief 设置背景颜色
47  */
48 void set_bk_color (int color)
49 {
50     BK_COLOR = color;
51 }
52 
53 /**
54  * rief 绘制一个点
55  */
56 void lcd_draw_point (int x, int y)
57 {
58     *((int *)SHOW_BUF + x + y * LCD_WIDTH) = PEN_COLOR;
59 }
60 
61 void lcd_draw_bk (int x, int y)
62 {
63     *((int *)SHOW_BUF + x + y * LCD_WIDTH) = BK_COLOR;
64 }
65 
66 /**
67  * rief 清屏(填充背景色)
68  */
69 void lcd_clean (void)
70 {
71     int i, j, k;
72     for(i=0; i<LCD_HEIGHT; i++) {
73         for(j=0; j<LCD_WIDTH; j++) {
74             lcd_draw_bk(j, i);
75         }
76     }
77 }

  lcd.h

 1 #ifndef __LCD_H
 2 #define __LCD_H
 3 
 4 /* 定义寄存器地址 */
 5 #define GPICON  (*(unsigned int *)0x7F008100)
 6 #define SPCON   (*(unsigned int *)0x7F0081A0)
 7 #define MIFPCON (*(unsigned int *)0x7410800c)
 8 #define GPJCON  (*(unsigned int *)0x7F008120)
 9 
10 #define VIDCON0       (*(unsigned int *)0x77100000) 
11 #define VIDCON1       (*(unsigned int *)0x77100004) 
12 #define VIDCON2       (*(unsigned int *)0x77100008) 
13 #define VIDTCON0      (*(unsigned int *)0x77100010) 
14 #define VIDTCON1      (*(unsigned int *)0x77100014) 
15 #define VIDTCON2      (*(unsigned int *)0x77100018) 
16 #define WINCON0       (*(unsigned int *)0x77100020) 
17 #define WINCON1       (*(unsigned int *)0x77100024) 
18 #define WINCON2       (*(unsigned int *)0x77100028) 
19 #define WINCON3       (*(unsigned int *)0x7710002C) 
20 #define WINCON4       (*(unsigned int *)0x77100030) 
21 #define VIDOSD0A      (*(unsigned int *)0x77100040) 
22 #define VIDOSD0B      (*(unsigned int *)0x77100044) 
23 #define VIDOSD0C      (*(unsigned int *)0x77100048) 
24 #define VIDOSD1A      (*(unsigned int *)0x77100050) 
25 #define VIDOSD1B      (*(unsigned int *)0x77100054) 
26 #define VIDOSD1C      (*(unsigned int *)0x77100058) 
27 #define VIDW00ADD0B0  (*(unsigned int *)0x771000A0)
28 #define GPECON        (*(unsigned int *)0x7f008080)
29 #define GPEDAT        (*(unsigned int *)0x7f008084)
30 
31 #define LCD_WIDTH   480     /* 定义LCD宽度 */
32 #define LCD_HEIGHT  272     /* 定义LCD高度 */
33 
34 /* 定义显存地址 */
35 #define SHOW_BUF 0x54000000
36 
37 /* 定义常用颜色 */
38 #define COL(R,G,B)   ((R<<16) | (G<<8) | (B))
39 #define LCD_RED          COL(0xFF, 0, 0)
40 #define LCD_GREEN     COL(0, 0xFF, 0)
41 #define LCD_BLUE      COL(0, 0, 0xFF)
42 #define LCD_WHITE     COL(0xFF, 0xFF, 0xFF)
43 #define LCD_BLACK     COL(0, 0, 0)
44 
45 /******************************* 函数声明 **************************/
46 /**
47  * rief LCD初始化
48  */
49 extern void lcd_init (void);
50 
51 /**
52  * rief 设置画笔颜色
53  */
54 extern void set_pen_color (int color);
55 
56 /**
57  * rief 设置背景颜色
58  */
59 extern void set_bk_color (int color);
60 
61 /**
62  * rief 绘制一个点
63  */
64 extern void lcd_draw_point (int x, int y);
65 
66 /**
67  * rief 清屏(填充背景色)
68  */
69 extern void lcd_clean (void);
70 
71 #endif

  main.c

1 #include "lcd.h"
2 
3 int main(int argc, const char *argv[])
4 {
5     lcd_init();
6     set_bk_color(LCD_RED);
7     lcd_clean();
8     return 0;
9 }

  start.s

1 .section .text
2 .global _start
3 
4 _start:
5     b main
6     .end

 Makefile

 1 CC = arm-none-linux-gnueabi-
 2 objs = main.o lcd.o start.o
 3 
 4 test.bin:$(objs)
 5     $(CC)ld $(objs) -Ttext 50008000 -o test.elf
 6     $(CC)objcopy -O binary test.elf test.bin
 7 
 8 %.o:%.c
 9     $(CC)gcc -c $< -o [email protected]
10 
11 %.o:%.s
12     $(CC)gcc -c $< -o [email protected]
13 
14 clean:
15     rm *.o *.elf *.bin

 

以上是关于LCD屏填充纯色的主要内容,如果未能解决你的问题,请参考以下文章

Proteus仿真LCD1602整屏内容移动

如何用纯色填充位图?

stm32点亮st7735s的0.96寸lcd屏(调试中)

STM32 SPI+DMA刷LCD屏

LCD 交流屏 -直流屏

用渐变(或纯色)填充特定的可绘制矢量