文档详情

13-mini2440之LCD显示汉字、字母(高级版).doc

枫**
实名认证
店铺
DOC
62KB
约10页
文档ID:532936944
13-mini2440之LCD显示汉字、字母(高级版).doc_第1页
1/10

define GLOBAL_CLK 1#include "def.h"#include "option.h"#include "2440addr.h"#include "2440lib.h"#include "2440slib.h"#include "lmj.h"#include "happy.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) ) */#define LMJ_SIZE (sizeof(lmj) / sizeof(lmj[0]))#define HAPPY_SIZE (sizeof(happy) / sizeof(happy[0]))#define WORD_WIDTH 32 //字大小为32 * 32#define WORD_CHAR_NUM (WORD_WIDTH * WORD_WIDTH / 8)#define WORD_WIDTH_BYTE (WORD_WIDTH / 8)#define WORD_SIZE (WORD_CHAR_NUM / 8)#define WORD_NUM (LMJ_SIZE / WORD_SIZE)#define ASCII_WIDTH 16#define ASCII_HEIGHT 32#define ASCII_CHAR_NUM (ASCII_WIDTH * ASCII_HEIGHT / 8)#define ASCII_WIDTH_BYTE (ASCII_WIDTH / 8)#define ASCII_SIZE (ASCII_CHAR_NUM / 8)#define ASCII_NUM (HAPPY_SIZE / ASCII_SIZE)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_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_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, 70, 0xff0000, *lmj); lcd_draw_word(80, 145, 0xff0000, *(lmj+WORD_SIZE)); lcd_draw_word(80, 220, 0xff0000, *(lmj+WORD_SIZE * 2)); lcd_draw_ascii(120, 40, 0x00ff00, *happy); 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); //有效PWREN信号 rLCDCON5 = rLCDCON5 & (~(1<<5)) | (0<<5); //PWREN信号极性不翻转 rLCDCON1 |= 0x1; //开启LCD}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_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 < WORD_CHAR_NUM; i++) //万能函数 { mask = 0x80; buf = ch[i]; for (j = 0; j < 8; j++) { if (buf & mask) { lcd_put_pixel(x + i / WORD_WIDTH_BYTE, y + (i % WORD_WIDTH_BYTE) * 8 + j, color); } mask >>= 1; } }}void lcd_draw_ascii(unsigned int x, unsigned int y, unsigned int color, const unsigned char ch[]){ int i; for (i = 0; i < HAPPY_SIZE; i += ASCII_SIZE) { _lcd_draw_ascii(x, y + i * 2, color, *(happy + i)); }}void _lcd_draw_ascii(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 < ASCII_CHAR_NUM; i++) //万能函数 { mask = 0x80; buf = ch[i]; for (j = 0; j < 8; j++) { if (buf & mask) { lcd_put_pixel(x + i / ASCII_WIDTH_BYTE, y + (i % ASCII_WIDTH_BYTE) * 8 + j, color); } mask >>= 1; } }}void lcd_put_pixel(unsigned int x, unsigned int y, unsigned int color){ lcd_buf[x][y] = color;}下面分别是两个头文件lmj.hunsigned char lmj[][8] = { // 吕(0) (1) (2) 美(3) (4) (5) 娟(6) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00。

下载提示
相似文档
正为您匹配相似的精品文档