📄 lcd.c
字号:
#include "lcd1.h" // LCD utility (written in assembler) header file#include "lcd.h" // LCD utility (writeen in C) header file/*""FUNC COMMENT""************************************************************** ID : ---* Function name : void _init_lcd(void)* Function : initialize the LCD * Paramenter : none* Return : none* Function used : _lcd1__initial() : initialize the LCD control port* : _lcd1__wait(unsigned int) : software wait for t*100us* : _lcd1__wr_nibble_creg(int) : write command to LCD (4bit)* : write_creg(char) : write command to LCD (8bit)* : is_busy(void) : wait for busy flag free* Notice : none* History : ---*""FUNC COMMENT END""*********************************************************/void init_lcd(void){ _lcd1__initial(); /* initialize the LCD control port */ /*--- initial process after LCD reset ---*/ _lcd1__wait(150); /* wait 15ms after VDD is steady */ _lcd1__wr_nibble_creg(0x03); /* function set 8bit(0x03) */ _lcd1__wait(41); /* wait 4.1ms */ _lcd1__wr_nibble_creg(0x03); /* function set 8bit(0x03) */ _lcd1__wait(1); /* wait 0.1ms */ _lcd1__wr_nibble_creg(0x03); /* function set 8bit(0x03) */ _lcd1__wait(1); /* wait 0.1ms */ _lcd1__wr_nibble_creg(0x02); /* function set 4bit (0x02) */ _lcd1__wait(1); /* wait 0.1ms */ write_creg(CMD_FUNC_D4_N2_F7); /* set interface data length as 4 bit */ /* 2 lines, 5*7 dots */ _lcd1__wait(1); /* wait 0.1ms */ write_creg(CMD_DISP_DS); /* display off */ while(is_busy()); /* wait for busy flag free */ write_creg(CMD_CLEAR); /* clear display */ while(is_busy()); /* wait for busy flag free */ write_creg(CMD_ENTRY_INC); /* entry mode, increment */ while(is_busy()); /* wait for busy flag free */ write_creg(CMD_DISP_EN); /* display on, cursol off */ /* blink off */}/*""FUNC COMMENT""************************************************************** ID : ---* Function name : void set_cursol(int x, int y)* Function : set cursol position* Paramenter : int x : X axis* : int y : Y axis* Return : none* Function used : write_creg(char) : write command to LCD (8bit)* : is_busy(void) : wait for busy flag free* Notice : none* History : ---*""FUNC COMMENT END""*********************************************************/void set_cursol(int x, int y){ while(is_busy()); write_creg(0x80 | y*0x40 + x); /* internal address of the second line is from 0x40 to 0x4f */}/*""FUNC COMMENT""************************************************************** ID : ---* Function name : void write_lcd(const char* msg)* Function : write string to LCD* Paramenter : const char* : address of string to write to LCD* Return : none* Function used : write_dreg(char) : write data to LCD (8bit)* : is_busy(void) : wait for busy flag free* Notice : none* History : ---*""FUNC COMMENT END""*********************************************************/void write_lcd(const char *msg){ for( ; '\0' != *msg; msg++){ while(is_busy()); write_dreg(*msg); }}void write_lcd_char(const char msg){ while(is_busy()); write_dreg(msg);}/*""FUNC COMMENT""************************************************************** ID : ---* Function name : int is_busy(void)* Function : check busy flag* Paramenter : none* Return : int : state of busy flag* Function used : read_creg() : read command from LCD* Notice : none* History : ---*""FUNC COMMENT END""*********************************************************/int is_busy(void){ if(0x80 & read_creg()){ /* if(BusyFlag) */ return TRUE; } else{ return FALSE; }}/*""FUNC COMMENT""************************************************************** ID : ---* Function name : char read_creg(void)* Function : read command from LCD* Paramenter : none* Return : char : command read from LCD* Function used : _lcd1__rd_nibble_creg() : read command from LCD* Notice : none* History : ---*""FUNC COMMENT END""*********************************************************/char read_creg(void){ char command; command = _lcd1__rd_nibble_creg() << 4; /* interface length 4bit */ command |= _lcd1__rd_nibble_creg(); return command;}/*""FUNC COMMENT""************************************************************** ID : ---* Function name : void write_creg(char data)* Function : write command to LCD* Paramenter : char data : command to write to LCD* Return : none* Function used : _lcd1__wr_nibble_creg() : write command to LCD* Notice : none* History : ---*""FUNC COMMENT END""*********************************************************/void write_creg(char data){ _lcd1__wr_nibble_creg(data>>4 & 0x000f); /* interface length 4bit */ _lcd1__wr_nibble_creg(data & 0x000f);}/*""FUNC COMMENT""************************************************************** ID : ---* Function name : char read_dreg(void)* Function : read data from LCD* Paramenter : none* Return : char : data read from LCD* Function used : _lcd1__rd_nibble_dreg() : read data from LCD* Notice : none* History : ---*""FUNC COMMENT END""*********************************************************/char read_dreg(void){ char data; data = _lcd1__rd_nibble_dreg() << 4; /* interface length 4bit */ data |= _lcd1__rd_nibble_dreg(); return data;}/*""FUNC COMMENT""************************************************************** ID : ---* Function name : void write_dreg(char data)* Function : write data to LCD* Paramenter : char data : data to write to LCD* Return : none* Function used : _lcd1__wr_nibble_dreg() : write data to LCD* Notice : none* History : ---*""FUNC COMMENT END""*********************************************************/void write_dreg(char data){ _lcd1__wr_nibble_dreg(data>>4 & 0x000f); /* interface length 4bit */ _lcd1__wr_nibble_dreg(data & 0x000f);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -