/* * LcdWrite * Description: This procedure simply writes a data byte to the LCD. * It does not return until the LCD's busy flag is cleared. * * Argument: c: data byte * Return: None * * Input: None * Output: LCD * * Operation: Send the byte, then wait for the BF to be cleared. * * Revision History: * Dec. 16, 2012 Nnoduka Eruchalu Initial Revision */ void LcdWrite(unsigned char c) { LCD_DATA_LAT = c; /* put data on output port */ SET_RS(); /* RS = 1: Data */ CLEAR_RW(); /* R/W = 0: Write */ LCD_STROBE(); LcdWaitBF(); /* dont exit until the LCD is no longer busy */ }
inline void sc2004_ReturnHome(void) { SET_DDR_DATA_OUT; SET_RS(0); SET_RW(0); SET_DATA(1<<DB1); sc2004_PulseEnable(); }
inline void sc2004_ClearDisplay(void) { SET_DDR_DATA_OUT; SET_RS(0); SET_RW(0); SET_DATA(1<<DB0); sc2004_PulseEnable(); }
inline uint8_t sc2004_ReadData() { SET_DDR_DATA_IN; SET_RS(1); SET_RW(1); sc2004_PulseEnable(); return GET_DATA; }
inline void sc2004_WriteData(uint8_t data) { SET_DDR_DATA_OUT; SET_RS(1); SET_RW(0); SET_DATA(data); sc2004_PulseEnable(); }
void LCDByte(uint8_t c,uint8_t isdata) { //Sends a byte to the LCD in 4bit mode //cmd=0 for data //cmd=1 for command //NOTE: THIS FUNCTION RETURS ONLY WHEN LCD HAS PROCESSED THE COMMAND uint8_t hn,ln; //Nibbles uint8_t temp; hn=c>>4; ln=(c & 0x0F); if(isdata==0) CLEAR_RS(); else SET_RS(); _delay_us(0.500); //tAS SET_E(); //Send high nibble temp=(LCD_DATA_PORT & (~(0X0F<<LCD_DATA_POS)))|((hn<<LCD_DATA_POS)); LCD_DATA_PORT=temp; _delay_us(1); //tEH //Now data lines are stable pull E low for transmission CLEAR_E(); _delay_us(1); //Send the lower nibble SET_E(); temp=(LCD_DATA_PORT & (~(0X0F<<LCD_DATA_POS)))|((ln<<LCD_DATA_POS)); LCD_DATA_PORT=temp; _delay_us(1); //tEH //SEND CLEAR_E(); _delay_us(1); //tEL LCDBusyLoop(); }
inline void sc2004_SetAddr_DDRAM(uint8_t addr) { SET_DDR_DATA_OUT; SET_RS(0); SET_RW(0); SET_DATA( (1 << DB7) | (addr & 0b01111111) ); sc2004_PulseEnable(); }
void LCD_write_byte(uchar cmd,uchar data){ unsigned char data_temp; if(cmd==1) CLR_RS(); //向LCD写入命令 if(cmd==0) SET_RS(); //向LCD写入数据 data_temp=data; data_temp=data_temp>>4; LCD_Write_half_byte(data_temp & 0x0F); data_temp=data; LCD_Write_half_byte(data_temp & 0x0F); _delay_ms(1); }
inline void sc2004_EntryMode(uint8_t increment_direction, uint8_t display_shift) { SET_DDR_DATA_OUT; SET_RS(0); SET_RW(0); SET_DATA( (1<<DB2) | (increment_direction<<DB1) | (display_shift<<DB0) ); sc2004_PulseEnable(); }
inline void sc2004_CursorDisplayShift(uint8_t shift_display_or_cursor, uint8_t direction_right) { SET_DDR_DATA_OUT; SET_RS(0); SET_RW(0); SET_DATA( (1<<DB4) | (shift_display_or_cursor<<DB3) | (direction_right<<DB2) ); sc2004_PulseEnable(); }
inline void sc2004_DisplayMode(uint8_t display, uint8_t cursor, uint8_t cur_blink) { SET_DDR_DATA_OUT; SET_RS(0); SET_RW(0); SET_DATA( (1<<DB3) | (display<<DB2) | (cursor <<DB1) | (cur_blink<<DB0) ); sc2004_PulseEnable(); }
inline void sc2004_FunctionSet(uint8_t length_is_8bit, uint8_t double_line, uint8_t wide_font) { SET_DDR_DATA_OUT; SET_RS(0); SET_RW(0); SET_DATA( (1<<DB5) | (length_is_8bit<<DB4) | (double_line << DB3) | (wide_font << DB2) ); sc2004_PulseEnable(); }
inline void sc2004_setPort(sc2004_port * rec) { sbi(*rec->pddr_rs, rec->portno_rs); //init port direction sbi(*rec->pddr_rw, rec->portno_rw); sbi(*rec->pddr_enable, rec->portno_enable); SET_DDR_DATA_OUT; SET_RS(0); //SET_RW(0); SET_DATA(0); SET_ENABLE(0); pcurrent_port = rec; }
inline uint8_t sc2004_ReadBusyAndAddress(uint8_t * addr) { uint8_t data; SET_DDR_DATA_IN; SET_RS(0); SET_RW(1); sc2004_PulseEnable(); data = GET_DATA; if(addr) *addr = data & 0b01111111; return data & (1 << DB7); };