⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 -lcd.c

📁 智原mp3 SDK 开发包 与巨力 有mp3 wma ogg decoder
💻 C
字号:
#include <string.h>
#include "api.h"
//#include "mp3app.h"
#include "get_latin2.h"
#include "lcd.h"
#include "get_latin2.h"


#define MIN(a,b)	((a) < (b) ? (a) : (b))
#define MAX(a,b)	((a) > (b) ? (a) : (b))

UINT8 lcd_max_str;
UINT16 fg_color, bg_color;
UINT16 bg_pixel[SCREEN_WIDTH];
UINT16 pixel_buf[256];

//extern unsigned char code font8x16[];

void delay_1ms(void)
{
	UINT16 n;
	
	for(n = 420; n > 0; n--) {}
}

void delay(UINT16 n)
{
	while(n--)
		delay_1ms();
}

void writec(UINT8 cmd)
{
	lcd_setcmd(cmd);
}
void writed(UINT8 lcddata)
{
	lcd_setdata(lcddata);
}

void write2c(UINT8 i, UINT8 j)
{
	writec(i);
	writec(j);
}

BOOLEAN lcd_put_data(UINT16 buf, UINT16 size)
{
	return api_bLcdDataMove(buf, size);
}

void SetTextOutMode(UINT8 mode)
{
//	textoutmode = mode;
}

BOOLEAN lcd_get_data(UINT16 buf, UINT16 size)
{
 	UINT16 i;
 	UINT8 xdata *ptr = (UINT8 xdata *)buf;
 
 	api_vLcdPinSelect();
 
 	for(i = 0; i < size; i++) {
  		LCDC_DMYRDRS = 1;
  		while(!LCDC_READY);
  		ptr[i] = LCDC_DATARS1;
 	} 
 	api_vLcdPinRecover();
 	return true;
}


void lcd_set_rw_area(UINT8 x, UINT8 y, UINT8 w, UINT8 h)
{
	api_vLcdPinSelect();
	
	writec(X_ADDR_AREA_SET);
	writec(x+START_X);			// start x
	writec(x+START_X + w - 1);		// end x
	
	writec(Y_ADDR_AREA_SET);
	writec(y+START_Y);			// start y
	writec(y+START_Y + h - 1);		// end y
	
	api_vLcdPinRecover();
}

void lcd_set_rw_area1(UINT8 x, UINT8 y, UINT8 w, UINT8 h)
{
	api_vLcdPinSelect();
	
	writec(X_ADDR_AREA_SET);
	writec(x);			// start x
	writec(x + w - 1);		// end x
	
	writec(Y_ADDR_AREA_SET);
	writec(y);			// start y
	writec(y + h - 1);		// end y
	
	api_vLcdPinRecover();
}
BOOLEAN lcd_putc_8x8(UINT8 x, UINT8 y, UINT8 c)
{
	UINT8 i, j, w, h;
	UINT16 xdata *pixel = pixel_buf;

	//if(textoutmode) //get buffer from lcd.
	//{
	//	lcd_get_data(pixel_buf,128);	
	//}

	if(x >= XRES || y >= YRES)
		return false;

	w = MIN(8, XRES - x);
	h = MIN(8, YRES - y);
	
	lcd_set_rw_area(x, y, w, h);
	
	api_bGetLatinFont8x8BMP(c);
	
	for(j = 0; j < h; j++) {
		for(i = 0; i < w; i++) {
			if((BitMapData[i] >> j) & 0x1)
				*pixel++ = fg_color;
			else
			{			
				//if(!textoutmode)
					*pixel++ = bg_color;
			}		
		}
	}	
	
	lcd_put_data((UINT16)pixel_buf, w*h*2);	
	return true;
}

BOOLEAN lcd_putc_8x16(UINT8 x, UINT8 y, UINT8 c)
{	
	UINT8 i, j, w, h;
	UINT16 xdata *pixel = pixel_buf;
	lcd_set_rw_area(x, y, w, h);
	//if(textoutmode) //get buffer from lcd.
	//{
	//	lcd_get_data(pixel_buf,256);	
	//}	
	
	api_bGetLatinFont8x16BMP(c);
	
	if(x >= XRES || y >= YRES)
		return false;

	w = MIN(8, XRES - x);
	h = MIN(16, YRES - y);
	
	lcd_set_rw_area(x, y, w, h);

	for(j = 0; j < 8; j++) {
		for(i = 8; i < 16; i++) {
			if((BitMapData[i] >> j) & 0x1)
				*pixel++ = fg_color;
			else
			{			
				//if(!textoutmode)
					*pixel++ = bg_color;
			}
		}
	}
		
	for(j = 0; j < 8; j++) {
		for(i = 0; i < w; i++) {
			if((BitMapData[i] >> j) & 0x1)
				*pixel++ = fg_color;
			else
			{			
				//if(!textoutmode)
					*pixel++ = bg_color;
			}
		}					
	}
	
	lcd_put_data((UINT16)pixel_buf, (UINT16)w*h*2);	
	return true;
}

