|Shopping Cart Checkout Shipping Cost Download Website|
|You are here: 8051 Tools Development Board Old Versions Rev 3 (2001) LED Blink, Asm|
Getting Everything ReadyThis LED blink example must be built with the AS31 Assembler. If you do not have AS31, you must download AS31 here.
The description here assumes you are familar with how to communicate with the 8051 development board and download and run programs on it. If you haven't done this yet, the Using The Board For The First Time page explains in detail exactly how to setup communication with the board and download programs to it and run them.
Of course, you need to download the LED Blink AS31 source code:
Running The Pre-Built HEX File
The LED blink program comes with a copy already assembled, as "blink.hex". It is 10 lines of text, 390 bytes, or 400 bytes if converted to DOS CR/LF text format.
You should download this copy to the board and run it. You may use "Jump" to "2040", or use the "Run" command and select it from the menu, since this program has the 64 byte header that allows PAULMON2 to recognize it. Figure 1 illustrates what you should see when you run the LED blink program.
The blink program checks for you to press ESC as it is running, and aborts when it sees ESC. When you run other programs which run in an infinite loop and don't abort, press the reset button (located next to the serial port) to reboot the board. If no auto-start programs are in memory, you will be returned to PAULMON2. When you later load auto-start programs into the flash, you will need to use the "ERASE FLASH" jumper to return to PAULMON2.
Making A Simple Change and Rebuilding With AS31
Using your favorite text editor, load the BLINK.ASM file, and make a change. Find the code that causes a delay between each update to the LEDs. It looks like this:
This code waits for a length of time, which is set by the value of the accumulator when it is called. There are two nested loops. By changing the number "250" to something smaller, the delays will be shorted and the blinking animation will run more rapidly. For example, you could change this to 83 to make the display animate 3 times faster. Once you've made your changes, run AS31 to produce a new intel-hex file to download.
To run AS31, you just type:
Windows users will usually run AS31 in a "MS-DOS Prompt" window, as shown in figure 2. Linux distributions usually provide many terminals and shells. Figure 3 shows AS31 run from the Gnome Terminal, which is the default provided by Red Hat Linux 7.1.
If AS31 is installed properly, it will run as shown and produce a new intel hex output file. When you download this new .hex file to your board and run it, the faster animation should be very easy to see.
AS31 is also available with a GTK-based GUI front end when build on linux-based systems. To run the GUI version, type "as31-gtk".
Most Substantial Editing, Changing The Blink Patterns
The blink program uses a simple lookup table, which you can easily modify for different blinking patterns. In the lookup table, each pattern is shown and each has a time delay value. The last entry of the table has a time delay of zero, which marks the end of the list and causes the program to begin again at the top. Here's the lookup table from the code:
By changing the bit patterns and delays, together with removing or adding more lines, you can make this simple LED blink program produce nearly any blinking display that cycles through a fixed set of states.
Configuring For RAM, Flash, Automatic Start-Up
The boards that are tested by PJRC have a copy of this LED blink test loaded in the flash memory. To configure where a program will be loaded, you would edit the first line. The first line of the file should be:
To cause it to be loaded into the flash memory, set the location between 0x8000 to 0xFF00 (the last two digits must be zero for PAULMON2 to recognize the header). To program the flash memory, download your program in the same way as loading it into RAM, and PAULMON2 will automatically handle the flash programming as it receives the data. The portion of flash memory where you're downloading must be erased, otherwise the download will not work and you'll see errors reported. Because the ram doesn't need to be erased before it is written, it's easier to develop your code by downloading it into the RAM, and then setting it to the flash when it's working.
If you want to make the board run this LED blink program without being attached to your PC, edit the header to tell PAULMON2 that this is a startup program. To do this, change the "35" to "249" in the header. More details can be found in the PAULMON2 manual. Once you've done this, the board will boot up and run the LED blink instead of PAULMON2. To get back to PAULMON2, short the "ERASE FLASH" jumper and press the reset button.
Hopefully this page has provided you with a simple easy-to-get-going example with AS31 and the 8051 development board.