Report 1 Exercise Example ========================= Jonathan Higgins 1. Introduction =============== 1.1. What is a Micro-Stamp11? ----------------------------- Micro-Stamp11 is a complete computer based on Motorola's popular MC68HC11 micro-controller. The Micro-Stamp11 comes with an on-board EEPROM. Using the RS232 interface, programs can be down-loaded into the EEPROM. These programs will stay in the Micro-Stamp even when the power is off. The Micro-Stamp11 is based on a 68HC11D0 MCU, with 192 bytes of RAM on-chip. The chip has 32k EEPROM which is mapped to the upper half of the 64K memory map. The Micro-Stamp11 satisfies the needs of users who need lots of memory, but only require a modest number of I/O lines. 2. Getting Started. =================== 2.1. What is needed? -------------------- Several components are needed to get started with the Micro-Stamp11. The software that comes with the Micro-Stamp11 will need to be loaded onto a X86 based system running DOS or Windows. You may wish to setup several $PATH statements to make compilation and configuration easier. Create a directory on the C:\ drive called HC11. Copy the contents of the disk provided to this directory by typing xcopy A:\*.* C:\HC11 This will place files in the correct location on the system. A few pieces of hardware besides the Micro-Stamp11 and an X86 based computer are needed. A solder-less breadboard is probably the easiest way to get wires and lights connected to the Micro-Stamp11. A serial cable will be used to connect the Docking Module of the Micro-Stamp11 to the computer. Parts needed: IBM compatible PC with serial ports Micro-Stamp11 MS11M32K-FRA Serial Cable Docking Module MS11DM-RA-M1 ribbon cable solder-less breadboard adapter disk 68HC11 Utilities 30 gauge Jumper Wires solder-less breadboard +5v Power Supply several LED's (8) piezo speaker 2.2. Setup ---------- The docking module comes with 2 different sets of 20 pin connections. Place the docking module flat on the solder-less breadboard and connect the Micro-Stamp11 to the pins that are perpendicular to the breadboard. This configuration should look like the picture below. o PIC of the setup may be useful Now connect a ribbon cable to the other set of 20 pins that are parallel to the breadboard. Plug in the solder-less breadboard adapter to the breadboard and then attach the ribbon cable to the adapter. Connect the power jumper to the docking module and then connect the wires to the power source. Make sure that the power source is off during this procedure or you may damage the Micro-Stamp11. The Power requirements are +5V. 2.3. Demo Program ----------------- The Micro-Stamp11 comes with a default program. Connect the supplied serial cable between the docking module and a serial port on your PC. Start a terminal program on the PC. If windows is the default OS, use Hypertermial otherwise start a DOS terminal program provided. Configure the terminal program. Set the baud rate to 9600, parity to NONE, #DATA BITS =8, and #STOP BITS =1. Check the 2 switches on the Micro-Stamp11 and make sure they are both in the RUN position, and then press the Docking Module RESET button. LED D1 will blink twice to indicate that the demo program is running. If the LED did not blink, turn off the power to the Micro-Stamp11 and then check all connections, and then try again. If the system still fails, skip to the Upload section to install the demo program. If you have gotten this far, Hit on your keyboard. A menu of commands should appear on your terminal screen followed by a command prompt "?" symbol. A single keystroke will activate each command, typing a command that is not listed will cause the menu to be re-displayed. This demo program is intended to help test the Micro-Stamp11 to make sure that it is functioning properly. By pressing A,C,D, or S the program should return an appropriate response. We can further test the system by applying switches on some of the input port lines. If you attach a small piezo speaker directly to PA6 through a 330-Ohm resistor, and the other end to the ground, the S command should generate 2 beeps. 2.4. Writing your first Program ------------------------------- The first program is written in assembler. It is very basic and turns on the LED on PORT-A (PA6), and then waits in an infinite loop. org $e000 ;start at top of 8k EEPROM begin: ldaa #$04 ;disable COP in CONFIG register staa $3f ldaa #$40 ;write a logic high to PA6 staa $0 ;(and logic low to all other portA bits) bra * ;branch forever(until reset occurs) org $fffe ;define the reset vector to point to fdb begin ; the beginning of your code The 'org' at the top of this program tells the Micro-Stamp11 where to begin reading the program in EEPROM. The 'begin' is similar to an function heading in C or C++ and marks the beginning of a block of code. 'ldaa #$04' disables a COP or Computer Operating Properly register in the CONFIG register, More information on this later....Read the comments in the code to follow the rest of the program. After completing modifications to the code, save the program as "first.asm" This code needs to be compiled before it can be used in the Micro-stamp11. Execute the command c:\HC11\AS11\AS11 first.asm -l > output_file.txt Read through the output_file.txt to make sure that the program compiled correctly. If everything went smoothly, your are now ready to upload your new program. 2.5. How to Upload a program ---------------------------- Prepare the Micro-Stamp11 for new code by making sure that the chip is in the docking module and is connected to the PC. Place both switches to the LOAD position. Turn on the power to the Micro-Stamp11. Execute the following command C:\HC11\MSTAMP11\pms1 file o Note: the port that the docking module is connected to will determine which script your execute. Com1 will use pms1 and Com2 will use pms2. o Note: the file name is the first part of the compiled program from the previous section. Leave off the .s19 extension. Follow the instructions prompted from the script that you executed and it will return to a prompt when it has completed. To run the new program place the top switch to RUN and the bottom switch to PROTECT and press the reset button. The LED should turn on, and stay on continuously. 3. Programming Control ====================== 3.1. Flashing Lights using loops and time delays ------------------------------------------------ The first program written earlier turned a light on that was connected to PORTA (PA6) and left it on while the program was running. A few extra lines of code are all that is needed to change the program from a continuous light to a flashing light, using a loop structure to turn the light on and then off again. org $e000 ;start at top of 8k EEPROM begin: ldaa #$04 ;disable COP in CONFIG register staa $3f lds #$ff ;initialize the stack pointer loop: ldaa #$40 ;write a logic high to PA6 staa $0 ;(and logic low to all other portA bits) bsr Delay ;Branch to Subroutine "Delay" clr $0 ;make all portA bits logic low bsr Delay bra loop ;do it all again Delay: ldy #$ffff D1: dey ;pad delay loop with extra cycles iny : for total of 15 cycles dey ;this gives approx. 1/2 second at 8MHz bne D1 rts org $fffe ;define the reset vector to point to fdb begin ; the beginning of your code The "bsr", in the 'loop' section tells the program to branch to the subroutine Delay. Inside the Delay subroutine, the value #$ffff is added to index y and then decremented, incremented, and decremented. This process adds a few instructions to the process without too much difficulty and results in slowing the speed of the system down. The "bne", in the 'Delay' section tells the system to branch to D1, if not equal to 0. The "clr", back in the 'loop' section clears the bits of portA, which will turn the light off. Compile this code and then upload it to the Micro-Stamp11 to watch the lights flash. 3.2. Number counters -------------------- This program is a bit more in-depth. Eight(8) lights will need to be attached to the chip. The following is a list of the connections. Port LED PIN# ...................... ....................... ...................... PD0 8 20 PD1 7 19 PD2 6 18 PD3 5 17 PD4 4 16 PD5 3 15 PA4 2 4 PA5 1 3 The following code will have a subroutine by the name "Output", which helps to display our results to the lights. This code will only work if you lights have been connected using the previous table. This connection order and subroutine can and will be reused is several programs. This program will create a binary counter. org $e000 begin: ldaa #$4 staa $3f lds #$ff ;initialize stack pointer setupD: ldaa #$3f ;This section will initialize staa $9 ; PortD for use loop: ldaa #$0 ;Load the decimal value 0 into Register A bsr L1 ;Branch to L1 bra loop ;Branch to Loop L1: bsr Output ;Branch to Output bsr Delay ;Branch to Delay inca ;increment the value in Register A bne L1 ;Branch if not equal to Zero rts ;Return to Subroutine Delay: ;This is the same delay function ldy #$8fff ; except this time we decrease the D1: dey ; delay. bne D1 rts Output: ;This is the function that puts the tab ; data in the correct locations to andb #$3f ; make the lights turn on and off stab $8 ; tab - transfers data from Register A to B tab ; andb - is a masking technique andb #$c0 ; stab - stores the data in B to a location rorb ; rorb - Rotates the data in B to the right rorb ; do this again stab $0 rts org $fffe fdb begin Compile this code and load it onto the Micro-stamp11. Make sure that your lights are correctly connected to the pins of the Chip to see the results of the program.