BOOLEAN lcd_putc_16x16(UINT8 x, UINT8 y, UINT16 gcode)
{
	UINT8 i, j, w, h;
	UINT16 xdata *pixel = (UINT16 xdata *)&pixel_buf[0];	
	
	if(x >= XRES || y >= YRES)
		return false;
		
	if(gcode) {
		if(!api_bGetUniFont16x16BMP(gcode))
			return false;		
	}
	
	w = MIN(16, XRES - x);
	h = MIN(16, YRES - y);
	
	api_vLcdPinSelect();
	write2c(ENTRY_MODE_SET,0x04);	// 0xE
	api_vLcdPinRecover();	
	
	lcd_set_rw_area(x,108 - y, 16, 16);
				
	for(j = 0; j < h; j++) {
		for(i = 0; i < w; i++) {
			if((BitMapData[(i << 1) + (j >> 3)] >> (j & 0x7)) & 0x1)
				*pixel++ = fg_color;
			else
			{			
				//if(!textoutmode)
					*pixel++ = bg_color;
			}
		}		
	}

	lcd_put_data((UINT16)pixel_buf, (UINT16)w*h*2);
	
	api_vLcdPinSelect();
	write2c(ENTRY_MODE_SET,0x00);	// 0xE
	api_vLcdPinRecover();		
	
	return true;
}

void lcd_puts(UINT8 x, UINT8 y, UINT8 *str, UINT8 fontsize)
{
	
	INT8S data r1;
	UINT8 data n;

	n = 0;
	r1 = 0;
	api_s8GetFont16x16BMP(0, TRUE);

	while(*str != '\0') {
		if(n >= lcd_max_str)
			return;
				
		if(fontsize == FONTSIZE_8x8) {
			if(lcd_putc_8x8(x, y, *str++)) {
				x += 8;
				n++;
			}
		}
		else {
			if((fontsize == FONTSIZE_8x16) || 
			   (fontsize == FONTSIZE_HYPER && r1 != 1 && *str <= 0x80)) {
				if(lcd_putc_8x16(x, y, *str++)) {
					x += 8;
					n++;
				}
				continue;
			}
			r1 = api_s8GetFont16x16BMP(*str++, FALSE);
			if(r1 == 0) {
				if(lcd_putc_16x16(x, y, 0)) {
					x += 16;
					n += 2;
				}
			}
		}
	}	
}

void lcd_puts_unicode(UINT8 x, UINT8 y, UINT16 *str, UINT8 fontsize)
{
	UINT8 data n;
	n = 0;
	while(*str != '\0') {
		if(n >= lcd_max_str)
			return;

		if(fontsize == FONTSIZE_8x8) {
			if(lcd_putc_8x8(x, y, *str++)) {
				x += 8;
				n++;
			}
		}
		else {
			if((fontsize == FONTSIZE_8x16) ||
		   	   (fontsize == FONTSIZE_HYPER && *str <= 0x80)) {
		   		if(lcd_putc_8x16(x, y, *str++)) {
					x += 8;
					n++;
				}
				continue;
			}
			if(lcd_putc_16x16(x, y, *str++)) {
				x += 16;
				n += 2;
			}
		}
	}
}

void lcd_clear(void)
{
	UINT8 i;
	
	lcd_set_rw_area(0, 0, XRES, YRES);
	
	memset(pixel_buf, 0x0, sizeof(pixel_buf));
	
	for(i = 0; i < YRES; i++)
		lcd_put_data((UINT16)pixel_buf, XRES << 1);
}

void lcd_set_brightness(UINT8 v)
{
	api_vLcdPinSelect();
	write2c(CONTRAST_CONTROL,v);
	api_vLcdPinRecover();
}

void lcd_init(void)
{
	Print("LCD Init\n");
//#if 0	
	api_vLcdInit(LCM_INTERFACE_6800);
	api_vLcdPinSelect();
	write2c(OSC_MODE_SET,0x00);	// Internal OSC OFF
	write2c(ENTRY_MODE_SET,0x00);	// 0xE
	write2c(DRIVER_OUT_SET,0xB0);	// 1/132
	writec(STANDBY_MODE_OFF);
	delay(20);
	write2c(OSC_MODE_SET,0x01);	// Internal OSC ON
	delay(20);
	write2c(BIAS_SET,0x03);
	write2c(DC_DC_SELECT,0x01);
	write2c(DC_DC_CLK_DIV_SET,0x00);
	write2c(DC_DC_AMP_SET,0x01);
	delay(20);
	write2c(DC_DC_AMP_SET,0x09);
	delay(100);
	write2c(DC_DC_AMP_SET,0x0B);
	delay(100);
	write2c(DC_DC_AMP_SET,0x0F);
	delay(20);
	
	write2c(TEMP_COMP_SET,0x01);
	write2c(N_BLOCK_INVERSION,0x8D);
	write2c(ROW_VECTOR_SET,0x02);
	writec(DISPLAY_ON);
	write2c(CONTRAST_CONTROL,0xC0);
	
#if 1
	write2c(AREA_SCROLL_SET, 0x00);
	write2c(NON_OPERATION, 0x83);
	writec(0x00);
	write2c(PARTIAL_DISPLAY_SET,0x00);
	write2c(PD_START_LINE_SET,0x00);
	write2c(PD_END_LINE_SET,0x00);
	write2c(SCROLL_START_LINE_SET,0x00);
#endif	
	

	api_vLcdPinRecover();
//#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -