📄 lcd.c
字号:
#include <string.h>
#include "api.h"
//#include "mp3app.h"
#include "get_latin2.h"
#include "lcd.h"
#include "get_latin2.h"
#include"common.h"
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
UINT8 lcd_max_str;
#ifdef loop_show_file_name
INT8 sonename_loop_step;//john 070606
INT8 songname_Chinese_max;//john 070606
INT8 songname_English_max;//john 070606
#endif
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);
}
#if 0
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;
}
#endif
void lcd_set_rw_area(UINT8 x, UINT8 y, UINT8 w, UINT8 h)
{
api_vLcdPinSelect();
writec(0x43);
writec(x); // start x
writec(x + w - 1); // end x
writec(0x42);
writec(y+2); // start y
writec(y + h + 1 ); // end y
api_vLcdPinRecover();
}
void lcd_set_disply_mode(UINT8 disply_mode,UINT8 scan_direction )
{
api_vLcdPinSelect();
writec(0x40);
writec(disply_mode); //显示模式
writec(0x10);
writec(scan_direction); // 扫描方向 22 和 26相反
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(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
{
*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;
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
{
*pixel++ = bg_color;
}
}
}
for(j = 0; j < 8; j++) {
for(i = 0; i < w; i++) {
if((BitMapData[i] >> j) & 0x1)
*pixel++ = fg_color;
else
*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);
lcd_set_disply_mode(0x08,0x22);
lcd_set_rw_area(x,142 - y, w, h); //or 108
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);
lcd_set_disply_mode(0x00,0x22);
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 += 6;
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 += 6;
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);
}
#if 0
void lcd_clear_word(void)
{
UINT8 i;
lcd_set_rw_area(50, 74, 54, 80);
memset(pixel_buf, 0xF77F, sizeof(pixel_buf));
for(i = 96; i < 102; i++)
lcd_put_data((UINT16)pixel_buf, XRES << 1);
}
void lcd_set_brightness(UINT8 v)
{
#if 1
api_vLcdPinSelect();
writec(0x2a);
writec(0xce+v); //90 0xde c8
delay(20);
writec(0x2b);
writec(0x44+v); //90 0x54 c8
api_vLcdPinRecover();
#else
api_vLcdPinSelect();
writec(0x2a);
writec(v*8); //90 0xde c8
delay(20);
writec(0x2b);
writec(v*8); //90 0x54 c8
api_vLcdPinRecover();
#endif
}
void lcd_init(void)
{
// Print("LCD Init\n");
api_vLcdInit(LCM_INTERFACE_6800);
api_vLcdPinSelect();
XBYTE[0XF400] = 0XFF;
XBYTE[0XF401] = 0XFF;
//
bLCD_PIN_RESET = 0;
delay(100);
bLCD_PIN_RESET = 1;
CDIR = 0;
delay(100);
//-------------------------------------------------
writec(0x2C);
delay(20);
//-------------------------------------------------
writec(0x02);
writec(0x01);
delay(20);
//-------------------------------------------------
writec(0x26);
writec(0x01);
delay(20);
writec(0x26);
writec(0x09);
delay(20);
writec(0x26);
writec(0x0b);
delay(20);
writec(0x26);
writec(0x0f);
delay(20);
//------------------------------------------------
writec(0x10);
writec(0x23); // 21,25
delay(5);
//-------------------------------------------------
writec(0x20);
writec(0x03); //20
delay(20);
//-------------------------------------------------
writec(0x22);
writec(0x11);
delay(5);
//------------------------------------------------
writec(0x24);
writec(0x11); //00
delay(20);
//-------------------------------------------------
writec(0x28);
writec(0x01);
delay(20);
//------------------------------------------------
writec(0x2a);
writec(0xc8); //90 0xde
delay(20);
//------------------------------------------------
writec(0x2b);
writec(0xc8); //90 0x54
delay(10);
//------------------------------------------------
writec(0x30);
writec(0x09); //0b
delay(20);
//------------------------------------------------
writec(0x32);
writec(0x0E);
delay(20);
//-----------------------------------------------
writec(0x34);
writec(0x08);//0d
delay(20);
//-------------------------------------------------
writec(0x36);
writec(0x00);
delay(20);
//---------显示模式----------
writec(0x40);
writec(0x00);//显示模式08和 00相反 竖屏
writec(0x10);
writec(0x22);
delay(20);
//------------------------------------------------
writec(0x43);
writec(0x00);
writec(0x7F);
delay(20);
//------------------------------------------------
writec(0x42);
writec(0x00);
writec(0x9F);
delay(20);
//------------------------------------------------
writec(0x53);
writec(0x00);
delay(20);
//-------------------------------------------------
writec(0xEB);
delay(20);
//-------------------------------------------------
writec(0x45);
writec(0x00);
//-------------------------------------------------
writec(0x55);
writec(0x00);
delay(20);
//------------------------------------------------
writec(0x5A);
writec(0x00);
delay(20);
//------------------------------------------------
writec(0x51);
delay(40);
api_vLcdPinRecover();
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -