geezer88
Senior Member
I can't help myself. I've started playing with the LCD and I can't stop. Here's a snippet that approximates an analog display with a pointer. It only has a resolution of the number of characters in a particular display, but for many applications that would be acceptable. It is also much faster than the previously posted bar graph with 80 positions. As before, this code runs on an 18M2 connected with the display through a four bit parallel arrangement. I used a spare touch input as a simple way to get analog data for testing.
tom
tom
Code:
#rem 6/6/11
This bit of code displays an arrow for an analog display.
Touch input for demo purposes
#endrem
'* Pin Assignments **************************************
'LCD pin 6 = SE = c.6 = pin 15 MPU
'LCD pin 4 = RS = c.7 = pin 16 MPU
'LCD pin 11 = D4 = b.4 = pin 10 MPU
'LCD pin 12 = D5 = b.5 = pin 11 MPU
'LCD pin 13 = D6 = b.6 = pin 12 MPU
'LCD pin 14 = D7 = b.7 = pin 13 MPU
'touch input c.0 Used for a source of variable input data to display
'* Symbols ************************************************
symbol LcdSE = c.6 'strobe data into display
symbol LcdRS = c.7 'set low for instruction, high for character entry
symbol LcdByte = b0 'data sent to LCD routines
symbol j = b1 'scratch byte
symbol position = b2 'current point position
symbol last = b3 'last pointer position
symbol huns = b4 'hundreds digit in bintoascii
symbol tens = b5 'tens digit in bintoascii
symbol ones = b6 'ones digit in bintoascii
'* Main Routine *******************************************
EEPROM 0, (14,14,14,14,14,31,14,4)
'This list of data creates five user defined characters that are called to make partially filled blocks
'0=no lines, 1=one line, 2=two lines, 3=three lines, 4=four lines
gosub LCD_Init 'get lcd ready
LcdByte = 64 'move to user memory slot 0
gosub LCD_WrIns
for j = 0 to 7 'write the data to LCD user memory
read j, LcdByte
gosub LCD_WrChr
next j
gosub LCD_init 're-initialize display - not sure this is needed
lcdbyte = 128 'move to first line, first position
gosub lcd_wrins
lcdbyte = 0 'address of our new character
gosub lcd_wrchr
last = 0 'last position of pointer
do 'for demo purpose this is simply looped continously
touch c.0, j 'get some data for testing
position = j / 16 'scale to 16 character length display, adjust for your display
if position <> last then 'only update if changed
lcdbyte = 128 + position'move to required position (128 is first position of first line)
gosub lcd_wrins
lcdbyte = 0 '0 prints the arrow
gosub lcd_wrchr
lcdbyte = 128 + last 'move to old position
gosub lcd_wrins
lcdbyte = 32 '32 prints a space over last arrow
gosub lcd_wrchr
last = position 'update last
endif
'****Print digits on second line****Remove if you don't want it
lcdbyte = 192 'move to second line, first position
gosub lcd_wrins
bintoascii position, huns, tens, ones 'break down input number so it can be displayed
lcdbyte = tens 'display tens
gosub lcd_wrchr
lcdbyte = ones 'display ones
gosub lcd_wrchr
'****end of digit print****
loop
end
'* Initialise LCD *****************************************
LCD_Init:
'set relevant pins to output
dirsb = %11110000
dirsc = %11000000
low LcdRS
low LcdSE
'wait for LCD to stabilise (>40ms after Vcc > 2.7V)
pause 100
'send 00110000 three times to initialise LCD by instruction
outpinsb = %00110000
pause 1
pulsout c.6,1000
pause 1
pulsout c.6,1000
pause 1
pulsout c.6,1000
pause 1
outpinsb = %00100000 'set to 4 bit mode
pause 1
pulsout c.6,1000
LcdByte = %00101000 'set interface
pause 1
gosub LCD_WrIns
LcdByte = %00001100 'enable display, no cursor
pause 1
gosub LCD_WrIns
LcdByte = %00000001 'clear and home cursor
pause 1
gosub LCD_WrIns
LcdByte = %00000110 'set cursor direction: movement
pause 1
gosub LCD_WrIns
return
'* Display Character On LCD *******************************
LCD_WrChr:
high LcdRS 'set RS high (write data)
pause 1
outpinsb = LcdByte and %11110000
pause 1
pulsout LcdSE,1
outpinsb = LcdByte * 16
pause 1
pulsout LcdSE,1
return
'* Send Instruction to LCD ********************************
LCD_WrIns:
low LcdRS 'set RS low (write instruction)
pause 1
outpinsb = LcdByte and %11110000
pause 1
pulsout LcdSE,1
outpinsb = LcdByte * 16
pause 1
pulsout LcdSE,1
return
Attachments
-
47.3 KB Views: 157