Revision: 1342 Author: sebastien.lelong Date: Thu Sep 24 10:04:37 2009 Log: LCD tutorial, updated PDF and fix some links & API updates http://code.google.com/p/jallib/source/detail?r=1342
Added: /trunk/doc/dita/tutorials/code/blog_16f88_sl_lcd_hd44780_4.jal /trunk/doc/dita/tutorials/images/lcd_1.jpg /trunk/doc/dita/tutorials/images/lcd_16.jpg /trunk/doc/dita/tutorials/images/lcd_4bit.png /trunk/doc/dita/tutorials/images/lcd_bconn.jpg /trunk/doc/dita/tutorials/images/lcd_bpic.jpg /trunk/doc/dita/tutorials/images/lcd_bwhole.jpg /trunk/doc/dita/tutorials/images/lcd_connector.jpg /trunk/doc/dita/tutorials/images/lcd_jhd204a.jpg /trunk/doc/dita/tutorials/images/lcd_overview.jpg /trunk/doc/dita/tutorials/images/lcd_pins.png /trunk/doc/dita/tutorials/tutorial_lcd.xml Modified: /trunk/doc/dita/tutorials/tutorial_i2c2.xml /trunk/doc/dita/tutorials/tutorial_i2c3.xml /trunk/doc/dita/tutorials/tutorials.ditamap /trunk/doc/dita/tutorials/tutorials.pdf ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/code/blog_16f88_sl_lcd_hd44780_4.jal Thu Sep 24 10:04:37 2009 @@ -0,0 +1,113 @@ +-- ------------------------------------------------------ +-- Title: Test program for lcd_hd44780_4.jal +-- Author: Eur Van Andel, Copyright (c) 2008, all rights reserved. +-- Adapted-by: Rob Hamerling, Joep Suijs +-- Compiler: >=2.4g +-- +-- This file is part of jallib (http://jallib.googlecode.com) +-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php) +-- +-- Description: +-- This sample shows how to setup an LCD and writes +-- "Hello World" to the first line, using a string and the print library. +-- Line 3 and line 4 are used as well, but will work properly only on a 4x20 LCD. +-- A counter is printed to show the running forever loop. +-- -- +-- This file defines a test for JALLIB testing, using a test-board +-- defined by a BOARD file . +-- +-- Sources: +-- +-- Notes: +-- setup: an hd44780 compatible display, used in 4-bit mode. +-- +-- -------------------------------------------------------------------------- +-- +-- This file has been generated on Sun Jan 25 12:30:33 2009, from: +-- * board: board_16f88_sl.jal +-- * test : test_lcd_hd44780_4.jal +-- + + +;@jallib section chipdef +-- chip setup +include 16f88 + +;-- +-- We'll use internal oscillator. It work @ 8MHz +pragma target clock 8_000_000 +pragma target OSC INTOSC_NOCLKOUT +-- Specify no postscaler, ie. really runs @8MHz +OSCCON_IRCF = 0b_111 +pragma target WDT disabled -- no watchdog +pragma target LVP disabled -- no low-voltage programming +pragma target CCP1MUX RB0 -- ccp1 pin on B0 +pragma bootloader long_start -- for TinyBootloader + +;@jallib section lcd_hd44780_4 +-- LCD IO definition +var bit lcd_rs is pin_a6 -- LCD command/data select. +var bit lcd_rs_direction is pin_a6_direction +var bit lcd_en is pin_a7 -- LCD data trigger +var bit lcd_en_direction is pin_a7_direction + +var byte lcd_dataport is porta_low -- LCD data port +var byte lcd_dataport_direction is porta_low_direction +const byte LCD_ROWS = 4 -- 4 lines +const byte LCD_CHARS = 20 -- 20 chars per line +;@jallib section led +-- LED IO definition +var bit led is pin_b3 +var bit led_direction is pin_b3_direction +var bit led2 is pin_b1 +var bit led2_direction is pin_b1_direction + +enable_digital_io() + +led_direction = output + + +lcd_rs_direction = output +lcd_en_direction = output +lcd_dataport_direction = output + +include lcd_hd44780_4 -- LCD library with 4 data lines +include print -- formatted output library + +for 4 loop -- blink LED 4 times to indicate startup + LED = on + delay_100ms(2) + LED = off + delay_100ms(2) +end loop + +const byte str1[] = "Hello world!" -- define strings +const byte str2[] = "third line" +const byte str3[] = "fourth line" + +lcd_init() -- initialize LCD + +print_string(lcd, str1) -- show hello world! +lcd_cursor_position(2,0) -- to 3rd line +print_string(lcd, str2) +lcd_cursor_position(3,0) -- to 4th line +print_string(lcd, str3) + +var byte counter = 0 + +forever loop -- loop forever + + counter = counter + 1 -- update counter + lcd_cursor_position(1,0) -- second line + print_byte_hex(lcd, counter) -- output in hex format + delay_100ms(3) -- wait a little + + if counter == 255 then -- counter wrap + lcd_cursor_position(1,1) -- 2nd line, 2nd char + lcd = " " -- clear 2nd char + lcd = " " -- clear 3rd char + end if + +end loop + + ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_1.jpg Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_16.jpg Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_4bit.png Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_bconn.jpg Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_bpic.jpg Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_bwhole.jpg Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_connector.jpg Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_jhd204a.jpg Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_overview.jpg Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/lcd_pins.png Thu Sep 24 10:04:37 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/tutorial_lcd.xml Thu Sep 24 10:04:37 2009 @@ -0,0 +1,121 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd"> +<topic id="topic-1"> + <title>Interfacing a HD44780-compatible LCD display</title> + <abstract> + <p>In this "Step by Step" tutorial, we're going to (hopefully) have some fun with a LCD display. Particularly one compatible with HD44780 specifications, which seems to be most widely used.</p> + </abstract> + <prolog> + <author>Sébastien Lelong</author> + <publisher>Jallib Group</publisher> + <copyright> + <copyryear year="2009"/> + <copyrholder>Jallib Group</copyrholder> + </copyright> + </prolog> + <body> + <section> + <title>Setting up the hardware</title> + <p>As usual, there are <xref href="http://www.google.com/search?hl=en&q=lcd+hd44780" format="html">plenty resources</xref> on the web. I found <xref href="http://home.iae.nl/users/pouweha/lcd/lcd.shtml" format="html">this one</xref> quite nice, covering lots of thing. Basically, LCDs can be accessed with two distinct interfaces: <i>4-bit or 8-bit interfaces</i>. <i>4-bit interface requires less pins</i> (4 pins), but is somewhat slow, <i>8-bit interface requires more pins</i> (8 pins) but is faster. jallib comes with the two flavors, it's up to you deciding which is most important, but usually, pins are more precious than speed, particularly when using a 16F88 which only has 16 I/O pins (at best). Since 4-bit interface seems to be most used, and we'll use this one here...</p> + <p>So, I've never used LCD, to be honest. Most guys consider it as an absolute minimum thing to have, since it can help a lot when debugging, by printing messages. I tend to use serial for this... Anyway, I've been given a LCD, so I can't resist anymore :)</p> + <p>The LCD I have seems to be quite a nice beast ! It has 4 lines, is 20 characters long.</p> + <p><image href="images/lcd_overview.jpg" width="400" placement="break"/></p> + <p>Looking closer, "<i>JHD 204A</i>" seems to be the reference. Near the connector, only a "1" and a "16". No pin's name.</p> + <p><image href="images/lcd_jhd204a.jpg" placement="break"/></p> + <p><image href="images/lcd_1.jpg" placement="break"/></p> + <p><image href="images/lcd_16.jpg" placement="break"/></p> + <p>Googling the whole points to a forum, and at least a link to the <xref href="http://www.8051projects.net/e107_files/public/1231066792_13674_FT0_jm204aspec.pdf" format="pdf">datasheet</xref>. A section describes the "Pin Assignement". Now I'm sure about how to connect this LCD.</p> + <p><image href="images/lcd_pins.png" width="400" placement="break"/></p> + <p>For this tutorial, we're going to keep it simple:<ul> + <li>as previously said, we'll use 4-bit interface. This means we'll use DB4, DB5, DB6 and DB7 pins (respectively pin 11, 12, 13 and 14).</li> + <li>we won't read from LCD, so R/W pin must be grounded (pin 5)</li> + <li>we won't use contrast as well, V5 pin (or Vee) must be grounded (pin 3)</li> + </ul></p> + <p>Including pins for power, we'll use 10 pins out of the 16 available, 6 being connected to the PIC (RS, EN and 4 data lines).</p> + <p>For convenience, I soldered a male connector on the LCD. This will help when building the whole on a breadboard.</p> + <p><image href="images/lcd_connector.jpg" placement="break"/></p> + <p>So we now have everything to build the circuit. Here's the schematic. It also includes a LED, it will help us checking everything is ok while powering up the board.</p> + <p><image href="images/lcd_4bit.png" width="500" placement="break"/></p> + <p>Using a breadboard, it looks like this:</p> + <p><image href="images/lcd_bwhole.jpg" width="400" placement="break"/></p> + <p><image href="images/lcd_bpic.jpg" width="400" placement="break"/></p> + <p><image href="images/lcd_bconn.jpg" width="400" placement="break"/></p> + </section> + <section> + <title> Writing the software</title> + <p>For this tutorial, we'll use one of the available samples from <xref href="http://code.google.com/p/jallib/source/browse/" format="html">jallib repository</xref>. I took <xref href="http://code.google.com/p/jallib/source/browse/trunk/sample/16f88_lcd_hd44780_4.jal" format="jal">one</xref> for 16f88, and adapt it to my board (specifically, I wanted to use PORTA when connecting the LCD, and let PORTB's pins as is).</p> + <p>As usual, writing a program with jallib starts with configuring and declaring some parameters. So we first have to declare which pins will be connected:</p> + <p><codeblock> -- LCD IO definition +var bit lcd_rs is pin_a6 -- LCD command/data select. +var bit lcd_rs_direction is pin_a6_direction +var bit lcd_en is pin_a7 -- LCD data trigger +var bit lcd_en_direction is pin_a7_direction + +var byte lcd_dataport is porta_low -- LCD data port +var byte lcd_dataport_direction is porta_low_direction + +-- set direction +lcd_rs_direction = output +lcd_en_direction = output +lcd_dataport_direction = output</codeblock></p> + <p>This is, pin by pin, the translation of the schematics. Maybe except <codeph>porta_low</codeph>. This represents pin A0 to A3, that is pins for our 4 lines interface. <codeph>porta_high</codeph> represents pin A4 to A7, and <codeph>porta</codeph> reprensents the whole port, A0 to A7. These are just "shorcuts".</p> + <p>We also have to declare the <b>LCD geometry</b>:</p> + <p><codeblock>const byte LCD_ROWS = 4 -- 4 lines +const byte LCD_CHARS = 20 -- 20 chars per line</codeblock></p> + <p>Once declared, we can then include the library and initialize it:</p> + <p><codeblock>include lcd_hd44780_4 -- LCD library with 4 data lines +lcd_init() -- initialize LCD</codeblock></p> + <p> +For this example, we'll also use the <filepath>print.jal</filepath> library, which provides nice helpers when printing variables.</p> + <p><codeblock>include print</codeblock></p> + <p> +Now the main part... How to write things on the LCD.</p> + <ul> + <li>You can either use a procedure call: <codeph>lcd_write_char("a")</codeph></li> + <li>or you can use the pseudo-variable : <codeph>lcd = "a"</codeph></li> + <li><codeph>lcd_cursor_position(x,y)</codeph> will set the cursor position. x is the line, y is the row, starting from 0</li> + <li>finally, <codeph>lcd_clear_screen()</codeph> will, well... clear the screen !</li> + </ul> + <p><xref href="http://jallib.googlecode.com/svn/trunk/doc/html/lcd_hd44780_4.html" format="html">Full API documentation</xref> is available on <xref href="http://jallib.googlecode.com/svn/trunk/doc/html/index.html" format="html">jalapi</xref>.</p> + <p>So, for this example, we'll write some chars on each line, and print an increasing (and incredible) counter:</p> + <p><codeblock>const byte str1[] = "Hello world!" -- define strings +const byte str2[] = "third line" +const byte str3[] = "fourth line" + +print_string(lcd, str1) -- show hello world! +lcd_cursor_position(2,0) -- to 3rd line +print_string(lcd, str2) +lcd_cursor_position(3,0) -- to 4th line +print_string(lcd, str3) + +var byte counter = 0 + +forever loop -- loop forever + + counter = counter + 1 -- update counter + lcd_cursor_position(1,0) -- second line + print_byte_hex(lcd, counter) -- output in hex format + delay_100ms(3) -- wait a little + + if counter == 255 then -- counter wrap + lcd_cursor_position(1,1) -- 2nd line, 2nd char + lcd = " " -- clear 2nd char + lcd = " " -- clear 3rd char + end if + +end loop</codeblock></p> + <p>The full and ready-to-compile code is available on jallib repository:<ul> + <li> + <xref href="http://code.google.com/p/jallib/source/browse/trunk/doc/dita/tutorials/code/blog_16f88_sl_lcd_hd44780_4.jal" format="jal">blog_16f88_sl_lcd_hd44780_4.jal</xref> + </li> + </ul></p> + <p>You'll need last jallib-pack, available on jallib's <xref href="http://code.google.com/p/jallib/downloads/list" format="html">download section</xref>.</p> + </section> + <section> + <title>How does this look when running ?</title> + <p>Here's the video !</p> + <p><xref href="http://www.youtube.com/watch?v=hIVMuaz8OS8" format="html">http://www.youtube.com/watch?v=hIVMuaz8OS8</xref></p> + </section> + <p><i>Sébastien Lelong</i></p> + </body> +</topic> ======================================= --- /trunk/doc/dita/tutorials/tutorial_i2c2.xml Tue Sep 22 07:13:08 2009 +++ /trunk/doc/dita/tutorials/tutorial_i2c2.xml Thu Sep 24 10:04:37 2009 @@ -35,8 +35,8 @@ <p>Note master will send its i2c frame to a specific address, which don't necessarily need to be the same as the slave one (and I recommand to use different addresses, just to make sure you understand what's going on).</p> <p>What about the sources ? <xref href="http://code.google.com/p/jallib/downloads/list" format="html">Download</xref> last jallib pack, and check the following files (either in <filepath>lib</filepath> or <filepath>sample</filepath> directories):<ul> <li><xref href="http://jallib.googlecode.com/svn/trunk/include/peripheral/i2c/i2c_hw_slave.jal" format="jal">i2c_hw_slave.jal</xref>: main i2c library</li> - <li><xref href="http://jallib.googlecode.com/svn/trunk/sample/by_device/16f88/16f88_i2c_sw_master_check_bus.jal" format="jal">16f88_i2c_sw_master_check_bus.jal</xref>: code for master</li> - <li><xref href="http://jallib.googlecode.com/svn/trunk/sample/by_device/16f88/16f88_i2c_hw_slave_check_bus.jal" format="jal">16f88_i2c_hw_slave_check_bus.jal</xref>: code for slave</li> + <li><xref href="http://jallib.googlecode.com/svn/trunk/sample/16f88_i2c_sw_master_check_bus.jal" format="jal">16f88_i2c_sw_master_check_bus.jal</xref>: code for master</li> + <li><xref href="http://jallib.googlecode.com/svn/trunk/sample/16f88_i2c_hw_slave_check_bus.jal" format="jal">16f88_i2c_hw_slave_check_bus.jal</xref>: code for slave</li> </ul></p> <p>The main part of the slave code is the way the initialization is done. A constant is declared, telling the library to enable Start/Stop interrupts.</p> <p><codeblock>const SLAVE_ADDRESS = 0x23 -- whatever, it's not important, and can be @@ -77,9 +77,9 @@ <li>if so, blinks 'til the end of time (or your battery)</li> </ul></p> <p>Now, go compile both samples, and program two PICs with them. With a correct i2c bus setting, you should see the following:</p> - <p>video</p> + <p><xref href="http://www.youtube.com/watch?v=NalAkRhFP-s" format="html">http://www.youtube.com/watch?v=NalAkRhFP-s</xref></p> <p>On this next video, I've removed the pull-ups resistors, and it doesn't work anymore (slave doesn't high speed blink its LED).</p> - <p>video</p> + <p><xref href="http://www.youtube.com/watch?v=cNK_cCgWctY" format="html">http://www.youtube.com/watch?v=cNK_cCgWctY</xref></p> <p>Next time (and last time on this topic), we'll see how to implement the state machine using jallib, defining callback for each states.</p> <p><i>Sébastien Lelong</i></p> </section> ======================================= --- /trunk/doc/dita/tutorials/tutorial_i2c3.xml Wed Sep 23 02:53:09 2009 +++ /trunk/doc/dita/tutorials/tutorial_i2c3.xml Thu Sep 24 10:04:37 2009 @@ -1,5 +1,5 @@ <?xml version='1.0' encoding='UTF-8'?> -<!-- This document was created with Syntext Serna Free. --><!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd" []> +<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd"> <topic id="topic-1"> <title>Building an i2c slave with jallib (part 3)</title> <abstract> @@ -21,7 +21,7 @@ <p/> <section> <title>Building the i2c master</title> - <p>Let's start with the easy part. What will master do ? Just collect characters from a serial link, and convert them to i2c commands. So you'll need a PIC to which you can send data via serial. I mean you'll need a board with serial com. capabilities. I mean we won't do this on a breadboard... There are plenty out there on the Internet, pick your choice. If you're interested, you can <xref href="http://sirbot.org/sirbot-modules/main_board/" format="html">find one</xref> on my <xref href="http://sirbot.org/" format="html">SirBot</xref> site: dedicated to 16f88, serial com. available, and i2c ready (pull-ups resistors).<!--TODO: talk about Jaluino here !--></p> + <p>Let's start with the easy part. What will master do ? Just collect characters from a serial link, and convert them to i2c commands. So you'll need a PIC to which you can send data via serial. I mean you'll need a board with serial com. capabilities. I mean we won't do this on a breadboard... There are plenty out there on the Internet, pick your choice. If you're interested, you can <xref href="http://sirbot.org/sirbot-modules/main_board/" format="html">find one</xref> on my <xref href="http://sirbot.org/" format="html">SirBot</xref> site: dedicated to 16f88, serial com. available, and i2c ready (pull-ups resistors).</p> <p> It looks like this:</p> <p><image href="images/i2c_seb_mainboard_up.jpg" width="400" placement="break"/></p> @@ -150,19 +150,19 @@ <p> I use a connector adapted with a PCB to connect my main board with my breadboard. Connector's wires provide power supply, 5V-regulated, so no other powered wires it required.</p> <p><fig> - <image placement="break" href="images/i2c_connector.jpg" width="400"/> + <image href="images/i2c_connector.jpg" width="400" placement="break"/> <p><i>Connector, with power wires </i></p> </fig></p> <p><fig> - <image placement="break" href="images/i2c_details.jpg" width="400"/> + <image href="images/i2c_details.jpg" width="400" placement="break"/> <p><i>Everything is ready...</i></p> </fig></p> <p><fig> - <image placement="break" href="images/i2c_crimescene.jpg" width="400"/> + <image href="images/i2c_crimescene.jpg" width="400" placement="break"/> <p><i>Crime scene: main board, breadboard and battery pack</i></p> </fig></p> <p>Once connected, power the whole and use a terminal to test it. When pressing "a", you'll get a "a" as an echo from the master, then "b" as result from the slave.</p> - <p><image placement="break" href="images/i2c_pseudoecho.png"/></p> + <p><image href="images/i2c_pseudoecho.png" placement="break"/></p> </section> <section> <title>What now ?</title> @@ -170,5 +170,6 @@ <p>i2c is a widely used protocol. Most of the time, you access i2c devices, acting as a master. We've seen how to be on the other side, on the slave side. Being on the slave side means you can build modular boards, accessible with a standard protocol. For instance, I've built a <xref href="http://sirbot.org/sirbot-modules/dc-motor-controller-board" format="html">DC motor controller</xref> daughter board using this. It's a module, a unit on its own, just plug, and send/receive data, with just two wires.</p> <p>And I also plan to build a LCD controller board, but that's for another "Step by Step" post :)<fn>and actually this LCD controller was being built by Jallib guys (Joep, Albert, Richard, Rob), and known as "LCD interface" project. See <xref href="http://code.google.com/p/jallib/source/browse/#svn/trunk/project/lcd_interface" format="html">here</xref> for more.</fn></p> </section> + <p><i>Sébastien Lelong</i></p> </body> </topic> ======================================= --- /trunk/doc/dita/tutorials/tutorials.ditamap Wed Sep 23 02:53:09 2009 +++ /trunk/doc/dita/tutorials/tutorials.ditamap Thu Sep 24 10:04:37 2009 @@ -39,5 +39,6 @@ </chapter> <chapter href="tutorial_externals.xml"> <topicref href="tutorial_gp2d02.xml"/> + <topicref href="tutorial_lcd.xml"/> </chapter> </bookmap> ======================================= --- /trunk/doc/dita/tutorials/tutorials.pdf Wed Sep 23 02:53:09 2009 +++ /trunk/doc/dita/tutorials/tutorials.pdf Thu Sep 24 10:04:37 2009 Binary file, no diff available. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jallib?hl=en -~----------~----~----~----~------~----~------~--~---
