DOC PREVIEW
UCSC CMPE 012 - Lecture Notes

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

AbstractA microcontroller is a microprocessor that controls everydayappliances such as microwaves and wristwatches. Themicrokits used by computer engineering classes use a MotorolaHC11 microcontroller for all of the processing. The HC11microkits have 8 input switches, a single interrupt request but-ton (IRQ), 8 output LEDs, and a two-line liquid crystal dis-play (LCD). The HC11 kit also has a pulse accumulator, or acounter, which is incremented once per clock cycle. I wrote aprogram for the HC11 that computes two random numbersand adds or subtracts them, depending on the user input. Theprocedure I used to compute a random number is simply this:When an external interrupt is encountered (the interrupt re-quest (IRQ) button is depressed), take the remainder of thepulse accumulator (counter) divided by 9. The result of thisoperation gives a number between 0 and 9. Do this twice,adding or subtracting the values and displaying the result inhexadecimal format to the LCD. Simultaneously with the ad-dition or subtraction, step the lights once in their light pattern,flipping all of the on lights to off and vice versa. This series ofinstructions makes use of the pulse accumulator as well asinternal interrupts (generated by my program) and externalinterrupts (the IRQ button). The pulse accumulatorinitializations were written by Stephen Petersen.The HC11Alexandra Carey & Richard HugheyUniversity of California, School of EngineeringSanta Cruz, CA 95064IntroductionThe HC11A8 is the first microprocessor in a line of HC11processors by Motorola. These microkits are used in a fewcomputer engineering courses at UCSC. The first of thesecourses is computer engineering 12c, introduction to computerorganization. In the second half of this class, the students areasked to program in HC11 assembly language, which givesstudents an abstract view of the way a computer works.Initially, the program (a hexadecimal adder and subtractor)prints a welcome message and enters an infinite loop waitingfor an interrupt. The interrupt is received in the form of theIRQ pin by the switches, and will begin the program. Beforedepressing this button, select a function by entering the binarypattern string on the switches. The valid inputs are listed inFigure 1. After selecting the functionality and depressing theIRQ, the first thing the user will notice is that the light emit-ting diodes (LEDs) are flashing with a pattern – each lightalternates from on to off. Next, the user may notice the LCDhas displayed the first problem. There is a short delay beforethe answer is produced. The user does not need to input theanswer, only to think of it or say it out loud. An example ofthe output is in Figure 3. The program then waits indefinitely,flashing the lights, until the IRQ is depressed again, and thenperforms the requested action.Materials and Methods - AlgorithmInitialization• Download and execute program. The program is nowknown as the resident program.• Initialize Registers. See Figure 2 for more informationon the registers available to the user.• Store the address of the IRQ interrupt service routine (ISR)by storing the address of the ISR to the address of theIRQ pin on the interrupt table. The ISR is simply a pro-cedure that will handle the interrupt – that is, when aninterrupt occurs, it will be sent to this location in memoryand will execute the code there until told to go back. Theinterrupt table holds information about all sorts of differ-ent interrupts that could occur while executing a residentprogram.• Clear the LCD and display welcome messages.Main loop• Enter the main loop. Here, the light pattern flips all onesto zeros and all zeros to ones and the user input (comingfrom the SWITCHES) locks by storing the bit pattern tomemory. The bit pattern is then checked against one ofthree input values: 0000 0000, 0000 0001, and 0000 0011for add, subtract, and restart. All other values are regardedas the last operation processed.• Perform some preliminary steps before computation. Ifthe user wishes to add, then store a plus sign (+) to a vari-able in memory for later use. If subtracting is selected,store a minus sign (-). Restarting will send the programback to the point of displaying initial welcome messagesto the LCD.• Reset the user input and resume operation from the mainloop.Interrupt processing• When the IRQ is depressed, immediately rush to the ISRfor the IRQ. Do not even wait to finish the instruction inexecution! On the way there, save all of the importantinformation (stored in the registers and accumulator) ontothe system stack.• From within the interrupt, compute the random numbers,add or subtract them, and display the result. Next, clearthe user input and return, restoring all saved registers.Calculation and Display• Generate the pseudorandom numbers by finding the re-mainder of division of the pulse accumulator by 9. Thisgives a value between 0 and 8. If the two random num-bers are not in the 0-9 range, add hexadecimal 37 to boostthem up to the uppercase hex values on the ASCII table.Else add #$30 (hexadecimal) to make them ASCII nu-merals.• Sort in descending order. This will guarantee that therewill be no negatives!• Print the numbers, displaying the sign (+/-) between them.Print the equal sign.• Adding or subtracting the two values usually will give ahexadecimal result between 0 and F. Convert the resultto a printable character by adding the appropriate hexa-decimal values. Create a short delay (thinking time!) anddisplay the result in the same manner.• Return from interrupt to Main loop, restoring variablesfrom stack.ResultsUnanticipated Features (Bugs)1.Lights flash slower when switches are 0000 0011. This isbecause the restart routine will display welcome messagesto the LCD. Each message has a short delay, thus slow-ing the entire procedure.2.As soon as value on SWITCHES changes to 0000 0011,the program goes to restart mode, not waiting for the IRQto be depressed.3.Lights do not flash while displaying answer. This is be-cause the answer is calculated and displayed from withinthe interrupt, and the light flashing routine is in the mainprogram.4.Interrupts are not debounced. That is, one press of theIRQ may spawn several nested interrupts. The conse-quence is a number of result digits are displayed onto thescreen.5.Only one digit arithmetic is supported.6.Result of addition of 8+8=G, which is not a hexadecimalvalue.Future


View Full Document

UCSC CMPE 012 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?