Professional Documents
Culture Documents
Chapter 6 - LCD
Chapter 6 - LCD
Chapter 6 - LCD
EMBEDDED SYSTEM
IN INDUSTRY
CHAPTER 6:
LCD
Home Cursor:
This returns the cursor to the home position, returns a shifted
display to the correct position, and sets the display data (DD)
RAM address to 0. Its line settings are as follows:
#set GPIO.out
GPIO.setup(LCD_E, GPIO.OUT) # E
GPIO.setup(LCD_RS, GPIO.OUT) # RS
GPIO.setup(LCD_D0, GPIO.OUT) # DB0
GPIO.setup(LCD_D1, GPIO.OUT) # DB1
GPIO.setup(LCD_D2, GPIO.OUT) # DB2
GPIO.setup(LCD_D3, GPIO.OUT) # DB3
GPIO.setup(LCD_D4, GPIO.OUT) # DB4
GPIO.setup(LCD_D5, GPIO.OUT) # DB5
GPIO.setup(LCD_D6, GPIO.OUT) # DB6
GPIO.setup(LCD_D7, GPIO.OUT) # DB7
'''
Function Name :lcd_string(message,line)
Function Description :print the data on lcd
'''
def lcd_string(message):
# Send string to display
message = message.ljust(LCD_WIDTH," ")
for i in range(LCD_WIDTH):
lcd_byte(ord(message[i]),LCD_CHR)
NGUYEN THANH NGHIA 28
Chapter 6: LCD
4. Application
4.1 Display information on LCD
Code:
def lcd_goto_xy(x,y): # dua con tro den toa do (x,y)
(x:0-1, y:0-15)
dc=(0x80,0xC0)
lcd_byte(dc[x]+y,LCD_CMD)
time.sleep(0.0005)
#set GPIO.out
GPIO.setup(LCD_E, GPIO.OUT) # E
GPIO.setup(LCD_RS, GPIO.OUT) # RS
GPIO.setup(LCD_D0, GPIO.OUT) # DB0
GPIO.setup(LCD_D1, GPIO.OUT) # DB1
GPIO.setup(LCD_D2, GPIO.OUT) # DB2
GPIO.setup(LCD_D3, GPIO.OUT) # DB3
GPIO.setup(LCD_D4, GPIO.OUT) # DB4
GPIO.setup(LCD_D5, GPIO.OUT) # DB5
GPIO.setup(LCD_D6, GPIO.OUT) # DB6
GPIO.setup(LCD_D7, GPIO.OUT) # DB7
'''
Function Name :lcd_string(message,line)
Function Description :print the data on lcd
'''
def lcd_string(message):
# Send string to display
message = message.ljust(LCD_WIDTH," ")
for i in range(LCD_WIDTH):
lcd_byte(ord(message[i]),LCD_CHR)
NGUYEN THANH NGHIA 36
Chapter 6: LCD
4. Application
4.2 Clock counter and display on LCD
Code:
def lcd_goto_xy(x,y): # dua con tro den toa do (x,y)
(x:0-1, y:0-15)
dc=(0x80,0xC0)
lcd_byte(dc[x]+y,LCD_CMD)
time.sleep(0.0005)
The end!