![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
![]() |
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Demonstration
Parts:
Hookup:
BX-24 programming:
This program sends data out to the shift register and 'counts' in binary: 0000_0001, 0000_0010, 0000_0011, etc.
Option Explicit
'A basicX function driver module for powering a 40x2 LCD display
'controls init and basic writing functions
'This driver assumes that the 8bit input pins of the LCD are
'connected to the BX special register PORTC which consists
'of pins 5 - 12 inclusive, and can be addressed directly.
'The MSB of the lcd input starts with pin 5, the LSB of the
'lcd input ends with pin 12
'Register Select Pin
const lcd_rs as byte = 13
'Read/Write pin
const lcd_rw as byte = 14
'Enable pin
const lcd_en as byte = 15
dim myString as string
dim force_sensor as integer
Public Sub Main()
call delay(0.5) 'standard startup delay
call init_lcd() 'initialize the lcd
do
force_sensor = getADC(16)
debug.print "force_sensor = " ; cstr(force_sensor)
if (force_sensor < 500) then
myString = "push more!"
call printf(myString)
else
myString = "ouch!"
call printf(myString)
end if
call delay(2.0)
call clearScreen()
loop
End Sub
''''''''''''''''''''''''''''''''''''''''
'LCD DRIVER CODE '
''''''''''''''''''''''''''''''''''''''''
public sub printf(ByRef printData as string)
call startText()
dim character as string * 1
dim counter as byte
dim printpass as byte
for counter = 1 to cbyte(len(printData))
character = mid(printData, counter, 1)
printpass = asc(character)
Register.portC = printpass
call sendData()
next
end sub
public sub clearScreen()
call startFunction()
Register.portC = bx0000_0001
call sendData()
call startText()
end sub
public sub init_lcd()
'sends the proper setup signals to initialize the lcd
register.ddrc = bx1111_1111
'Setup the cursor and home location
call startFunction()
Register.portC = bx0000_1111 'set the cursor style
call sendData()
Register.portC = bx0011_1000 'set display to 2line, 5x7 character, 8bit data
call sendData()
Register.portC = bx0000_0001 'clear screen
call sendData()
end sub
public sub startFunction()
'sets up the lcd values to send a function variable
call lcdEN(1) 'bring enable high
call lcdRW(0) 'set the read write register to write
call lcdRS(0) 'set the register to function
end sub
public sub startText()
call lcdEN(1) 'bring enable high
call lcdRW(0) 'bring read write register to write
call lcdRS(1) 'set the register to text
end sub
public sub lcdRS(byVal state as byte)
call putpin(lcd_rs, state)
end sub
public sub lcdRW(byVal state as byte)
call putpin(lcd_rw, state)
end sub
public sub lcdEN(byVal state as byte)
call putpin(lcd_en, state)
end sub
public sub sendData()
call putpin(lcd_en, 0) 'pulse the enable to tell the lcd to grab data
call putpin(lcd_en, 1)
end sub
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
References
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LCDs · Introduction to Physical Computing · Prof. Tom Igoe | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||