Character LCM (cont.)

Report
[Lab11] Character LCM
Deploy LCM
Example
Exercise
Character LCM
In this lecture, we use YJD1602A-1 as
LCD module to display 16 characters, 2
lines information.
Character LCM (cont.)
Character LCM (cont.)
YJD1602A-1 data sheet
4-bits or 8-bits interface avaliable
Power supply: 5V±10%
Character LCM (cont.)
Vss : Connect to GND.
VDD: Connect to P9_7, +5V from BBIO.
V0: For adjusting the contrast. Connect to GND.
RS: Register Select. Connect to P8_12, control
by program.
R/W: Read from LCM or write to LCM.
Connect to GND for write only.
Character LCM (cont.)
E: Enable Signal Signal, Connect to P8_14,
control by program.
DB0-DB3: Data bus used in 8 bits transfer, did
not use in this lecture.
DB4-DB7: Data bus for both 4 and 8 bits
transfer. Connect to P8_16, P8_18, P8_20,
P8_22.
BLA and K: Power for BackLight.
A for +5V and K for GND.
Character LCM (cont.)
 We are going to implement functions
Including:
 lcdcommand(str) for giving instructions
to LCM
 lcdprint(str) for giving string to LCM.
 setup() for initial setting.
 loop() for discribe main function’s action
control.
Character LCM (cont.)
Example:
Show a string and Beaglebone
uptime on the LCM.
Character LCM (cont.)
Source code:
from bbio import *
from datetime import timedelta
import time
import datetime
import os
import sys
usleep = lambda x : time.sleep(x/1000000.0) #generate a microsecond delay
iomap = [GPIO1_12, GPIO0_26, GPIO1_5, GPIO1_31, GPIO2_1, GPIO1_14]
Character LCM (cont.)
def lcdcommand(str) :
digitalWrite(iomap[1], 1)
usleep(500)
digitalWrite(iomap[0], 0)
iteration = 0
for idr in str:
digitalWrite(iomap[iteration+2], int(idr))
iteration = iteration + 1
if iteration == 4:
iteration = 0
usleep(100)
digitalWrite(iomap[1], LOW)
usleep(100)
digitalWrite(iomap[1], HIGH)
usleep(500)
return
Character LCM (cont.)
def lcdprint(str) :
for char in str:
bitmap = bin (ord(char)) [2:].zfill(8)
digitalWrite(iomap[1], 1)
usleep(20)
digitalWrite(iomap[0], 1)
iteration = 0
for idr in bitmap:
digitalWrite(iomap[iteration+2], int(idr))
iteration+= 1
if iteration == 4:
iteration = 0;
usleep(20)
digitalWrite(iomap[1], LOW)
usleep(20)
digitalWrite(iomap[1], HIGH)
usleep(20)
return
Character LCM (cont.)
def setup():
sys.stdout.write(“Python YJD1602A-1 LCD Driver”)
sys.stdout.write(‘\n’)
pinMode(iomap[0], OUTPUT)
pinMode(iomap[1], OUTPUT)
pinMode(iomap[2], OUTPUT)
pinMode(iomap[3], OUTPUT)
pinMode(iomap[4], OUTPUT)
pinMode(iomap[5], OUTPUT)
sys.stdout.write(“Setting Up Screen”)
sys.stdout.write(‘\n’)
lcdcommand(‘0011’) #Initialization Sequence
lcdcommand(‘0011’) #Initialization Sequence
lcdcommand(‘0011’) #Initialization Sequence
lcdcommand(‘0010’) #4BIT Mode
Character LCM (cont.)
lcdcommand(‘00000001’) # Reset
lcdcommand(‘00001100’) # Display On
sys.stdout.write(“Transferring LCD Control to main loop”)
sys.stdout.write(‘\n’)
sys.stdout.write(“Process PID: “)
sys.stdout.write(str(os.getpid()))
sys.stdout.write(‘\n’)
Character LCM (cont.)
def loop():
with open('/proc/uptime', 'r') as f:
uptime_seconds = float(f.readline().split()[0])
uptime_string = str(datetime.timedelta(seconds = uptime_seconds))
pid = str(os.getpid())
lcdcommand('10000000') #upper line display
lcdprint("B-Bone Uptime")
lcdcommand('11000000') #lower line display
lcdprint(uptime_string)
usleep(1000) #1ms delay
run(setup,loop)
Character LCM (cont.)
Character LCM (cont.)
Exercise:
 Show your student ID and “exercise11” on each
line.
Pin Configuration
END

similar documents