tag:blogger.com,1999:blog-91308548043109330312024-02-09T00:43:32.426+05:30Learn About Robotics And Robo ProjectGet in-depth knowledge about robotics. Be it micro controller or solar or motor based learn it here.
robotics developer studio vex robotics competition robotics studio us robotics robot robotics modemJatinhttp://www.blogger.com/profile/16882648731915542759noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-9130854804310933031.post-21904651101447004712008-12-24T02:40:00.000+05:302008-12-24T02:46:26.987+05:30Using a Dot Matrix LCD With a Microcontroller<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_q63EJ4Kf-3U/SVFVGjQfkwI/AAAAAAAAABk/jfB6JNGqSFY/s1600-h/muc.gif"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 186px;" src="http://1.bp.blogspot.com/_q63EJ4Kf-3U/SVFVGjQfkwI/AAAAAAAAABk/jfB6JNGqSFY/s320/muc.gif" alt="" id="BLOGGER_PHOTO_ID_5283097408914297602" border="0" /></a><br />This article shows how to hook up a LCD screen to your microcontroller.<br /><br /><br />LCD displays are a great way to add output to your robot - they can be a very useful debugging aid and also can make controlling the robot much easier (setting options, viewing battery voltage etc.). <blockquote> One main drawback is that they require up to 10 IO lines to use (although this can be reduced to 6 - see below). Serial controllers are available, but I will discuss how to control the displays using a parallel bus. </blockquote> <blockquote> The display I am using is made by Trident but uses a standard instruction set. These instructions are for the Hitachi (HD44780) chipset, which is a common standard. A cheap display can be had for around £7 ($10), but add a few pounds (or dollars) for a backlight. </blockquote> <blockquote> As I mentioned, the display can be used with either 6 or 10 output lines. If the display is set to 8 bit operation (where the data bus contains 8 connections between the display and controller) or 4 bit operation. In 4 bit mode, the code for each instruction or character must be sent in 2 parts; the first 4 bits (the most significant bits) and then the second 4 bits. As well as the data lines, there are 3 control lines; E, RS and RW (Enable, Register Select and Read/Write). For most operations, the Read/Write line can simply be tied to 0v. </blockquote> <blockquote> Unfortunately, I have only had experience using the display in 8 bit mode so this is what I will discuss in this article. However, the Hitachi datasheet details how to use the 4 bit mode.<br /> The code in this article is written in Motorola HC11 assembly (although I actually developed in on the HC05), but can easily be modified for any microcontroller. </blockquote> <blockquote> Initializing the Display<br /> Before data can be sent, the display must be set up. This is done by sending a series of commands, and between each, ’strobing’ (turning on then off) the Enable pin (E). Below is a routine to send the relevant codes to the display setting it up with the most common settings.<br /> The code assumes the 8 data lines are connected to port B (output-only port) and RS and E are connected to bits 0 and 1 of port C. <p> </p> <p align="left">SetupLCD<br /> ldaa #$ff<br /> staa ddrc ; Set port C as an output port </p><p align="left">ldaa #$01 ; Clear screen<br /> jsr ctrllong ; Need longer wait for these commands<br /> ldaa #$02 ; Home cursor<br /> jsr ctrllong<br /> ldaa #$38 ; Set data bus width, no. of lines, font size<br /> jsr lcdctrl<br /> ldaa #$0c ; Turn on display, no cursor<br /> jsr lcdctrl<br /> ldaa #$06 ; Set entry mode (see text)<br /> jsr lcdctrl ; LCD now set up<br /> rts </p></blockquote> <p align="center"> </p><p align="center">The ‘ctrllong’ and ‘lcdctrl’ subroutines simply strobe the Enable line and pause for a while to let the display execute the instruction. Below is the code for this;<br /></p><blockquote> <p align="left"> <br /> lcdctrl<br /> stab tempb ; Save registers<br /> staa tempa<br /> staa portb ; Put data onto port B<br /> bset 1,portc ; Strobe ‘E line<br /> bclr 1,portc<br /> jsr wait120us ; Wait a while<br /> ldaa tempa ; Restore registers<br /> ldab tempb<br /> rts </p><p align="left">ctrllong<br /> stab tempb ; Save registers<br /> staa tempa<br /> staa portb ; Put data onto port B<br /> bset 1,portc ; Strobe ‘E’ line<br /> bclr 1,portc<br /> jsr wait5ms ; Wait 5ms<br /> ldaa tempa ; restore registers<br /> ldx tempb<br /> rts </p><blockquote> <p align="left"> </p></blockquote> </blockquote> <p align="center">First of all, the contents of the ‘a’ and ‘b’ registers are stored in temporary variables and the data is stored at port B. The ‘E’ line is then strobed (bset and bclr stand for bit set and bit clear). Below are the pause routines (these depend on the clock frequency however). </p><blockquote> <p align="left">wait5ms<br /> ldaa #3 ; Change this value depending on clock frequency (assumes 4MHz crystal)<br /> outer<br /> ldab #$ff<br /> inner decb<br /> bne inner<br /> deca<br /> bne outer<br /> rts </p><p align="left">wait120us<br /> ldab #30<br /> loop120<br /> decb<br /> bne loop120<br /> rts </p></blockquote> <blockquote> Note: The timing of these delay routines is not critical; as long as the delays are longer than 5 milliseconds and 120 microseconds respectively, they should work fine. </blockquote> <blockquote> Now that the display is set up, the rest is easy! The display accepts characters in standard ASCII format, so the 8 bit code for a particular character is placed in the ‘a’ accumulator and another routine is executed. This time, the ‘Register Select’ line must be set to a ‘1′ first, to tell the display that we are sending data rather than an instruction. </blockquote> To send the letter ‘A’ to the display for example, the following code is used. <blockquote> <p align="left">ldaa #’A’ ; Print an ‘A’<br /> jsr lcddata<br /> here bra here ; Stop! </p><p align="left">lcddata<br /> stab tempb ; Save registers<br /> staa tempa<br /> staa portb ; Put data onto port B<br /> bset 0,portc ; Set ‘RS’ line to ‘1′<br /> bset 1,portc ; Strobe ‘E’ line<br /> bclr 1,portc<br /> bclr 0,portc ; Clear ‘RS’ line<br /> jsr wait120us ; Wait 120 us<br /> ldaa tempa ; restore registers<br /> ldx tempb<br /> rts </p></blockquote> That’s just about it - this code lets you set up the display and enter any character you want (There is a full character set on the Hitachi data sheet - this is an invaluable resource!). There are many more function however; You can create your own characters, read data from the display (this needs the R/W line though), and set the way in which data is entered onto the screen.Jatinhttp://www.blogger.com/profile/16882648731915542759noreply@blogger.com0