Controlling LCD Tutorial with only o/p and delay icons.

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Controlling LCD Tutorial with only o/p and delay icons.

Post by medelec35 »

This is a tutorial with a difference. Using 18F4455 (can change target device of course :p )
The attached flowchart shows how to initialise LCD, display the word Hello and finally make the cursor blink, all without the use of any LCD component macros or C blocks.
The only Icons used are delays and port outputs.
Hopefully this should make it less daunting to follow than typical datasheets:
http://docs-europe.electrocomponents.co ... 6dda16.pdf
By following icons you should be able to see how Enable(E) and Register select (RS) is used for control and data functions.
Once you have learned how to control the LCD, it should be much easier to create a customised Cblock to produce your own customised characters and functions.
Attachments
18F4455 LCD Port D.fcf
(17.63 KiB) Downloaded 792 times
Martin

singhdeol
Posts: 30
Joined: Sat Dec 18, 2010 6:07 am
Has thanked: 6 times
Been thanked: 2 times
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by singhdeol »

Thx for the post

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by brandonb »

martin, i was working on trying to do the same thing as post, i created a macro that takes a byte, splits to two nibbles, splits to 4 pins and sends high nibble followed by low nibble, when i looked at the datasheet on mine its confusing, was hoping to understand how to control and lcd, heres what i have so far
initialize part i copied from lcd start and sent those bytes out one after another, pretty sure that part works?
after that for instructions and data is where the problem is as i dont know what to do since i dont understand what im suppose to do.... i have
r/s 0 to send instruction and 1 to send data
enable high and pulse it low after every nibble
does the flowchart look right at this point?
can you explain the commands and how i should look at it, it looks really simple in the explainations, was hoping you could explain it to me, since when you explain things it seems to make sense to me :wink:
here is the lcd that im using, to note the matix component macro works perfect for this display, datasheet is at the bottom of the page, ..... thank for looking in to this for me
http://microcontrollershop.com/product_ ... iuguturur1
Attachments
BIT MASKING FOR LCD.fcf
(17.19 KiB) Downloaded 441 times

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by brandonb »

holy **** i figured it out, i had the pins in the wrong order (my bad) :roll:
display flashes message on hardware below
BIT BANGED LCD.fcf
(17.17 KiB) Downloaded 483 times
... to add byte_to_nibble macro works best set up with delays as shown here
connections are as would be shown in flowcode
data0 d5
data1 d4
data2 d3
data3 d2
rs d7
en d6
Attachments
lcd shifting bits.jpg
lcd shifting bits.jpg (61.28 KiB) Viewed 13321 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by Enamul »

Well done...You must be feeling the happiness of crossing mount Everest :mrgreen:
Enamul
University of Nottingham
enamul4mm@gmail.com

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by brandonb »

this is for danny to show a simplier way of doing it :D
--- hardware ---
data0=c0
data1=c1
data2=c2
data3=c3
rs=c5
en=c4
wr=tied to ground(write only mode)
lcd_masking.jpg
lcd_masking.jpg (64.66 KiB) Viewed 13284 times
in this fcf i took the lcd_byte variable and sent it to the output pins for data0-3 by useing bit masking,
in binary bits 7-0 have these values <128 64 32 16 8 4 2 1>
so if you have ascii char 'F' which is represented by the decimal number 70, it would look like this with the binary position value
0 1 0 0 0 1 1 0
128 64 32 16 8 4 2 1
-------------------------
so if we want to send the high nibble (top 4 bytes) to the lcd you can think of it like this:
portc.c3 = lcd_byte & 128
portc.c2 = lcd_byte & 64
portc.c1 = lcd_byte & 32
portc.c0 = lcd_byte & 16
so we are passing:
c3=0
c2=1
c1=0
c0=0
because for bit positions we get:
7=128 returned value of 0
6=64 returned value of 1
5=32 returned value of 0
4=16 returned value of 0
then toggle enable pin high for 100 microsecond then low for 100 microseconds
send the low 4 bytes in same manner as above but with bitwise and masking of 8,4,2,1, toggle enable high for 100 microseconds, then low for 100 microseconds, followed by 2 millisecond delay so lcd module can process the 4 combined nibbles that were sent

