EMCH 367 Dr. Victor Giurgiutiu Fundamentals of Microcontrollers Page 1 Lab 2 2/12/2016 EMCH 367 Fundamentals of Microcontrollers Lab 2 LAB 2 – PARALLEL AND SERIAL COMMUNICATION OBJECTIVE The objectives of this lab are to review the parallel and serial communication in the MC68HC11 microcontroller. The objective of this laboratory experiment is to learn how to use the serial communication port of the M68HC11. Basic concepts of serial communications will be reviewed. The registers used to transmit and receive serial communications data and the RDRF and TDRE flags used to identify whether or not serial communications data has been received or sent will be examined. The BAUD rate and other aspects of the serial communications interface (SCI) will be investigated.. Review the use parallel ports Illustrate the generation of a square wave using Port B output and a waiting sequence Illustrate the use of Port C for input and output using a 4-button 4-LED box Examine the relation between time and clock cycles Review the use of serial communications Investigate BAUD rate, ASCII code, 10-bit serial communication Develop and practice the concept of echo Measure serial communications signals, including the start bit, ASCII code, and the stop bit, using the oscilloscope with an external trigger generated by MCU PREREQUISITES Floppy disk with the asm codes for the programs: LASTNAME_Firstname_Buttons_bx.asm LASTNAME_Firstname_Sq_wav1.asm LASTNAME_Firstname_Sq_wav2.asm LASTNAME_Firstname_Echo.asm Hard copy (printout) of Hmwk4a and Hmwk 4b. When printing, use the 'pages per sheet' option in the lower right corner of the print dialog-box with settings of 4 or 2 (depending on your eyesight) to save paper. (We may want to experiment a little with this before printing the full document.) PROCEDURE The students will utilize the asm code developed with the THRSim11 simulator for Hmwk4a and Hmwk4b. The students will go through their Hmwk4a and Hmwk4b step by step and will verify that the MCU responds to instructions as expected. The lab is divided into sections. After completing each section, the student will ask the TA to check the student’s work and make a check mark on that section. The asm code is activated into the MCU following the standard procedure learned in Lab 1. Dr. Victor Giurgiutiu Page 2 2/12/2016 EMCH 367 Fundamentals of Microcontrollers Lab 2 WARM UP EXERCISES 1) Connect the oscilloscope Channel 1 through a hook probe to Port B Pin0 using a male connector. Set the oscilloscope Channel 1 to DC, 5V/div, and zero vertically in mid screen. Use the MM command to put $01 into PORTB, i.e., in the MCU address $1004. The oscilloscope signal should jump to 5 V. Put again $00 in PORTB. The oscilloscope signal should jump to 0 V. Do you observe this? ___ Y ___ N 2) Assume $A5 is loaded into PORTB at address $1004. What will be the output of parallel port B? Predict the results in the table below. Label which pin is the MSB. Port B pins PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0 Value Use the MM command to put $A5 into PORTB, i.e., in the MCU address $1004. Verify the output of parallel port B with the oscilloscope and the 8-LED display. Check the voltages on all of the pins of parallel port B (PB0 - PB7) with the oscilloscope. Then check them with the 8-LED display. Write down your observations. PB0: V PB1: V PB2: V PB3: PB4: V PB5: V PB6: V PB7: When satisfied with your results, call your TA and demonstrate. TA checkmark ________ 3) If you place $fa in DDRC at address $1007 and then load $c8 into PORTC at address $1003, what will be the output of parallel port C? Enter your prediction in the table below. DDRC pins Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 PC7 PC6 PC5 PC4 PC3 PC2 PC1 PC0 Value Port C pins Value Load $fa in DDRC at address $1007 and then load $C8 into PORTC at address $1003. Verify the output of parallel port C. Check the voltages on all of the PC0 - PC7 pins of parallel port C with the oscilloscope probe. Then check them with the 8-LED display. Write down your observations. PC0: V PC1: V PC2: V PC3: PC4: V PC5: V PC6: V PC7: When satisfied with your results, call your TA and demonstrate. TA checkmark ________ Dr. Victor Giurgiutiu Page 3 2/12/2016 EMCH 367 Fundamentals of Microcontrollers Lab 2 SQUARE WAVE Use the code LASTNAME_Firstname_Sq_wav2.asm generated in Hmwk4a. The parallel port B is used to generate a square wave. A square wave is a signal that is high for a specified period of time, then low for a specified period of time. In this case, the high state will be +5V, and the low state will be 0V. Your target is to generate a square wave signal with the period of time for each state (half-wavelength) approx. 100 s. The square wave signal generated by your MCU will be measured on the oscilloscope screen and compared with your predictions. Your code should make the MCU send out a low signal for a specified time, then a high signal for the same time. After sending out a high signal and then a low signal, it will repeat the process. The duration of the high and low states is specified using the variable DELAY. The variable DELAY is used in a wait subroutine. The MCU is a very fast device. Our M68HC11 has an 8 MHz crystal, which generates a 2 MHz clock speed. Compute and answer the following questions: a) What is the shortest duration of time that the oscilloscope can measure per division? Look up on the oscilloscope panel and enter your answer here: ___________________________ b) What is the duration of an M68HC11 machine cycle? Calculate your answer using the M68HC11 clock speed of 2 MHz and enter your answer here: ________________________ Activate the code LASTNAME_Firstname_Sq_wav2.asm. According to your Example Square wave, when value $40 is entered in DELAY (The address of DELAY is 0000; Buffalo command MM 0000 is used to change the value of DELAY), the length of your half-wave, t, should be 165 s. Hook the oscilloscope probe to the pin corresponding to your coding, and verify that what you see on the oscilloscope screen meets with your predictions. (Adjust the time/div button to see the square wave properly…). Write here the half-wavelength value read on the oscilloscope screen ______ s. Change DELAY to the other values given in the table below, and run your program again. Enter the t (sec) predicted by you using the simulator (see Hmwk4a) and the values read on the oscilloscope screen. DELAY t (sec) Measured by simulator t (sec) Measured on oscilloscope Col 3 Error, % (col 2 – col 3)/col 3 Col 1 Col 2 Col 4 $10 $__ 100 100 0% $40 165/166 165 0.3% $A0 $FF Try to adjust the value of DELAY to have the half-wave last 100 s. With just a few trials, you should be able to find the right value of DELAY to achieve this. The value you found is: DELAY = $_________ Enter the value in the table. When satisfied with your results, call your TA and demonstrate. TA checkmark ________ Dr. Victor Giurgiutiu Page 4 2/12/2016 EMCH 367 Fundamentals of Microcontrollers Lab 2 BUTTONS BOX You are given a box (see Figure) with four buttons and four LED’s (light emitting diodes). When pressed, the buttons (B0, B1, B2, B3) produce either +5 Volt (Normally Open = N.O. type buttons) or 0 Volt (Normally Closed = N.C. type buttons). The buttons are connected (through a port protection card) to the even port C pins PC0, PC2, PC4, and PC6. The LED’s are connected to the odd port C pins PC1, PC3, PC5, and PC7. Port C B0 5V PC7 PC1 LED’s 0V PC3 PC5 5V Buttons PC0 PC2 PC4 PC0 L0 B1 PC2 L1 0V PC6 B2 5V Port C connection Figure 1 L2 0V 0V PC3 PC4 5V Wires: Green=Gnd Red = +5 V PC1 B3 PC5 PC6 L3 PC7 The 4-Button 4-LED Box: (a) photo; (b) diagram Attach the box to the microprocessor through a port protection card. Be careful that you connect the MSB of the button box to the MSB of the microprocessor. Activate your LASTNAME_Firstname_Buttons_bx.asm program. Press buttons and see how the corresponding LED is lighting up. When satisfied with your results, call your TA and demonstrate. TA checkmark ________ Dr. Victor Giurgiutiu Page 5 2/12/2016 EMCH 367 Fundamentals of Microcontrollers Lab 2 SERIAL COMMUNICATION ECHO You wish to create a program that will receive a keystroke from the terminal keyboard, and echo the same keystroke, continuously, to the terminal screen. The program will also let you see the binary pattern of keystrokes sent from the computer to the MCU. To achieve this, you will continuously check if the MCU has received, via SCI reception, a keystroke from the computer keyboard. When a key has been pressed, you will send out its ASCII value through the parallel port B, and back through the SCI transmission. A LED board, affixed to the parallel port B, will display the bit pattern of the ASCII value. This way, you check that the bit pattern corresponds to the ASCII table. Serial cable Wire connected to TXD pin PD1 Figure 2 Dr. Victor Giurgiutiu Connection diagram of serial communication Page 6 2/12/2016 EMCH 367 Fundamentals of Microcontrollers Lab 2 You will also monitor the communication by tapping the serial communications signal and displaying it on the oscilloscope screen. You will be able to see the complete 10-bit pattern, and the time duration of the communication. This exercise is based on Hmwk4b, Serial communication. a) Fill in the ASCII codes for each key listed in Table #1. b) Connect the LED board to port B. Attach a probe from channel 2 to parallel port C. Attach another probe from O-scope channel 1 to the leading out wire (serial communication TXD pin PD1). Set the O-scope trigger to channel 2, Set display to “Both”. c) Activate your code LASTNAME_Firstname_Echo.asm. in the MCU and run it. Press key "Q" on the keyboard. The character should appear on the screen continuously, while its ASCII code is sent out through the parallel port B and displayed on the LED board. Read the bit pattern displayed on the LED board and enter it in Table #1. Write the equivalent Hex number and compare the ASCII code. d) Manipulate the time (horizontal) scale, amplitude (vertical) scale, and the trigger level, until you see both the triggering pulse and the serial communications transmission. Identify the start bit, the ASCII code for the character being transmitted, and the stop bit on the oscilloscope screen. Compare the ASCII code listed in M68HC11 Quick Reference Manual to the one displayed on the oscilloscope. Enter your answer in Table 1. e) Use the oscilloscope to calculate the BAUD rate of the MCU Duration of signal t = ________ ms; Number of bits read in the signal N = ________; Calculated BAUD rate = # of bits/duration = Nt =____________bits/sec f) Repeat for keys 0, 3, 8, D. g) Sketch below the 10-bit pattern observed on the oscilloscope screen for character Q. Dr. Victor Giurgiutiu Page 7 2/12/2016 EMCH 367 Fundamentals of Microcontrollers Lab 2 TABLE 1 Key Q ASCII code 51 0 3 8 D LED MSBLSB 8-bit pattern Equivalent Hex values O-scope 8-bit pattern* Equivalent Hex values * This should be the 8-bit character as you see it on the O-scope screen. When satisfied with your results, call your TA and demonstrate. TA checkmark ________ Dr. Victor Giurgiutiu Page 8 2/12/2016 EMCH 367 Dr. Victor Giurgiutiu Fundamentals of Microcontrollers Page 9 106727435 2/12/2016 EMCH 367 Dr. Victor Giurgiutiu Fundamentals of Microcontrollers Page 10 106727435 2/12/2016