/* 设置显示RAM起始地址,亦即光标位置,(x,y)-对应屏幕上的字符坐标 */ void LcdSetCursor(unsigned char x, unsigned char y) { unsigned char addr; if (y == 0) //由输入的屏幕坐标计算显示RAM的地址 addr = 0x00 + x; //第一行字符地址从0x00起始 else addr = 0x40 + x; //第二行字符地址从0x40起始 LcdWriteCmd(addr | 0x80); //设置RAM地址 }
/*************************************** 说明: 设置光标定位 *****************************************/ void LocateXY(char x , char y) { unsigned char temp; temp = x & 0xf; y &= 0x1; if ( y )temp |= 0x40; temp |= 0x80; LcdWriteCmd(temp,1); }
/******************************************* 函数名称:Lcd1602LocateXY 功 能:向液晶输入显示字符位置的坐标信息 参 数:x--位置的列坐标 y--位置的行坐标 返回值 :无 ********************************************/ void Lcd1602LocateXY(uint8 x,uint8 y) { uint8 temp; temp = x&0x0f; y &= 0x01; if(y) temp |= 0x40; //如果在第2行 temp |= 0x80; LcdWriteCmd(temp,1); }
static void LcdSetCursor(uint8_t pos) { uint8_t offset[] = { #ifdef LCD_KS0073 0x00, 0x20, 0x40, 0x60 #elif (LCD_COLS >= 20) 0x00, 0x40, 0x14, 0x54 #else 0x00, 0x40, 0x10, 0x50 #endif }; pos = offset[(pos / LCD_COLS) % LCD_ROWS] + pos % LCD_COLS; LcdWriteCmd(1 << LCD_DDRAM | pos); }
/******************************************* 函数名称:Lcd1602Reset 功 能:对1602液晶模块进行复位操作 参 数:无 返回值 :无 ********************************************/ void Lcd1602Reset(void) { LcdCtlOut; //控制线端口设为输出状态 LcdDatOutCtl; //数据端口设为输出状态 LcdWriteCmd(0x38, 0); //规定的复位操作 delay_ms(5); LcdWriteCmd(0x38, 0); delay_ms(5); LcdWriteCmd(0x38, 0); delay_ms(5); LcdWriteCmd(0x38, 1); //显示模式设置 LcdWriteCmd(0x08, 1); //显示关闭 LcdWriteCmd(0x01, 1); //显示清屏 LcdWriteCmd(0x06, 1); //写字符时整体不移动 LcdWriteCmd(0x0c, 1); //显示开,不开游标,不闪烁 }
static int LcdInit(NUTDEVICE * dev) { LCD_RS_CLR(); LCD_RW_CLR(); LcdClrBits(LCD_DATA); NutMicroDelay(30); LCD_EN_CLR(); NutMicroDelay(30); NutSleep(18); /* This initialization will make sure, that the LCD is switched * to 8-bit mode, no matter which mode we start from or we finally * need. */ LcdWriteCmd(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)); NutSleep(16); LcdWriteCmd(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)); NutSleep(4); LcdWriteCmd(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)); NutSleep(2); LcdWriteInstruction((_BV(LCD_FUNCTION)) | (_BV(LCD_FUNCTION_8BIT)) | (_BV(LCD_EXT)) , LCD_SHORT_DELAY); /* Switch display and cursor off. */ LcdWriteNibble(_BV(LCD_ON_CTRL) >> 4); LcdWriteNibble(_BV(LCD_ON_CTRL)); NutSleep(2); /* Clear display. */ LcdClear(); /* Set entry mode. */ LcdWriteCmd(_BV(LCD_ENTRY_MODE) | _BV(LCD_ENTRY_INC)); /* Switch display on. */ LcdWriteCmd(_BV(LCD_ON_CTRL) | _BV(LCD_ON_DISPLAY)); /* Move cursor home. */ LcdCursorHome(); /* Set data address to zero. */ LcdWriteCmd(_BV(LCD_DDRAM)); return 0; }
static void LcdWriteInstruction(uint8_t cmd, uint8_t xt) { LcdWriteCmd(cmd); }
static void LcdCursorMode(uint8_t on) { LcdWriteCmd(1 << LCD_ON_CTRL | on ? 1 << LCD_ON_CURSOR : 0x00); }
static void LcdClear(void) { LcdWriteCmd(_BV(LCD_CLR)); NutSleep(2); }
static void LcdCursorRight(void) { LcdWriteCmd(1 << LCD_MOVE | 1 << LCD_MOVE_RIGHT); }
static void LcdCursorLeft(void) { LcdWriteCmd(1 << LCD_MOVE); }
static void LcdCursorHome(void) { LcdWriteCmd(1 << LCD_HOME); NutSleep(2); }
/* 打开光标的闪烁效果 */ void LcdOpenCursor(){ LcdWriteCmd(0x0F); }
/* 关闭光标显示 */ void LcdCloseCursor(){ LcdWriteCmd(0x0C); }
/******************************************* 函数名称:Lcd1602Clr 功 能:LCD1602 清屏显示 参 数:无 返回值 :无 ********************************************/ void Lcd1602Clr(void) { LcdWriteCmd(0x01,1); }
static int LcdInit(NUTDEVICE * dev) { #if defined(PMC_PCER) outr(PMC_PCER, _BV(LCD_RS_PIO_ID) | _BV(LCD_EN_PIO_ID)); #endif /* Initialize GPIO lines. */ #ifdef LCD_RW_BIT outr(PMC_PCER, _BV(LCD_RW_PIO_ID)); LCD_RW_CLR(); #endif #ifdef LCD_EN2_BIT outr(PMC_PCER, _BV(LCD_EN2_PIO_ID)); LCD_EN2_CLR(); #endif #ifdef LCD_RST_BIT outr(PMC_PCER, _BV(LCD_RST_PIO_ID)); LCD_RST_CLR(); #endif LCD_RS_CLR(); LCD_RW_CLR(); LcdClrBits(LCD_DATA); NutMicroDelay(30); LCD_EN_CLR(); NutMicroDelay(30); /* Initial delay. Actually only required after power on. */ NutSleep(16); /* This initialization will make sure, that the LCD is switched * to 8-bit mode, no matter which mode we start from or we finally * need. */ LcdWriteNibble((_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)) >> 4); NutSleep(15); LcdWriteNibble((_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)) >> 4); NutSleep(4); LcdWriteNibble((_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)) >> 4); NutSleep(2); #ifdef LCD_IF_4BIT /* We now switch to 4-bit mode */ LcdWriteNibble(_BV(LCD_FUNCTION) >> 4); NutSleep(2); // TODO: Add support for large font in single line displays /* Set number of lines and font. Can't be changed later. */ #if (LCD_ROWS == 2) || (LCD_ROWS==4) LcdWriteNibble((_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_2LINES)) >> 4); LcdWriteNibble(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_2LINES)); #else LcdWriteNibble(_BV(LCD_FUNCTION) >> 4); LcdWriteNibble(_BV(LCD_FUNCTION) ); #endif #else /* LCD_IF_4BIT */ LcdWriteCmd(_BV(LCD_FUNCTION) | _BV(LCD_FUNCTION_8BIT)); #endif /* LCD_IF_4BIT */ NutSleep(2); /* Switch display and cursor off. */ LcdWriteNibble(_BV(LCD_ON_CTRL) >> 4); LcdWriteNibble(_BV(LCD_ON_CTRL)); NutSleep(2); /* Clear display. */ LcdClear(); /* Set entry mode. */ LcdWriteCmd(_BV(LCD_ENTRY_MODE) | _BV(LCD_ENTRY_INC)); /* Switch display on. */ LcdWriteCmd(_BV(LCD_ON_CTRL) | _BV(LCD_ON_DISPLAY)); /* Move cursor home. */ LcdCursorHome(); /* Set data address to zero. */ LcdWriteCmd(_BV(LCD_DDRAM)); return 0; }
/******************************************* 函数名称:Lcd1602Cursor( uint8 u8CurOn) 功 能:1602 光标显示 开关 参 数:u8CurOn为0 光标关,否则开 返回值 :无 ********************************************/ void Lcd1602CursorOn(uint8 u8CurOn) { if(u8CurOn) LcdWriteCmd(0x0f,1); else LcdWriteCmd(0x0c,1); }