您的当前位置:首页正文

12-mini2440之LCD显示汉字、字母

2024-08-28 来源:易榕旅网
#define GLOBAL_CLK 1

#include \"def.h\" #include \"option.h\" #include \"2440addr.h\" #include \"2440lib.h\" #include \"2440slib.h\" #include \"word.h\" /*

*#define LCD_W35 *

*#elif defined(LCD_W35) *

*#define LCD_WIDTH 320 宽 //在option.h文件里面有他们的定义

*#define LCD_HEIGHT 240 高

*#define LCD_PIXCLOCK 4 时钟参数

*#define LCD_RIGHT_MARGIN 0x44 右边沿 *#define LCD_LEFT_MARGIN 0x04 左边沿 *#define LCD_HSYNC_LEN 0x01 行无效脉冲宽度

*#define LCD_UPPER_MARGIN 10 上边沿 *#define LCD_LOWER_MARGIN 4 下边沿 *#define LCD_VSYNC_LEN 1 列无效脉冲宽度

*#define LCD_CON5 ((1<<11) | (1<<8) | (1<<9) | (1<<0) ) */

unsigned int lcd_buf[LCD_HEIGHT][LCD_WIDTH]; //24bpp,定义为(unsigned int)32位

void delay(unsigned int times); void lcd_init(void);

void lcd_brush_background(unsigned int color);

void lcd_draw_circle(unsigned int color, unsigned int radius);

void lcd_draw_word(unsigned int x, unsigned int y, unsigned int color, const unsigned char ch[]); void lcd_draw_ascii(unsigned int x, unsigned int y, unsigned int color, const unsigned char ch[]); void lcd_put_pixel(unsigned int x, unsigned int y, unsigned int color);

int Main(void) { lcd_init(); lcd_brush_background(0xffffff); //白 lcd_draw_word(80, 100, 0x00ff00, *word); lcd_draw_word(80, 200, 0x00ff00, *(word + 4)); lcd_draw_ascii(130, 80, 0xff0000, *(word + 8)); lcd_draw_ascii(130, 155, 0xff0000, *(word + 10)); lcd_draw_ascii(130, 230, 0xff0000, *(word + 12)); while (1) ; return 0; }

void delay(unsigned int times) {

int i;

for (;times > 0; times--) for (i = 0; i < 400; i++) ; }

void lcd_init(void) { rGPCCON = 0xaaaa02a9; //管脚配置用于LCD rGPCUP = 0xffffffff; rGPDCON = 0xaaaaaaaa; rGPDUP = 0xffffffff; rGPGCON |= (0x3<<8); //设置GPG4为LCD_PWREN rGPGUP |= (0x1<<4); rGPGDAT |= (0x1<<4); rLCDCON1 = (LCD_PIXCLOCK<<8) | (0x3<<5) | (0xd<<1); //设置时钟、LCD类型为TFT、24bpp rLCDCON2 = (LCD_UPPER_MARGIN<<24) | ((LCD_HEIGHT - 1)<<14) | (LCD_LOWER_MARGIN<<6) | (LCD_VSYNC_LEN); rLCDCON3 = (LCD_RIGHT_MARGIN<<19) | ((LCD_WIDTH - 1)<<8) | (LCD_LEFT_MARGIN);

rLCDCON4 = LCD_HSYNC_LEN; rLCDCON5 = 0x0308; rLCDSADDR1 = (((unsigned int)lcd_buf>>22)<<21) | ((0x1fffff) & ((unsigned int)lcd_buf>>1)); rLCDSADDR2 = 0x1fffff & (((unsigned int)lcd_buf + (LCD_WIDTH * LCD_HEIGHT * 4))>>1); rLCDSADDR3 = LCD_WIDTH * 32 / 16; rLCDINTMSK |= 0x3; rTCONSEL = 0; rLCDCON5 = rLCDCON5 & (~(1<<3)) | (1<<3); rLCDCON5 = rLCDCON5 & (~(1<<5)) | (0<<5); rLCDCON1 |= 0x1; }

void lcd_brush_background(unsigned int color) { int x, y; for (x = 0; x < LCD_HEIGHT; x++) { for (y = 0; y < LCD_WIDTH; y++) { lcd_buf[x][y] = color; } } }

void lcd_draw_circle(unsigned int color, unsigned int radius) { unsigned int x, y; unsigned int sqr = radius * radius; for (x = 0; x < LCD_WIDTH; x++) { for (y = 0; y < LCD_HEIGHT; y++) { if (((x-120)*(x-120) + (y-160)*(y-160)) <= sqr) { lcd_buf[x][y] = color; //有效PWREN信号 //PWREN信号极性不翻转 //开启LCD //点在圆内的话就上色

} } } }

void lcd_draw_word(unsigned int x, unsigned int y, unsigned int color, const unsigned char ch[]) { unsigned short int i, j;

unsigned char mask, buffer; for(i = 0; i < 16; i++) //程序长,但容易理解 { mask = 0x80; //掩码 buffer = ch[i * 2]; //提取一行的第一个字节 for(j = 0; j < 8; j++) { if(buffer & mask) { lcd_put_pixel(x + i, y + j, color); //为笔画上色 } mask >>= 1; } mask = 0x80; //掩码 buffer = ch[i*2+1]; //提取一行的第二个字节 for(j = 0; j < 8; j++) { if(buffer & mask) { lcd_put_pixel(x + i, y + j + 8, color);//为笔画上色 } mask >>= 1; } } } /*

void lcd_draw_word(unsigned int x, unsigned int y, unsigned int color, const unsigned char ch[]) { unsigned short int i, j; unsigned char buf, mask;

for(i = 0; i < 32; i++) { mask = 0x80; buf = ch[i]; for (j = 0; j < 8; j++) { if (buf & mask) //程序更短,但下面的参数不好想到 { lcd_put_pixel(x + i / 2, y + (i % 2) * 8 + j, color); } mask >>= 1; } } } */

void lcd_draw_ascii(unsigned int x, unsigned int y, unsigned int color, const unsigned char ch[]) { unsigned short int i,j;

unsigned char mask,buffer; for(i=0;i<16;i++) { mask = 0x80; buffer = ch[i]; for(j = 0; j < 8; j++) { if(buffer & mask) { lcd_put_pixel(x + i, y + j, color); } mask >>= 1; } } }

void lcd_put_pixel(unsigned int x, unsigned int y, unsigned int color) { lcd_buf[x][y] = color; }

下面是word.h文件

unsigned char word[][8] = { //陈(0) 剑(1) A(2) R(3) M(4)

{0x00,0x40,0x78,0x40,0x4B,0xFE,0x48,0x80}, {0x51,0x00,0x61,0x40,0x52,0x40,0x4B,0xFC}, {0x48,0x40,0x68,0x50,0x52,0x48,0x42,0x44},

{0x44,0x46,0x48,0x42,0x41,0x40,0x40,0x80},/*\"陈\

{0x08,0x04,0x08,0x04,0x14,0x24,0x12,0x24}, {0x21,0x24,0x7F,0xA4,0x80,0x24,0x11,0x24}, {0x49,0xA4,0x25,0x24,0x15,0x24,0x12,0x24},

{0x07,0x84,0x78,0x04,0x00,0x14,0x00,0x08},/*\"剑\

{0x00,0x00,0x00,0x10,0x10,0x18,0x28,0x28},

{0x24,0x3C,0x44,0x42,0x42,0xE7,0x00,0x00},/*\"A\

{0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x7C},

{0x48,0x48,0x44,0x44,0x42,0xE3,0x00,0x00},/*\"R\

{0x00,0x00,0x00,0xEE,0x6C,0x6C,0x6C,0x6C},

{0x54,0x54,0x54,0x54,0x54,0xD6,0x00,0x00} /*\"M\ };

因篇幅问题不能全部显示,请点此查看更多更全内容