to initialize display:
set rs to low since we are sending a command,then send these numbers
51,50,44,6,12
to clear:
set rs low for command, and send a 1
to set cursor:
set rs low for command,
to return to home you can simply send 2
but to send anything else you have to refer to this chart
ddram char position.jpg
ddram char position.jpg (28.8 KiB) Viewed 13287 times
you still have to have rs low when you send this but the tricky part is you have to find the position on the chart, like in example flowchart i show "hi!" in the middle of the top row,
to do this i wanted to print starting at top line position 6!
which you would think that you have to send 6 out to lcd, but there is one extra step that you have to do,
for the lcd to recognize that its a cursor setting operation you have to also set bit 7 high with the message
to do this i did this
lcd_byte=6
lcd_byte=lcd_byte|1<<7
now we have this in binary to send how as a special cursor command
10000110
we can now send out characters to be displayed on lcd screen starting at the location 0,6
to do this rs is set high to accept data!!!
then to simplify this we just send out ascii char's with the notation of ' ' before and after the letter like this:
'H'
i kept the example simple with out using arrays or tables to send out data,
so to make this work do this
lcd_byte='H'
call macro for lcd_making
lcd_byte='I'
call macro for lcd_making
lcd_byte='!'
call macro for lcd_making
note the internals of the lcd automaticly advance the position when you send next char data
hope this helps you out in understanding how the flowchart and lcd works
for danny simple lcd example.fcf
(13.2 KiB) Downloaded 476 times

DannyBerry
Posts: 29
Joined: Tue Aug 30, 2011 9:20 pm
Has thanked: 11 times
Been thanked: 1 time
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by DannyBerry »

to initialize display:
set rs to low since we are sending a command,then send these numbers
51,50,44,6,12
How did you get these numbers Brandon?

DannyBerry
Posts: 29
Joined: Tue Aug 30, 2011 9:20 pm
Has thanked: 11 times
Been thanked: 1 time
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by DannyBerry »

Oh..wait I see it now ...those are the initialization numbers in converted from hex to decimal. :D

LCD initialize
0x33,....51
Set for 4 bit operation
0x32,.....50
Set for 2 line LCD
0x2c,.....44
Select move after write
0x06,.....6
disp. on cursor off blink off
0x0c......12

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by brandonb »

yes, i borrowed those from the matrix c code cd, the datasheet for this display is really screwed up on that part, but it does send 0011 three times to get it into 4 bit mode then 0010
here is the snippet from the cd

Code: Select all

/*  LCD initialize                */
    0x33,
/*  Set for 4 bit operation       */
    0x32,
/*  Set for 2 line LCD            */
    0x2c,
/*  Select move after write       */
    0x06,
/*  disp. on cursor off blink off */
    0x0c

the intitialization section is this
0011 0011
0011 0010
0000 0110
0000 1100
give it a try with the 16f1938, then modify it to say different things on different lines,
you can also try the different commands and such to make it do different things
have fun

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by brandonb »

was playing around and realized i could break a string variable down like an array and send the characters out one byte at a time, check it out, sent two strings out to display, also to send numbers would be really easy as well since would be sending them out one digit at a time it would be number+48 for the ascii equivelant, the trick is knowing how many char's are in the number and string, would be fairly easy to calculate that
44pin_lcd_macros.fcf
(23.28 KiB) Downloaded 412 times

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by brandonb »

think i might have it,
initializes
clears and returns to home
prints number variables 0-9999999
prints string variables and termainates at last letter
full cursor placement top line 0-15 bottom line 64-79
give it a try and tell me what you think?
playing with strings.fcf
(37.98 KiB) Downloaded 407 times
here is a screen shot of program
100_1105.gif
100_1105.gif (157.83 KiB) Viewed 13206 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Controlling LCD Tutorial with only o/p and delay icons.

Post by medelec35 »

I have given it a try.

It's very cleverly done indeed.
Works superbly
Thanks for posting

Martin
Martin

Post Reply