Revision: 1436 Author: [email protected] Date: Fri Oct 30 23:58:47 2009 Log: Added Blink A Led Tutorial http://code.google.com/p/jallib/source/detail?r=1436
Added: /trunk/doc/dita/tutorials/images/blink_a_led /trunk/doc/dita/tutorials/images/blink_a_led/16f877_pin_info.bmp /trunk/doc/dita/tutorials/images/blink_a_led/16f877_pinout.bmp /trunk/doc/dita/tutorials/images/blink_a_led/Thumbs.db /trunk/doc/dita/tutorials/images/blink_a_led/blink_circuit.bmp /trunk/doc/dita/tutorials/images/blink_a_led/circuit.jpg /trunk/doc/dita/tutorials/images/blink_a_led/jalv2_dir.bmp /trunk/doc/dita/tutorials/images/blink_a_led/micropro_read_pic.jpg /trunk/doc/dita/tutorials/images/blink_a_led/programmer.jpg /trunk/doc/dita/tutorials/images/blink_a_led/serial_cable.jpg /trunk/doc/dita/tutorials/images/blink_a_led/serial_pinout.jpg /trunk/doc/dita/tutorials/images/blink_a_led/usb_to_serial.jpg /trunk/doc/dita/tutorials/tutorial_blink_a_led.xml Modified: /trunk/doc/dita/tutorials/tutorial_serial_port_board.xml ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/16f877_pin_info.bmp Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/16f877_pinout.bmp Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/Thumbs.db Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/blink_circuit.bmp Fri Oct 30 23:58:47 2009 File is too large to display a diff. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/circuit.jpg Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/jalv2_dir.bmp Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/micropro_read_pic.jpg Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/programmer.jpg Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/serial_cable.jpg Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/serial_pinout.jpg Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/images/blink_a_led/usb_to_serial.jpg Fri Oct 30 23:58:47 2009 Binary file, no diff available. ======================================= --- /dev/null +++ /trunk/doc/dita/tutorials/tutorial_blink_a_led.xml Fri Oct 30 23:58:47 2009 @@ -0,0 +1,202 @@ +<?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" []> +<topic id="template_id"> + <title>Blink A Led (Your First Project)</title> + <prolog> + <author>Matthew Schinkel</author> + <publisher>Jallib Group</publisher> + </prolog> + <body> + <p id="firstcontent">In this tutorial we are going to learn how to connect our first circuit and blink our first LED.</p> + <section> + <title>Where to we start?</title> + <p>Let’s make a LED blink on and off, how fun is that!</p> + <p>So, you’ve followed the installation guide and now have a Programming language (JALv2) + Libraries (JALLIB) + Editor. We will be using JALEDIT for our first example.</p> + </section> + <section> + <title>Setup your workspace</title> + <p>Start by getting out your programmer and connect it to your pc. Some connect by serial port, some connect via USB. I actually use a serial port programmer attached to a USB-to-Serial addapter to free up my serial port for other projects.</p> + <p>If you are using a serial port programmer you need to check that you have a regular serial cable and is not a null modem cable. Using your multimeter, check that each pin of your serial cable matches, if pins 7 & 8 are crossed, it is a null modem cable.</p> + <p><image href="images/blink_a_led/serial_cable.JPG"/><image href="images/blink_a_led/usb_to_serial.JPG"/><image href="images/blink_a_led/serial_pinout.JPG"/></p> + <p>Get out your PIC microcontroller (we will now refer to it as a PIC). You can use PIC’s 16f877, 16f877A, 18F2550 , 18F452 or 18F4550 for this project since the port pinouts are the same for all of them. I will use 16f877A for this blink a led project.</p> + <p>Now check PC connectivity to your programmer. Open your programming software on your PC, check the settings within your software to change the serial port number and programmer type (if available). Your programmer software may tell you that your board is connected, if not, put your PIC in your programmer and do some basic tests such as “read chip”, “blank / erase chip”</p> + <image href="images/blink_a_led/programmer.jpg"/> + <p>If you are using Micropro, click on “file” -> “port”, and “file” -> “programmer” -> (your programmer type). If you do not know the programmer type, you will have to guess untill Micropro says something like “K149-BC board connected”. Choose your PIC type from the “Chip Selector” text box. Now do some basic read/erase tests.</p> + </section> + <section> + <title>Build your circuit</title> + <p>Well, it looks like we’re all set to go, so grab your breadboard and other components, put together the following circuit:</p> + <p><image href="images/blink_a_led/blink_circuit.bmp"/></p> + </section> + <section> + <p>And here’s what it looks like. Notice the additional orange wire to the left of my PIC, this ensures that I always put my PIC in the correct position after programming. Do not connect your power 5v supply till your circuit is complete and checked over at least twice. You will burn your PIC if power is on while building your circuit. You will want an on/off switch for your power supply.</p> + <p><image href="images/blink_a_led/circuit.jpg"/></p> + </section> + <section> + <p>Your circuit is done, and it looks pretty, but it doesn’t do anything :o(..</p> + </section> + <section> + <title>Understand the jalv2 direcotry structure</title> + <p>First take a look at your jalv2 installation directory on your PC, wherever you installed it. </p> + <p><image href="images/blink_a_led/jalv2_dir.bmp"/></p> + <p><b>compiler</b> – holds the jalv2.exe compiler program to convert your JAL code to microcontroller hex code</p> + <p><b>jaledit </b>– JAL text editor where you will write your code</p> + <p><b>lib</b> – A set of libraries to make things work</p> + <p><b>sample</b> – Working examples.</p> + <p>Create yourself a folder called workspace, and in that folder create a folder called blink_a_led (eg. C:\jalv2\workspace\blink_a_led\)</p> + </section> + <section> + <title>Setup your editor & .jal file</title> + <p>Open up your fav text editor. I will use JALEdit. Run jaledit.exe from the jaledit directory. Start a new document, and save it in jalv2\workspace\blink_a_led\ and name it blink_a_led.jal (eg: C:\jalv2\workspace\blink_a_led\blink_a_led.jal)</p> + </section> + <section> + <title>Let’s write some code</title> + <p>So now we’re going to write the code that will make our LED blink. All code will be shown in green text. You can read more about JAL language useage here: <xref class="- topic/xref ">http://www.casadeyork.com/jalv2/language.html</xref></p> + </section> + <section> + <title>Title & Author Block</title> + <p>Start out by writing a nice title block so everyone know’s who created it. Here’s an example Title block from Rob Hamerling’s working 16f877a_blink.jal blink a led example in the sample directory. Every PIC has at least one working sample. You can see that two dashes “-“ declare a comment so your notes get ignored by the compiler. The character “;” can also be used for comments. We will comment our code as we go along so it is easier for us to read our own code.</p> + <p><codeblock>-- ------------------------------------------------------ +-- Title: Blink-an-LED of the Microchip pic16f877a +-- +-- Author: Rob Hamerling, Copyright (c) 2008..2009, all rights reserved. +-- +-- Adapted-by: +-- +-- Compiler: 2.4l +-- +-- This file is part of jallib (http://jallib.googlecode.com) +-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php) +-- +-- Description: +-- Sample blink-an-LED program for Microchip PIC16f877a. +-- +-- Sources: +-- +-- Notes: +-- - File creation date/time: 14 Oct 2009 20:24:20. +-- +-- ------------------------------------------------------</codeblock></p> + </section> + <section> + <title>Choose your PIC</title> + <p>Write the following code to choose the PIC you are using, change 16f877a to whatever PIC you have:</p> + <p><codeblock>include 16f877a -- target PICmicro</codeblock></p> + </section> + <section> + <title>Choose your crystal speed</title> + <p>Write the following code according to the speed of the crystal you are using in your circuit. I suggest 20mhz for 16f877. You can check your chip’s datasheet for it’s max speed. Higher speeds may not work the way you want them to on a temporary breadboard.</p> + <p><codeblock>-- This program assumes a 20 MHz resonator or crystal +-- is connected to pins OSC1 and OSC2. +pragma target clock 20_000_000 -- oscillator frequency</codeblock></p> + </section> + <section> + <title>Configure PIC Settings</title> + <p>The following code sets some of the PIC’s internal settings, called fuses. A OSC setting of HS tells the PIC there is an external clock or crystal ocillator source. You must disable analog pins with enable_digital_io() , you don’t need to worry about the others.</p> + <p><codeblock>-- configuration memory settings (fuses) +pragma target OSC HS -- HS crystal or resonator +pragma target WDT disabled -- no watchdog +pragma target LVP disabled -- no Low Voltage Programming +-- +enable_digital_io() -- disable analog I/O (if any) +--</codeblock></p> + </section> + <section> + <title>Choose an output pin</title> + <p>Let’s choose an output pin to control our LED. As you can see from the circuit, our LED is connected to pin #2. Let’s check our datasheet to find the pin name from the pinout diagram.</p> + <p><image href="images/blink_a_led/16f877_pinout.bmp"/></p> + <p>As you can see, we are using the pin RA0/ANO at pin #2. RA0 is the pin name we are looking for. AN0 is another name for this same pin (used in the analog to digital tutorial), but we can ignore it in this tutorial. In the JAL language RA0 is written as pin_A0</p> + <p>Now let’s read the details of this pin in the PDF file on page 10. As you can see RA0 is a TTL Digital I/O pin. We are checking this to make sure it is not a open drain output. Open drain outputs (like pin RA4) require a pull-up resistor from the pin to V+</p> + <p><image href="images/blink_a_led/16f877_pin_info.bmp"/></p> + <p>Now write code for pin A0. We are writing an “alias” only because in the future we can refer to pin 2 (A0) as “led”. This way we no longer need to remember the name of the pin (exept for the next line of code we will write)</p> + <p><codeblock>-- +-- You may want to change the selected pin: +alias led is pin_A0</codeblock></p> + </section> + <section> + <title>Configure the pin as an inout or output</title> + <p>Now we must tell the PIC if this is an input or an output pin. The directional setting is always named (pin_ + pinname_ + direction). Since we are writing data to the port, to turn the LED on, it is an output.</p> + <p><codeblock>pin_A0_direction = output</codeblock></p> + <p>A better way to write this, is to make an alias with “alias led_direction is pin_A0_direction”, then write “led_direction = output”, then we can change it from output to input in the middle of the program without knowing the pin name.</p> + </section> + <section> + <title>Write your program</title> + <p>So, now that we have the LED under our control, let’s tell it what to do.</p> + <p>We will want our led to continue doing whatever we want it to do forever, so we’ll make a loop</p> + <p><codeblock>forever loop</codeblock></p> + <p>In this loop, we will tell the LED to turn on (put 2 spaces before each line within the loop)</p> + <p><codeblock> led = ON</codeblock></p> + <p>now have some delay (250ms) a quarter of a second so we can see the led on.</p> + <p><codeblock> _usec_delay(250000)</codeblock></p> + <p>turn the LED off again</p> + <p><codeblock> led = OFF</codeblock></p> + <p>and have another delay before turning it back on again</p> + <p><codeblock> _usec_delay(250000)</codeblock></p> + <p>close our loop, when the PIC gets to this location, it will go back to the beginning of the loop</p> + <p><codeblock>end loop +--</codeblock></p> + <p>And that’s it for our code. Save your file, It should look something like this:</p> + <p><codeblock>-- ------------------------------------------------------ +-- Title: Blink-an-LED of the Microchip pic16f877a +-- +-- Author: Rob Hamerling, Copyright (c) 2008..2009, all rights reserved. +-- +-- Adapted-by: +-- +-- Compiler: 2.4l +-- +-- This file is part of jallib (http://jallib.googlecode.com) +-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php) +-- +-- Description: +-- Sample blink-an-LED program for Microchip PIC16f877a. +-- +-- Sources: +-- +-- Notes: +-- - File creation date/time: 14 Oct 2009 20:24:20. +-- +-- ------------------------------------------------------ +-- +include 16f877a -- target PICmicro +-- +-- This program assumes a 20 MHz resonator or crystal +-- is connected to pins OSC1 and OSC2. +pragma target clock 20_000_000 -- oscillator frequency +-- configuration memory settings (fuses) +pragma target OSC HS -- HS crystal or resonator +pragma target WDT disabled -- no watchdog +pragma target LVP disabled -- no Low Voltage Programming +-- +enable_digital_io() -- disable analog I/O (if any) +-- +-- You may want to change the selected pin: +alias led is pin_A0 +pin_A0_direction = output +-- +forever loop + led = on + _usec_delay(250000) + led = off + _usec_delay(250000) +end loop +--</codeblock></p> + </section> + <section> + <title>Compile your code to .hex</title> + <p>Now let’s get this beautiful code onto our PIC. Your PIC cannot understand JAL, but it does understand hex, this is what the compiler is for. The compiler takes people readable code and converts it to code your PIC can understand.</p> + <p>If you are using jaledit, click the compile menu at the top and choose compile.</p> + <p>If you are using your own text editor in windows, you will need to open windows command prompt. Click start -> run and type cmd and press ok. Now type (path to compiler) + (path to your .jal file) + (-s) + (path to JALLIB libraries) + (options) Here’s an example:</p> + <p>C:\jalv2\compiler\jalv2.exe "C:\jalv2\workspace\blink_a_led\blink_a_led.jal" -s "C:\jalv2\lib" -no-variable-reuse</p> + <p>The option -no-variable-reuse will use more PIC memory, but will compile faster.</p> + <p>If all this went ok, you will now have a blink_a_led.hex located in the same directory as your blink_a_led.jal, If there where errors or warnings, the compiler will tell you.</p> + <p>A error means the code has an problem and could not generate any .hex file. If there is a warning, the hex file was generated ok and may run on your PIC but the code shoud be fixed.</p> + </section> + <section> + <title>Write the hex file to your PIC</title> + <p>Take your PIC out of your circuit and put it in your programmer. With your programming software, open the blink_a_led.hex file. You should see that hex data loaded in your software. Now click the Write button. Your software will tell you when it is done.</p> + <p>Put your PIC back into your circuit, double check your circuit if you haven’t already, and make sure your PIC is facing the correct direction. Apply power to your circuit.</p> + <p>It’s alive! You should see your led blinking! Congradulations on your first JALv2 + JALLIB circuit!</p> + </section> + </body> +</topic> ======================================= --- /trunk/doc/dita/tutorials/tutorial_serial_port_board.xml Wed Oct 21 23:03:26 2009 +++ /trunk/doc/dita/tutorials/tutorial_serial_port_board.xml Fri Oct 30 23:58:47 2009 @@ -13,9 +13,7 @@ <p><image href="images/serialboard_purchased1.jpg"/><image href="images/serialboard_purchased2.jpg"/><image href="images/serialboard_purchased3.jpg"/></p> </section> <section> - <p>Now, lets build our own! - -</p> + <p><b>Now, lets build our own! </b></p> <p>First get yourself a RS232 port, you can cut up one of your serial port cords, or buy a port from the store for a dollar or two. </p> <p><image href="images/serialboard_port.jpg"/><image href="images/serialboard_port2.jpg"/></p> @@ -39,9 +37,9 @@ <p>It can be downloaded for free from http://sourceforge.net/projects/realterm/files/ </p> <p>Open the software, click “Port”, choose your speed and port number and press “open”</p> - <p>Hex output</p> + <p><b>Hex output</b></p> <p><image href="images/serialboard_realterm.jpg"/></p> - <p>Ascii output</p> + <p><b>Ascii output</b></p> <p><image href="images/serialboard_realterm2.jpg"/></p> </section> </body> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
