• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
EE312 Embedded Microcontrollers Lab
 

EE312 Embedded Microcontrollers Lab

on

  • 738 views

 

Statistics

Views

Total Views
738
Views on SlideShare
737
Embed Views
1

Actions

Likes
0
Downloads
16
Comments
0

1 Embed 1

http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    EE312 Embedded Microcontrollers Lab EE312 Embedded Microcontrollers Lab Document Transcript

    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 EE 312 Embedded Microcontrollers Final Lab Assignment “Modular programming with the MC68HC11, using loops,subroutines, branching, terminal I/O, Buffalo Monitor I/O, LEDs, LCDs, sounds, buttons, and ASCII conversion.” By: Loren K. Schwappach Student Number: 06B7050651 Date Due: May 18, 2009 Date Completed: May 16, 2009Professor: Pamela Hoffman Page 1 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009 1. Purpose: This program will cover many of the possibilities offered by the MC68HC11, FOX-11 board. It will use the buffalo monitor and terminal I/O addresses to get/send information to a monitor and LCD. This lab will demonstrate sound, buttons, LEDs, basic math operations, and finally how to convert ASCII user input into numerical values for a small math computation game. 2. Future project ideas for students: I. Use the keypad for setting variable speed of the LED racetrack.II. Create a module that would get/convert/store several larger ASCII (0- 9) numerals into Hex at a separate memory location and reconvert for terminal & LCD output.III. Develop song for intro using Buffalo monitor test.asm demoIV. Have credits at the end scroll and repeat over the LCD, by incrementing the X location in a loop and calling the LCD display subroutine until the end of the string +16. Professor: Pamela Hoffman Page 2 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009 3. Instructions and Directives:I. LOAD: Places a specified value or memory location(s) into a register for temporary storage manipulation. It can be used to load values / address in 8 bit accumulators A or B, or the 16 bit registers, double accumulator D (Uses A and B), the stack pointer, or either index register X or Y. Figure 4.1: Load instructions Professor: Pamela Hoffman Page 3 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009II. ADD: Performs arithmetic addition operation(s) upon registers. Very powerful! Figure 4.2: Add instructions Professor: Pamela Hoffman Page 4 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009III. SUB: Performs arithmetic subtraction operation(s) upon registers. Also very powerful! Figure 4.3: Subtraction instructions Professor: Pamela Hoffman Page 5 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009IV. STORE: Stores contents of register into memory location(s). Destination must be a valid storable memory location. Also if register is 16 bit register, storage will consume two blocks of memory. Figure 4.4: Store instruction Professor: Pamela Hoffman Page 6 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009 V. MUL: Multiplies an 8-bit unsigned value in A by an 8-bit unsigned value in B to obtain a 16-bit unsigned result in D (thus writes over A and B). Uses inherent addressing. Example: Start: ORG $9000 ; directive, sets program start ; location. Use go 9000 LDAA #10 ; load accum. A with decimal 10 LDAB #25 ; load accum. B with decimal 25 MUL ; multiplies A*B stores decimal ; value 250 in D STD $8000 ; stores D at location $8000 and ; $8001 END ; housekeeping directive tells ; program to halt.VI. DIV: There are two division instructions IDIV and FDIV. IDIV performs unsigned integer division of the 16 bit numerator in D by the 16 bit denominator in X. For the result, the quotient is placed in X and the remainder is placed in D. If denominator is 0 the quotient is set to $FFFF, the remainder is indeterminate and the CCR C flag is set=1. IDIV uses inherent addressing. Example: Professor: Pamela Hoffman Page 7 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009 LDD #4 ; Loads D with decimal value 4 LDX #2 ; Loads X with decimal value 2 IDIV ; (4/2)=2 w/ r=0 so X=2, D=0 FDIV performs unsigned fractional division of the 16 bit numerator in D by the 16 bit denominator in X. For the result, the quotient is placed in X and the remainder is placed in D. If the denominator is 0 or in the case of overflow the quotient is set to $FFFF and remainder is indeterminate and CCR C flag is set=1. The radix point is to the left of bit 15 for the quotient. FDIV uses inherent addressing. Example: LDD #2 ; 4 is loaded in D (numerator) LDX #3 ; 3 is loaded in X (denominator) FDIV ; quotient in X, remainder in DVII. DAA: Decimal Adjust Accumulator A, used for BCD addition. Checks CCR C (Carry) flag, upper half byte of Accumulator A, initial H (Half Carry) flag, lower byte of Accumulator A and uses conditions to add a set amount to Accumulator A and finally resets C flag. This ensures correct BCD addition. Use inherent addressing. Example: Professor: Pamela Hoffman Page 8 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009 LDA #$04 ; Load BCD 00100100, decimal value 04 ADDA #$16 ; Load BCD 00010110, decimal value 16 DAA ; Checks A, and CCR and then adds $06 to A ; A now correctly holds hex $20 BCD value ; 00100000VIII. Exchange Registers: There are two instructions that perform register exchanges. XGDX (exchange double accumulator D with index register X) and XGDY (exchange double accumulator D with index register Y), both use inherent addressing. Example (Assume X = 8020 and Y = 8040 prior to execution): LDD #$8000 ; Load D w/ hex value 8000 XGDX ; D now holds $8020, X now holds 8000 XGDY ; D now holds $8040, Y now holds 8020 Note: Another way of exchanging register is with the load and store instructions already covered. Professor: Pamela Hoffman Page 9 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009IX. Compare / Test Instruction: Used to compare or test registers / locations and set CCR flags, while leaving compared accumulator contents intact. Very powerful! Used to control branch instructions and interrupts. Often used in loop control. Figure 4.5 Compare and Test Instructions Professor: Pamela Hoffman Page 10 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009X. Branch / Jump / Return Instructions: Branch, Jump, and Return instructions tell the program to go somewhere else or return from somewhere, normally depending upon CCR flag and the use of the stack. Branch instructions (Essential for modular programming and loops): The following are branch instructions that if the conditions are met (CCR) the program branches to relative address specified (relative addresses are offsets from current address limited to -128 to 127 bytes) so is very limited to the location it can branch to...) Refer to a text on Boolean algebra if you do not understand AND, OR, XOR operations Instr. ; Meaning ; Branches if BRA <rel> ; branch (unconditional) ; Always BCC <rel> ; carry clear ; C = 0 BCS <rel> ; carry set ; C = 1 BLO <rel> ; lower (unsigned) ; C = 1 BHS <rel> ; higher or same (unsigned) ; C = 0 BEQ <rel> ; equal to 0 ; Z = 1 BNE <rel> ; not equal to 0 ; Z = 0 BPL <rel> ; plus (signed) ; N = 0 BMI <rel> ; minus (signed) ; N = 1 BVS <rel> ; overflow bit set ; V = 1 Professor: Pamela Hoffman Page 11 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009BVC <rel> ; overflow bit clear ; V = 0BGE <rel> ; greater or = to 0 (signed) ; (N XOR V) = 0BGT <rel> ; greater than 0 (signed) ; (Z + (N XOR V)) = 0BHI <rel> ; higher or same (unsigned) ; (C + Z) = 0BLE <rel> ; less than or = 0 ; (Z + (N XOR V)) = 1BLS <rel> ; lower or same (unsigned) ; (C + Z) = 1BLT <rel> ; less than 0 (signed) ; (N XOR V) = 1BCLR <operand> ; clear bits ; M AND M’ <msk>BRCLR <operand> ; if bits clear ; M AND (PC+2) = 0 <msk><rel>BSET <operand> ; set bits ; M + M AND M <msk>BRSET <operand> ; if bits set ; M AND (PC+2) = 1 <msk><rel>Professor: Pamela Hoffman Page 12 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Jump Instructions:JMP <operand> ; Jumps to instruction stored at effective address given inoperand. JMP uses extended or indexed addressing.JSR <operand> ; Jumps to subroutine specified by operand. JSR usesdirect, extended, or indexed addressing. Note: This allows for thecreation of modular programming (functions). JSR increments the programcounter (PC) by two or three depending upon addressing used and pushes thePC onto the stack so you can return where you left off using RTS (Returnfrom Sub Routine) instruction.Return Instructions: There are two return instructions RTS (Return from Sub Routine) andRTI (Return from interrupt).RTS ; Uses inherent addressing and is used to return out the calledsubroutine back to the caller subroutine. This is accomplished byincrementing the stack pointer and loading the address contained back intothe program counter.RTI ; Users inherent addressing and is used to restore A, B, X, Y, CCR,and PC states by pulling them from the stack, also may or may not set CCRX flag.Professor: Pamela Hoffman Page 13 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009 XI. Decrement / Increment Instructions (Often used in loops): DEC <operand> ; decrements value at location by 1, value - 1 DECA ; decrements A by 1, A = A - 1 DECB ; decrements B by 1, B = B - 1 DEX ; decrements X by 1, X = X - 1 DEY ; decrements Y by 1, Y = Y - 1 DES ; decrements SP by 1, SP = SP - 1 INC <operand> ; increments value at location by 1, value + 1 INCA ; increments A by 1, A = A + 1 INCB ; increments B by 1, B = B + 1 INX ; increments X by 1, X = X + 1 INY ; increments Y by 1, Y = Y + 1 INS ; increments SP by 1, SP = SP + 1XII. Rotate & Shift (Logical & Arithmetic) Instructions: Professor: Pamela Hoffman Page 14 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Figure 4.6: Rotate and Shift InstructionsProfessor: Pamela Hoffman Page 15 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009XIII. PUSH / PULL & Transfer Instructions: Push and pull instructions manipulate the stack which is discussed in detail in Section 8. They are extremely valuable instructions and assist in searching, accessing, and manipulating strings and arrays as well as preserving register values for modular programming. Figure 4.7: Push and Pull instructions Transfer Instructions: Professor: Pamela Hoffman Page 16 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009 Transfer instructions are used to manipulate the stack pointer (SP), and thus can be used to quickly navigate the stack. Figure 4.8: Transfer InstructionsXIV. Clear Instruction & variable initialization: Clear “CLR” instructions do just what they suggest; they replace the contents of a memory location or register with zeros. This is often used for variable initialization. Figure 4.9: Clear Instructions Professor: Pamela Hoffman Page 17 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009XV. Other Important Instructions: Logic Instructions ANDA <operand> ; AND A with memory (Immediate, Direct, Extended, or Indirect Addressing) ANDB <operand> ; AND B with memory (Immediate, Direct, Extended, or Indirect Addressing) BITA <operand> ; Bit tests A with memory (A AND M) and sets CCR (Immediate, Direct, Extended, or Indirect Addressing) BITB <operand> ; Bit tests B with memory (B AND M) and sets CCR (Immediate, Direct, Extended, or Indirect Addressing) COM <operand> ; Get value at operand and take ones complement or invert bits (extended or indirect addressing) COMA ; Take ones comp. of A store in A, invert bits COMB ; Take ones comp. of B store in B, invert bits EORA <operand> ; XOR with value in memory w/ A store in A (Immediate, extended, direct, indirect) EORB <operand> ; XOR with value in memory w/ B store in B (Immediate, extended, direct, indirect) Professor: Pamela Hoffman Page 18 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009NEG <operand> ; 2’s complement of memory store in memory (Extended or Indirect)NEGA ; 2’s complement of A store in ANEGB ; 2’s complement of B store in BORAA <operand> ; OR A with memory store in AORAB <operand> ; OR B with memory store in BOther Useful Instructions (Note: Several used for interrupts)CLV ; lear overflow flag, V=0NOP ; No operation, takes up clock cycles for nothingSEC ; Set carry, C=1SEI ; Set interrupt mask, I=1SEV ; Set overflow flag, V=1STOP ; Stop internal clockSWI ; Software interruptTAP ; Transfer A to CCRTPA ; Transfer CCR to AWAI ; Wait for interruptProfessor: Pamela Hoffman Page 19 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AM Final Lab Spring 2009XVI. Directives: Directives are commands to the assembler that define data and symbols, setting assembly conditions, and specifying output format. Directives do not produce code but perform housekeeping activities for the assembler. ORG <address> ; Sets value of location counter to address specified RMB <#> ; Reserves memory byte(s), number given by # DCB ; Defines constant block, reserves area in memory and initializes each byte to the same constant. FCB <......> ; Forms constant byte(s) w/ value set by operand FDB <......> ; Forms 2 bytes for each argument FCC <......> ; Forms constant character(s), forms ASCII string, use “This is my String” format. BSZ <#> ; Reserves a number of bytes specified starting at location counter and initializes each/all value(s) to $00. FILL <Value1, Value2> ; Reserves # of bytes (Value1) and fills each with Value2 starting at address given by location counter. END ; Indicates the END of a program. Professor: Pamela Hoffman Page 20 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 4. Understanding and Using the program: This begin this lab copy/paste/save/assemble/load the program andstart the program at memory location $9000 with the “go $9000” command.$9000 is where I begin to store all of the program code for this lab. Once the program begins the first thing that is accomplished is toload the stack pointer at $C800. This should always be in the first fewlines of code for any program that plans on making use of the stack, asall modular programs should. I also use the equate directive extensively, which helps in keepingport locations, terminal/Buffalo monitor I/O routines, ASCII values, anddelay loop variables easy to remember. I also declared/formed area for the storage of my user input ASCIIvalues and filled the first 16 blocks with ASCII whitespace and aterminating EOT so that the terminal display routine and Buffalo monitorLCD routine could correctly handle/display the correct information whencalled. These string locations as well as other temp variable locationsbegin at locations $8000 in memory for easy referencing. As with the above, I also formed/reserved storage for all of thestrings, ensuring all strings were 16 characters and ending in a ASCII EOTfor later referencing. All output strings begin at memory location $A000.This sort of memory assignment/separation is important for T/S code andensures that you don’t have problems where pieces of code override oneanother.Professor: Pamela Hoffman Page 21 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 Next, after beginning the program and loading the stack I immediatelycall a jump statement that sends the program to my main_func subroutine,which if you are reading the code right now is at the very bottom. Justlike in C or C++ this seemed a logical place for placing the subroutinethat would call all other subroutines. Once in main_func subroutine I begin calling all of the followingother subroutines but before I go into them let me explain something aboutthem all. To ensure that I can contain each subroutines variables andregister components intact I make extensive use of the stack pull and pushinstructions. This allows each subroutine to keep a form of temporaryregister storage and prevents a register value in one subroutine frominterfering with another subroutines values. If I plan on passing aregister from one subroutine to the next over and over I skip thispush/pull which allows the two to use each other’s register values. The first subroutine called is LCD_init which initializes the Buffalomonitor LCD for use. Next I call Clear LEDs which sets the value $00 inport B and clears the LEDs. Next, I call Disp_LCD_clear which clears theLCDs with whitespace. I then call Disp_welcome to display my initialprogram welcome message. Next, Flash_LEDs_osc displays an oscillating (middle to left/right,left/right to middle) LED pattern using a delay routine and specifiesvalues of Port B to flash the LEDs and make a beep when the LEDs touch(like a hospital heart monitor), a simple but dramatic effect.Professor: Pamela Hoffman Page 22 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 Next I call Disp_q_name to tell the user I would like their name. Ithen call Get_name to get the users name and store it at an assignedmemory location. I also prevent the users input from storing more than 16characters so that the name displays correctly on the LCD. I then callDisplay_name to display their results to screen. Finally I call Display_press_btn, which tells the user to press oneof three buttons and the I call Check_buttons which selectively calls forfour other subroutines, one which checks for a button being pressed, andif pressed calls one of the other three subroutines depending upon whichbutton was pressed. Depending upon the button pressed the program will doone of the following... The first button will flash the intro LED pulse pattern ten times.The second run a looping colorful racetrack LED pattern using thebreadboard and LEDs (Note: If you want to do this on your breadboard youwill need to use the PB0-PB7 outputs as highs to your breadboard LEDs anduse the ground as a low for your breadboard. I also ensured that thedelay subroutines used a temporary delay value that although I didn’t usethe user could expand upon the program and build a module to increase ordecrease the speed at which the racetrack LEDs flashed (I leave this up tothe user). The third button will run a simple math program to get two numbers(0-4) from the user, it then converts the numbers into their actual hexvalue representations for computation, reconverts the result into ASCIIProfessor: Pamela Hoffman Page 23 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009stores and displays on the terminal and LCD. I had plans to make thisperform larger computations but would have needed to create a largermodule in order to handle large user ASCII strings into hex valuesconversion for multi-precision addition (Remember each ASCII numeralentered is two bytes (representing 10 possibilities 0-9) where the actualhex only needs one and represents 16 possibilities (decimal 0-15 or 0-F).To simplify the program I used validation routines that ensured the usercould only enter a value between 0 and 4 (Because max values 4+4=8 whichsimplifies ASCII conversion +/- $30). Once the user is done with the choices I used a loop for theCheck_buttons routine which caused the loop to exit after a certain periodof inactive time (30 seconds). Then Display_credits and Display_exit_world is called to displaygoodbye messages to the user. Finally the program exits Main_Func and returns to the top where theregisters are cleared and the program terminates.Professor: Pamela Hoffman Page 24 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009* Assembly Code!* Final Project, Version 1* Coded by: Loren K. R. Schwappach* Coded on: 13 June 09* Completed in Requirements for:* EE312, Embedded Microcontrollers* Instructor: Professor Pamella Hoffman* Program description: This program will cover many of the possibilities* offered by the MC68HC11, FOX-11 board. It will use the buffalo monitor* and I/O addresses to get/send information to a monitor and LCD. It will* demonstrate sound, buttons, LEDs, and how to control output to a bread board.* it also demonstrates how to convert ASCII user input into numerical values* for a small math computation.* Future ideas (if time permitted..)* #1 Use the keypad for setting variable speed of racetrack* #2 Create a module the would get/convert/store large ASCII numerals to Hex* And then retrieve/convert/store these values in ASCII for display* #3 Develop song for intro..* #4 Have credits scroll and repeat over LCD by inc X in loop and increasing init string size* ------------------------* References* ------------------------* Define addresses for LCD outputLCD_init EQU $FF70 ; Address to initialize the LCDLCD_write_top EQU $FF73 ; Address to write to LCD topLCD_write_bottom EQU $FF76 ; Address to write to LCD bottomProfessor: Pamela Hoffman Page 25 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009* Define addresses/values for terminal I/OOutput_disp_text EQU $FFC7 ; Outputs all ASCII stored at loc in X until EOTInput_get_char EQU $FFCD ; Gets ASCII character from keyboard -> stores in AOutput_disp_CR EQU $FFC4 ; Outputs ASCII character return and line feedCR EQU $0D ; ASCII CR, (enter key)EOT EQU $04 ; ASCII EOT, (End Of Transmission)* Define port I/O addressesPort_A EQU $1000 ; Port A AddressPort_B EQU $1404 ; Port B AddressPort_C EQU $1403 ; Port C Address* Delay loop timesHundred_ms EQU 16700 ; Loop iterations for 100ms delayTen_ms EQU 1670 ; Loop iterations for 10ms delayOne_ms EQU 167 ; Loop iterations for 1ms delayVar_ms EQU 2505 ; Loop iterations for variable delay (15ms)* Other important values* Store Program at {$9000 - $9FFF}, Store Stack at {$C800 - $C000}Program_loc EQU $9000 ; Begin program here w/ go 9000 commandStack_loc EQU $C800 ; Set aside location for stack, used extensively* ------------------------* Variable Storage Locations {$8000 - $8FFF}* ------------------------Username EQU $8000 ; Location to reference later for ASCII name storage ORG $8000 ; Set location to $8000 FILL 16, $20 ; Fill 16 blocks from $8000 to $8010 with $20 "ASCII space" ; Note on above: value $20 used so LCDs display correctly FCB EOT ; Form Constant Block at $8011 with ASCII EOTProfessor: Pamela Hoffman Page 26 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Result EQU $8020 ; Location to reference later for ASCII math result storage ORG $8020 ; Set location to $8020 FILL 16, $20 ; Fill 16 blocks from $8020 to $8030 with $20 "ASCII space" ; Note on above: value $20 used so LCDs display correctly FCB EOT ; Form Constant Block at $8031 with ASCII EOTValue1 RMB 1 ; Reserve Memory Block at $8032 for math fun value 1value2 RMB 1 ; Reserve Memory Block at $8033 for math fun value 2* ------------------------* String Output Locations {$A000 - $AFFF}* ------------------------ ORG $A000 ; Set location for storage of stringClear_LCD FCC " " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A020 ; Set location for storage of stringWelcome1 FCC " Welcome to my " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A040 ; Set location for storage of stringWelcome2 FCC "EE312 FOX11 Demo" ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A060 ; Set location for storage of stringQuestion_Name1 FCC " Please enter, " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A080 ; Set location for storage of stringQuestion_Name2 FCC " Your name... " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A0A0 ; Set location for storage of stringWarning1 FCC " !Max 15 char! " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitorProfessor: Pamela Hoffman Page 27 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 ORG $A0C0 ; Set location for storage of stringQuestion_Name3 FCC "Enter name -here" ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A0E0 ; Set location for storage of stringResponse_Name1 FCC "**** Hello **** " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A100 ; Set location for storage of stringPress_Btn1 FCC " Press a Button " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A120 ; Set location for storage of stringPress_Btn2 FCC "PA0, PC1, or PC0" ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A140 ; Set location for storage of stringWarning2 FCC "20s left to exit" ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A160 ; Set location for storage of stringWarning3 FCC "10s left to exit" ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A180 ; Set location for storage of stringMathA_1 FCC " Time for some " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A1A0 ; Set location for storage of stringMathA_2 FCC "Simple math fun " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A1C0 ; Set location for storage of stringMathB_1 FCC " Give me two #s " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A1E0 ; Set location for storage of stringMathB_2 FCC "1 dig.= {0 to 4}" ; Form Constant Character for LCD "16 character" displayProfessor: Pamela Hoffman Page 28 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A200 ; Set location for storage of stringMathC_1 FCC "ENT 1st Number: " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A220 ; Set location for storage of stringMathD_1 FCC "ENT 2nd Number: " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A240 ; Set location for storage of stringMathE_1 FCC "The Result is.. " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A260 ; Set location for storage of stringCredits1 FCC "Created by.. " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A280 ; Set location for storage of stringCredits2 FCC "Loren Schwappach" ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A2A0 ; Set location for storage of stringExit_World1 FCC "Exiting EE312Lab" ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor ORG $A2C0 ; Set location for storage of stringExit_World2 FCC "Press reset btn " ; Form Constant Character for LCD "16 character" display FCB EOT ; Form Constant Block at location above + 17 for output to monitor* ------------------------* Call program and set Stack location* ------------------------Start ORG Program_loc ; Set location counter for program storage { Program starts at$9000 } LDS #Stack_loc ; Loads begining storage location for stack at $C800 JSR Main_func ; Jumps over all subroutines below to main subroutine at bottom ofpageProfessor: Pamela Hoffman Page 29 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 JSR Clear_reg ; Jump to subroutine clear registersTerminate END ; Ends Program* ------------------------* Subroutines* ------------------------* Clear RegistersClear_reg LDAA #$00 ; Load Accum. A w/ 0 LDAB #$00 ; Load Accum. B w/ 0 LDX #$0000 ; Load Index Reg X w/ 0 LDY #$0000 ; Load Index Reg Y w/ 0 RTS ; Return to Subroutine which called this* Delay SubroutinesDelay DEX ; Decrement X {Take up some time.. clock cycles} INX ; Increment X {Take up some time.. clock cycles} DEX ; Decrement X, initial X value provided by routine that called this BNE Delay ; Branch if not equal to 0 to Delay.. loop until X=0 RTS ; Return to Subroutine which called thisDelay_1ms PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #One_ms ; Load X with value referenced by EQU above BSR Delay ; With retrieved X value obtained branch to delay to take upindicated time PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called thisDelay_10ms PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Ten_ms ; Load X with value referenced by EQU aboveProfessor: Pamela Hoffman Page 30 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 BSR Delay ; With retrieved X value obtained branch to delay to take upindicated time PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called thisDelay_100ms PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Hundred_ms ; Load X with value referenced by EQU above BSR Delay ; With retrieved X value obtained branch to delay to take upindicated time PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called thisDelay_Var_ms PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Var_ms ; Load X with value referenced by EQU above BSR Delay ; With retrieved X value obtained branch to delay to take upindicated time PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called this* Clear LEDsClear_LEDs PSHA ; Push A onto stack, prevents loss of data stored in A duringsubroutine use LDAA #0 ; Load Accum A w/ value 0 {All LEDs out} STAA Port_B ; Stores value at Port_B {All LEDs out} PULA ; Pull A value stored in stack to A, restores data stored in Abefore subroutine call RTS ; Return to Subroutine which called this* Create beep sound at 25 pulsesBeep_once PSHX ; Push X onto stack, prevents loss of data stored in X during subroutineuseProfessor: Pamela Hoffman Page 31 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 PSHY ; Push Y onto stack, prevents loss of data stored in Y during subroutineuse PSHA ; Push A onto stack, prevents loss of data stored in A during subroutineuse LDX #25 ; Load X w/ value 25 {controls beep loops, pulses}Beep_once_loop LDAA #$20 ; Load A w/ value $20 {Determines sound/tone of beep} STAA Port_A ; Stores A in Port_A {Makes beep sound} JSR Delay_1ms ; Takes up some time LDAA #$00 ; Loads A w/ value 0 STAA Port_A ; Stores A in Port_A {Clears beep sound} JSR Delay_1ms ; Takes up some time DEX ; Decrements X CPX #0 ; Compares X w/ value 0 BNE Beep_once_loop ; Branches, loops.. if X does not equal 0 PULA ; Pull A value stored in stack to A, restores data stored in A beforesubroutine call PULY ; Pull Y value stored in stack to Y, restores data stored in Y beforesubroutine call PULX ; Pull X value stored in stack to X, restores data stored in X beforesubroutine call RTS ; Return to Subroutine which called this* Display race track, "LEDs circle around bread board"* If I had more time I had plans to allow user input* determine speed (Delay_Var_ms)Racetrack_sim PSHA ; Push A onto stack, prevents loss of data stored in A during subroutineuse PSHX ; Push X onto stack, prevents loss of data stored in X during subroutineuse JSR Clear_LEDs ; Clear LEDs LDX #10 ; Load X w/ value {determines number of loops}Race_loop LDAA #$01 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off 1 on, for 8LEDs}Professor: Pamela Hoffman Page 32 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 JSR Beep_once ; Beep JSR Delay_Var_ms ; Takes up some time LDAA #$02 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off 1 on, for 8LEDs} JSR Beep_once ; Beep JSR Delay_Var_ms ; Takes up some time LDAA #$04 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off 1 on, for 8LEDs} JSR Beep_once ; Beep JSR Delay_Var_ms ; Takes up some time LDAA #$08 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off 1 on, for 8LEDs} JSR Beep_once ; Beep JSR Delay_Var_ms ; Takes up some time LDAA #$10 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off 1 on, for 8LEDs} JSR Beep_once ; Beep JSR Delay_Var_ms ; Takes up some time LDAA #$20 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off 1 on, for 8LEDs} JSR Beep_once ; Beep JSR Delay_Var_ms ; Takes up some time LDAA #$40 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off 1 on, for 8LEDs} JSR Beep_once ; Beep JSR Delay_Var_ms ; Takes up some time LDAA #$80 ; Loads A w/ value, determines what LED will lightProfessor: Pamela Hoffman Page 33 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off 1 on, for 8LEDs} JSR Beep_once ; Beep JSR Delay_Var_ms ; Takes up some time DEX ; Decrement X by 1 CPX #0 ; Compare X to 0 BEQ Exit_race_loop ; Branches out of loop if X = 0 JMP Race_loop ; Loop if X does not equal 0Exit_race_loop JSR Clear_LEDs ; Clear LEDs PULX ; Pull X value stored in stack to X, restores data stored in X beforesubroutine call PULA ; Pull A value stored in stack to A, restores data stored in A beforesubroutine call RTS ; Return to Subroutine which called this* Flash LEDs in a pulse patternFlash_LEDs_osc PSHA ; Push A onto stack, prevents loss of data stored in Aduring subroutine use PSHX ; Push X onto stack, prevents loss of data stored in Xduring subroutine use JSR Clear_LEDs ; Clear LEDs LDX #10 ; Load X w/ value used for # of loopsLED_loop_osc LDAA #$18 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off1 on, for 8 LEDs} JSR Beep_once ; beep when LEDs touch JSR Delay_100ms ; Takes up some time LDAA #$24 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off1 on, for 8 LEDs} JSR Delay_100ms ; Takes up some time LDAA #$42 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off1 on, for 8 LEDs} JSR Delay_100ms ; Takes up some timeProfessor: Pamela Hoffman Page 34 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 LDAA #$81 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off1 on, for 8 LEDs} JSR Delay_100ms ; Takes up some time LDAA #$42 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off1 on, for 8 LEDs} JSR Delay_100ms ; Takes up some time LDAA #$24 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off1 on, for 8 LEDs} JSR Delay_100ms ; Takes up some time DEX ; Decrement X by 1 BNE LED_loop_osc ; Loop if X does not equal 0Exit_LED_loop_osc LDAA #$18 ; Loads A w/ value, determines what LED will light STAA Port_B ; Stores A at port B, lights LEDs indicated by value {0 off1 on, for 8 LEDs} JSR Delay_100ms ; Takes up some time JSR Clear_LEDs ; Clear LEDs PULX ; Pull X value stored in stack to X, restores data storedin X before subroutine call PULA ; Pull A value stored in stack to A, restores data storedin A before subroutine call RTS ; Return to Subroutine which called this* Read buttons PA0, PC1, and PC0Read_button LDAA Port_C ; Load A w/ value at Port C COMA ; Invert bits in A ANDA #$03 ; AND A w/ value $03, lowest 2 bits only LDAB Port_A ; Load B w/ value at Port A COMB ; Invert bits in B ANDB #$01 ; AND B w/ value $01, lowest bit only ASLB ; Arithmatic Shift Left Accum B ASLB ; Arithmatic Shift Left Accum BProfessor: Pamela Hoffman Page 35 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 ABA ; Add B to A store in A RTS ; Return to Subroutine which called this* Subroutines which run depending upon user input {btn press}* Note: Had to create these Check buttons because BNE* is limited to how far it can branch to..Run_math PSHA ; Push A onto stack, prevents loss of data stored in A duringsubroutine use PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use JSR Add_numbers ; Jump to Sub Routine JSR Display_press_btn ; Jump to Sub Routine PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call PULA ; Pull A value stored in stack to A, restores data stored in Abefore subroutine call JMP Check_buttons ; Jump back to Check_buttonsRun_race PSHA ; Push A onto stack, prevents loss of data stored in A duringsubroutine use PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use JSR Racetrack_sim ; Jump to Sub Routine PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call PULA ; Pull A value stored in stack to A, restores data stored in Abefore subroutine call JMP Check_buttons ; Jump back to Check_buttonsRun_LEDs PSHA ; Push A onto stack, prevents loss of data stored in A duringsubroutine use PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use JSR Flash_LEDs_osc ; Jump to Sub Routine PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine callProfessor: Pamela Hoffman Page 36 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 PULA ; Pull A value stored in stack to A, restores data stored in Abefore subroutine call JMP Check_buttons ; Jump back to Check_buttons* Check buttons PA0, PC1, and PC0 and do somethingCheck_buttons LDX #12 ; Load X w/ value used for determining when loop should end LDY #4000 ; Load Y w/ value used for determining when loop should endCheck_buttons_loop BSR Read_button ; Branch to Sub Routine to read button STAA Port_B ; Stores read button result in A BITA #$01 ; Is PC0 pressed? BNE Run_LEDs ; Then run LEDs, If A does not equal 0 BITA #$02 ; Is PC1 pressed? BNE Run_race ; Then run LED racetrack, If A does not equal 0 BITA #$04 ; Is PA0 pressed? BNE Run_math ; Then run math program, If A does not equal 0 DEY ; Decrement Y by 1 CPX #10 ; Compare X to value BEQ Disp_t_warning0 ; If X = value branch to location given CPX #8 ; Compare X to value BEQ Disp_t_warning1 ; If X = value branch to location given CPX #4 ; Compare X to value BEQ Disp_t_warning2 ; If X = value branch to location given CPX #0 ; Compare X to value BEQ Check_buttons_done ; If X = value branch to location given CPY #0 ; Compare Y to value BEQ Decrement_X ; If X = value branch to location given JMP Check_buttons_loop ; Loop if X does not equal 0Decrement_X DEX ; Decrement X JMP Check_buttons_loop ; Jump back to loopCheck_buttons_done RTS ; Return to Subroutine which called thisProfessor: Pamela Hoffman Page 37 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009* Display time warnings* Display clear screen..Disp_t_warning0 PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Clear_LCD ; Load Clear LCD string location in X JSR LCD_write_top ; Display 16 Character string at loc X on top LCD PULX ; Pull X value stored in stack to X, restores data stored in X beforesubroutine call JMP Decrement_X ; Jump to location* Display 20s left warning..Disp_t_warning1 PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Warning2 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD JSR Beep_once ; Beep PULX ; Pull X value stored in stack to X, restores data stored in X beforesubroutine call JMP Decrement_X ; Jump to location* Display 10s left warning..Disp_t_warning2 PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Warning3 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD JSR Beep_once ; Beep PULX ; Pull X value stored in stack to X, restores data stored in X beforesubroutine call JMP Decrement_X ; Jump to location* Display 15 max char warning..Disp_char_warning PSHX ; Push X onto stack, prevents loss of data stored in Xduring subroutine use LDX #Warning1 ; Load X w/ location of stringProfessor: Pamela Hoffman Page 38 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #Warning1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at Xand ending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by aline feed JSR Beep_once ; Beep PULX ; Pull X value stored in stack to X, restores data storedin X before subroutine call RTS ; Return to Subroutine which called this* Pause for Carraige Return keyPause_return PSHA ; Push A onto stack, prevents loss of data stored in A during subroutineuseCR_loop JSR Input_get_char ; Jump to Sub Routine that gets a single ASCII character from keyboard andstores in A CMPA #CR ; Compares A with ASCII CR BEQ Out_CR_loop ; Branch out of loop if equal JMP CR_loop ; If not equal.. stay in loopOut_CR_loop PULA ; Pull A value stored in stack to A, restores data stored in A beforesubroutine call RTS ; Return to Subroutine which called this* Clear LCDDisp_LCD_clear PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Clear_LCD ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #Clear_LCD ; Load X w/ location of string JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCD PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called this* Display Welcome & Pause for CR KeyProfessor: Pamela Hoffman Page 39 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Disp_welcome PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Welcome1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #Welcome2 ; Load X w/ location of string JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCD LDX #Welcome1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR LDX #Welcome2 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Pause_return ; Jump to Sub Routine that pauses until user presses enter key.. CR PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called this* Display Question_Name & Pause for CR KeyDisp_q_name PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Question_Name1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #Question_Name2 ; Load X w/ location of string JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCD LDX #Question_Name1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR LDX #Question_Name2 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Pause_return ; Jump to Sub Routine that pauses until user presses enter key.. CR JSR Disp_LCD_clear ; Jump to Sub Routine to clear LCDsProfessor: Pamela Hoffman Page 40 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 JSR Disp_char_warning ; Jump to Sub Routine JSR Pause_return ; Jump to Sub Routine that pauses until user presses enter key.. CR PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called this* Displays NameDisplay_name PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use LDX #Response_Name1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #Username ; Load X w/ location of string JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCD JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed LDX #Response_Name1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR LDX #Username ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Pause_return ; Jump to Sub Routine that pauses until user presses enter key.. CR JSR Disp_LCD_clear ; Jump to Sub Routine to clear LCDs PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called this* Displays Press a ButtonDisplay_press_btn PSHX ; Push X onto stack, prevents loss of data stored in Xduring subroutine use LDX #Press_Btn1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #Press_Btn2 ; Load X w/ location of string JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCDProfessor: Pamela Hoffman Page 41 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by aline feed LDX #Press_Btn1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at Xand ending when ASCII CR LDX #Press_Btn2 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at Xand ending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by aline feed PULX ; Pull X value stored in stack to X, restores data storedin X before subroutine call RTS ; Return to Subroutine which called this* Displays CreditsDisplay_credits PSHX ; Push X onto stack, prevents loss of data stored inX during subroutine use LDX #Credits1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #Credits2 ; Load X w/ location of string JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCD JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by aline feed LDX #Credits1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at Xand ending when ASCII CR LDX #Credits2 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at Xand ending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by aline feed JSR Pause_return ; Jump to Sub Routine that pauses until user presses enterkey.. CR PULX ; Pull X value stored in stack to X, restores data storedin X before subroutine call RTS ; Return to Subroutine which called thisProfessor: Pamela Hoffman Page 42 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009* Displays Final OutputDisplay_exit_world PSHX ; Push X onto stack, prevents loss of data stored in Xduring subroutine use LDX #Exit_World1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #Exit_World2 ; Load X w/ location of string JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCD JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by aline feed LDX #Exit_World1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at Xand ending when ASCII CR LDX #Exit_World2 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at Xand ending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by aline feed JSR Pause_return ; Jump to Sub Routine that pauses until user presses enterkey.. CR PULX ; Pull X value stored in stack to X, restores data storedin X before subroutine call RTS ; Return to Subroutine which called this* Loop to get & math numbers..Add_numbers PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use PSHY ; Push Y onto stack, prevents loss of data stored in Y duringsubroutine use PSHA ; Push A onto stack, prevents loss of data stored in A duringsubroutine use PSHB ; Push B onto stack, prevents loss of data stored in B duringsubroutine useAdd_nmbrs_loop JSR Beep_once ; Beep LDX #MathA_1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #MathA_2 ; Load X w/ location of stringProfessor: Pamela Hoffman Page 43 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCD LDX #MathA_1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR LDX #MathA_2 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Pause_return ; Jump to Sub Routine that pauses until user presses enter key.. CR JSR Beep_once ; Beep LDX #MathB_1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #MathB_2 ; Load X w/ location of string JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCD LDX #MathB_1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR LDX #MathB_2 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CRGet_value1 JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Pause_return ; Jump to Sub Routine that pauses until user presses enter key.. CR JSR Beep_once ; Beep LDX #MathC_1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #MathC_1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Input_get_char ; Jump to Sub Routine that gets a single ASCII character fromkeyboard and stores in A CMPA #$2F ; Compare A w/ value {ASCII value before ASCII 0} BLS Get_value1 ; Branch if lower or same (Used to ensure only an ASCII 0-4 areentered)Professor: Pamela Hoffman Page 44 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 CMPA #$35 ; Compare A w/ value {ASCII value after ASCII 4} BHS Get_value1 ; Branch if higher or same (Used to ensure only an ASCII 0-4 areentered) SUBA #$30 ; Subtracts $30 from value to convert ASCII (0 to 4) to actual hexvalue STAA Value1 ; Stores A at locationGet_value2 JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Pause_return ; Jump to Sub Routine that pauses until user presses enter key.. CR JSR Beep_once ; Beep LDX #MathD_1 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on bottom LCD LDX #MathD_1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Input_get_char ; Jump to Sub Routine that gets a single ASCII character fromkeyboard and stores in A CMPA #$2F ; Compare A w/ value {ASCII value before ASCII 0} BLS Get_value2 ; Branch if lower or same (Used to ensure only an ASCII 0-4 areentered) CMPA #$35 ; Compare A w/ value {ASCII value after ASCII 4} BHS Get_value2 ; Branch if higher or same (Used to ensure only an ASCII 0-4 areentered) SUBA #$30 ; Subtracts $30 from value to convert ASCII (0 to 4) to actual hexvalue STAA value2 ; Stores A at locationAdd_values LDAA Value1 ; Loads A w/ value at location given ADDA value2 ; Adds A to value at location stores in A ADDA #$30 ; Adds $30 to A -> converts Hex value (0-8) into ASCII (0-8) STAA Result ; Stores A in Result StringResult_section JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Beep_once ; Beep LDX #MathE_1 ; Load X w/ location of stringProfessor: Pamela Hoffman Page 45 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #MathE_1 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR LDX #Result ; Load X w/ location of string JSR LCD_write_bottom ; Display 16 Character string at loc X on bottom LCD LDX #Result ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Pause_return ; Jump to Sub Routine that pauses until user presses enter key.. CR JSR Beep_once ; BeepClose_add PULB ; Pull B value stored in stack to B, restores data storedin B before subroutine call PULA ; Pull A value stored in stack to A, restores data stored in Abefore subroutine call PULY ; Pull Y value stored in stack to Y, restores data stored in Ybefore subroutine call PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called this* Loop to get & store name..Get_name PSHX ; Push X onto stack, prevents loss of data stored in X duringsubroutine use PSHY ; Push Y onto stack, prevents loss of data stored in Y duringsubroutine use PSHA ; Push A onto stack, prevents loss of data stored in A duringsubroutine use LDX #Question_Name3 ; Load X w/ location of string JSR LCD_write_top ; Display 16 Character string at loc X on top LCD LDX #Question_Name3 ; Load X w/ location of string JSR Output_disp_text ; Jump to Sub Routine that outputs all ASCII starting at X andending when ASCII CR JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feed JSR Output_disp_CR ; Jump to Sub Routine that outputs ASCII CR followed by a line feedProfessor: Pamela Hoffman Page 46 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 LDX #Username ; Load X w/ location of string LDY #0 ; Load Y w/ location of stringGet_name_loop CPY #15 ; Compares Y w/ value 15 {Prevents user from inputing too manystrings} BEQ Close_Get_name ; Braches if Equal to location outside of loop JSR Input_get_char ; Jump to Sub Routine that gets a single ASCII character fromkeyboard and stores in A CMPA #CR ; Compare A w/ ASCII CR BEQ Close_Get_name ; Braches if Equal to location outside of loop CMPA #$1F ; Compare A w/ illegal character (Not 0-9, or A-Z, or a-z) BLS Get_name_loop ; Branch Lower or Same.. loops for new character if illegalencountered CMPA #$7F ; Compare A w/ illegal character (Not 0-9, or A-Z, or a-z) BHS Get_name_loop ; Branch Higher or Same.. loops for new character if illegalencountered STAA 0,X ; Store A at location in X INY ; Increment Y {Used to count # of characters} INX ; Increment X BRA Get_name_loop ; BranchClose_Get_name PULA ; Pull A value stored in stack to A, restores data stored in Abefore subroutine call PULY ; Pull Y value stored in stack to Y, restores data stored in Ybefore subroutine call PULX ; Pull X value stored in stack to X, restores data stored in Xbefore subroutine call RTS ; Return to Subroutine which called this* ------------------------* Start Main_func program* ------------------------Main_func JSR LCD_init ; Initialize LCD JSR Clear_LEDs ; Clear LEDs JSR Disp_LCD_clear ; Clear LCDs JSR Disp_welcome ; Jump to Subroutine to displays welcomeProfessor: Pamela Hoffman Page 47 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009 JSR Flash_LEDs_osc ; Jump to Subroutine to flash leds in a pulse pattern JSR Disp_q_name ; Jump to Subroutine to display question on LCD JSR Get_name ; Jump to Subroutine to get users name JSR Display_name ; Jump to Subroutine to display users name JSR Display_press_btn ; Jump to Subroutine to display statement on LCD JSR Check_buttons ; Jump to Subroutine to check buttons and do something JSR Display_credits ; Jump to Subroutine to display credits JSR Display_exit_world ; Jump to Subroutine to display exit world RTS ; Return to Subroutine which called thisNote: LAB Output: Because most of the program uses the LCDs and LEDs, it would bepointless and disappointing to be limited to the output I could captureusing terminal screenshots. Therefore, please copy/paste/assemble/load/and run the code above if you wish to see the program in action. You canalso use the trace “t” command to trace the changes to the PC, SP, andregisters, although be warned (The trace program will lose functionalityas soon as it enters the terminal I/O and Buffalo Monitor I/O subroutines.Remember you can also log terminal output to file! I used this trick withpreceding loabs.RE: Optimizing Code: I noticed a few areas where I could have removed some compareinstructions since the CCR was already set, I also noticed I could haveused the ROLA and RORA instructions in a loop for the racetrack modulewhich would have shortened the LED modules a bit.Professor: Pamela Hoffman Page 48 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 49 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 50 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 51 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 52 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 53 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 54 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 55 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 56 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 57 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 58 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 59 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 60 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 61 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 62 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 63 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 64 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 65 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 66 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 67 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 68 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 69 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 70 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 71 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 72 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 73 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 74 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 75 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 76 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 77 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 78 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 79 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 80 of 81 Colorado Technical University
    • EE312 Embedded Microcontrollers TUE / THU 9:00AMFinal Lab Spring 2009Professor: Pamela Hoffman Page 81 of 81 Colorado Technical University