A Free Template From Joomlashack

A Free Template From Joomlashack

Sign in with a social network::

Powered by OneAll Social Login

Who is online

We have 31 guests online

Chat with us

LCD Character Displays PDF Print E-mail
Written by Jurij Mikeln   

Displaying text on an LCD is something that has always attracted newbies to programming. However, this involves many tasks which are less appealing to the newbies. To display data on an LCD, you have to perform 16 tasks if programming in asembler

Character LCD displays refer to 1x8, 2x16, 4x20 and other character LCD modules that are widely available at very affordable prices. When programming in assembly language, it takes 16 steps to display data on LCD. Let me show you some of the steps:

  • after power-up wait at least 15 msec,
  • pins RS and R/W are set to 0,
  • write 0x3 to D7 – D4 ,
  • set and reset pin E,
  • wait 5 msec... etc.

You can trust me when I say that displaying text on a character LCD is one of the easiest tasks when programming with Bascom. You just have to make sure that the configuration (and wiring connections of course!) of the LCD is correct and then it will display data, text or even custom made characters flawlessly. The configuration commands in Bascom are as follows:

Config Lcd=16*2               ‘we will use 2x16 LCD
Config Lcdbus=4               ‘4-bit data bus will  be used
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 ,_
Db7 = Portb.7 , E = Portb.2 , Rs = Portb.1

The first statement tells the compiler what type of LCD we are using. In our case we have used the 2x16 LCD. When using the 4x20 LCD, for example, we would write 20*4. You can find all possible LCDs in the Options/Compiler/LCD menu as shown in Figure 1. Note that if using the 2x8 LCD, we should write 16*1a – this is the only case in which the Bascom description does not match the physical layout of the LCD panel.

As seen in Figure 1 you can also select your LCD in this menu. It is, however, advisable to write the program definitions at the top of your program (just as you would set the microcontroller and other definitions). It’s easy to set one type of LCD in the menu and later, when using another LCD, simply forget to change the LCD type. This has happened to me many times. As a result, the program will not work as it should. So, it is good practice to define the LCD type at the top of the program, when programming in Bascom.

The next statement defines the bus mode we use to connect the LCD: 8 or 4 bits. I always use the 4-bit data bus. There are several reasons for that: the 4-bit data bus uses fewer of the microcontrollers’ pins and it’s nearly as fast as the 8-bit data bus. So far I have not needed the extra speed provided by the 8-bit data format.

Next, you have to define data pins DB7 – DB4, Enable and Rs pins. Assign them according to your hardware. If, by any chance

, you have to redesign the hardware, it’s easier to change the definition of the pins. You can also define the data pins on different ports, if that is required by your hardware. It’s much easier to change the definitions of the data pins within your Bascom program than to change the hardware.

That is all we have to define and now we are ready to display what we want. Here is the simplest way to display data with only one statement:

LCD “Text”; variable1; “  “; variable2

It is as simple as that. You will notice that displaying text (or constants, and signs such as +/- etc.) can be done within brackets like “This is test, 123 +/-@”. This combination of text, numbers and signs will appear on the LCD exactly as written between the brackets, including spaces. If displaying a variable, then we just write its name instead of variable1, variable2, as shown in the example statement above. If displaying more than one variable, make sure that you include blank spaces between them, in order to distinguish them on the display.

LCD Character Displays

2012_AVR_UK_59

Continue reading

Shop area

Last Updated on Wednesday, 01 August 2012 14:37
 
Joomla Templates: by JoomlaShack