#ifndef MC8051FUN_LCD_H_ #define MC8051FUN_LCD_H #ifndef LCD_E #define LCD_E P3_4 #endif #ifndef LCD_RS #define LCD_RS P3_5 #endif #ifndef LCD_RW #define LCD_RW P3_6 #endif #ifndef LCD_DATA #define LCD_DATA P0 #endif #ifndef LCD_READY #define LCD_READY P0_7 #endif // Clear Display -------------- 0b00000001 #define LCD_CLEAR_DISPLAY 0x01 // Cursor Home ---------------- 0b0000001x #define LCD_CURSOR_HOME 0x02 // Set Entry Mode ------------- 0b000001xx #define LCD_SET_ENTRY 0x04 #define LCD_ENTRY_DECREASE 0x00 #define LCD_ENTRY_INCREASE 0x02 #define LCD_ENTRY_NOSHIFT 0x00 #define LCD_ENTRY_SHIFT 0x01 // Set Display ---------------- 0b00001xxx #define LCD_SET_DISPLAY 0x08 #define LCD_DISPLAY_OFF 0x00 #define LCD_DISPLAY_ON 0x04 #define LCD_CURSOR_OFF 0x00 #define LCD_CURSOR_ON 0x02 #define LCD_BLINKING_OFF 0x00 #define LCD_BLINKING_ON 0x01 // Set Shift ------------------ 0b0001xxxx #define LCD_SET_SHIFT 0x10 #define LCD_CURSOR_MOVE 0x00 #define LCD_DISPLAY_SHIFT 0x08 #define LCD_SHIFT_LEFT 0x00 #define LCD_SHIFT_RIGHT 0x04 // Set Function --------------- 0b001xxxxx #define LCD_SET_FUNCTION 0x20 #define LCD_FUNCTION_4BIT 0x00 #define LCD_FUNCTION_8BIT 0x10 #define LCD_FUNCTION_1LINE 0x00 #define LCD_FUNCTION_2LINE 0x08 #define LCD_FUNCTION_5X7 0x00 #define LCD_FUNCTION_5X10 0x04 #define LCD_SOFT_RESET 0x30 // Set CG RAM Address --------- 0b01xxxxxx (Character Generator RAM) #define LCD_SET_CGADR 0x40 #define LCD_GC_CHAR0 0 #define LCD_GC_CHAR1 1 #define LCD_GC_CHAR2 2 #define LCD_GC_CHAR3 3 #define LCD_GC_CHAR4 4 #define LCD_GC_CHAR5 5 #define LCD_GC_CHAR6 6 #define LCD_GC_CHAR7 7 // Set DD RAM Address --------- 0b1xxxxxxx (Display Data RAM) #define LCD_SET_DDADR 0x80 #define LCD_GOTO_HOME LCD_SET_DDADR #define LCD_GOTO_LINE1 LCD_GOTO_HOME #define LCD_GOTO_LINE2 LCD_SET_DDADR+0x40 #define lcd_wait_ready()\ LCD_E=1; \ LCD_RS=0; \ LCD_RW=1; \ LCD_DATA=0x80; \ while((LCD_DATA & 0x80)) \ { \ LCD_E=0; \ LCD_E=1; \ } \ LCD_E=1; \ LCD_RW=0; #define lcd_cmd(c) \ lcd_wait_ready(); \ LCD_RS=0; \ LCD_DATA=c; \ LCD_E=0 #define lcd_chr(c) \ lcd_wait_ready(); \ LCD_RS=1; \ LCD_DATA=c; \ LCD_E=0 #endif