EMCH 367 Fundamentals of Microcontrollers Example SCI TRANSMISSION EXAMPLE SCI TRANSMISSION OBJECTIVE This example has the following objectives: Review the use of serial communication interface (SCI) for transmission Illustrate the sending of a character through SCI PROGRAM SCI_TRANSMIT This program is an example of SCI transmission. The character T is being sent to SCDR when TDRE is set. Instructions a) Load REGBAS in reg. X b) Initialize BAUD=9600 c) Initialize 8-bit word d) Initialize TE and RE e) Load character 'T' in AccB f) Check if TDRE is set g) Store accB to SCDR h) Branch back to (v) i) SWI Flowchart Code START Initialize REGBAS in reg X Initialize SCI: BAUD = 9600 8-bit word TE=1, RE=1 LABEL2 Load ‘T’ in accB Check if TDRE is set LABEL3 Load SCSR into accA AND with mask %10000000 Loop if zero LDX #REGBAS LDAA #%00110000 STAA BAUD,X LDAA #%00000000 STAA SCCR1,X LDAA #%00001100 STAA SCCR2,X LABEL2 LDAB #'T' * Send the character to the terminal LABEL3 LDAA SCSR,X ANDA #%10000000 BEQ LABEL3 * You are here when the transmission reg. is empty STAB SCDR,X BRA LABEL2 SWI Store AccB to SCDR SWI FLOWCHART AND CODE The program flowchart is show to the right of the program instructions. Note the initialization block, which contains reg. X initialization and SCI initialization. After initialization, the character T is loaded into accB. Then, the status of TDRE (transmission data register empty) flag is checked in a loop. When TDRE is found set, the loop is exited and the contents of accB is stored in SCDR (serial communication data register). This operation automatically resets TDRE. Now, the program loops back to the beginning and tries to send again. The essential code for the program is shown to the right of the program flowchart. This essential code was incorporated into the standard asm template to generate the file SCI_transmit.asm. EXECUTION Open THRSim11. Close the Commands window. View serial registers. View serial receiver. Open and assemble SCI_transmit.asm. Set breakpoint at STAB SCDR,X instruction and at SWI. Reset registers. Set standard labels (Label/Set Standard Labels). Set display of accA to binary. Set display of BAUD, SCCR1, SCCR2, SCSR to binary. Arrange windows for maximum benefit: Reset, A, B, X. Press the RESET button. Your screen should look like this: Dr. Victor Giurgiutiu Page 12/12/2016 EMCH 367 Fundamentals of Microcontrollers Example SCI TRANSMISSION Note that the reset value of SCSR is %11000000, i.e., it has the flags TDRE and TC set. This indicates that the transmitter is ready to transmit. a) Press the RUN button. The program should loop on LABEL3 and exit the loop when the condition TDRE=1 is satisfy. This condition is checked with the mask %10000000. The mask is applied on the value found in SCSR. When bit 7 in SCSR is set, the mask senses it and the condition for exiting the loop is satisfied. Since TDRE=1 from the reset, the loop is passed through and exited. Dr. Victor Giurgiutiu Page 22/12/2016 EMCH 367 Fundamentals of Microcontrollers Example SCI TRANSMISSION b) When the ‘check TDRE’ loop is exited, the program gets to the line STAB SCDR,X This line is a breakpoint. At this moment, the screen looks like this: c) Step manually to the next line, which stores accB into SCDR. This store operation automatically resets TDRE. The screen looks like this: Dr. Victor Giurgiutiu Page 32/12/2016 EMCH 367 Fundamentals of Microcontrollers Example SCI TRANSMISSION Note that SCSR is %00000000. This proves that TDRE has been reset by the storing to SCDR. Also note that the value $54 from accB has not yet arrived in SCDR. (The reason for this is that the simulator has an internal delay when running SCI in manual mode.) d) Press RUN again. The program loops several times on LABEL3 before exiting. While looping, you can see SCSR=%00000000, i.e., TDRE=0. When exiting, SCSR=%10000000, i.e., TDRE=1. When the program pause, the screen looks like this: Note that SCSR=%10000000, i.e., TDRE=1. The transmission of the character was done, and SCI is ready to transmit again. Dr. Victor Giurgiutiu Page 42/12/2016 EMCH 367 Fundamentals of Microcontrollers Example SCI TRANSMISSION e) Press RUN again 2 times. Note that the character T has appeared in the serial receiver window. Your screen capture looks like this: f) Press RUN again. You get an additional character in the serial receiver window. Your screen capture looks like this: Dr. Victor Giurgiutiu Page 52/12/2016 EMCH 367 Fundamentals of Microcontrollers WHAT YOU HAVE LEARNED In this example, you have learned: The use of serial communication interface (SCI) for transmission The sending of a character through SCI New words and notations: SCSR, SCDR, TDRE. Dr. Victor Giurgiutiu Page 62/12/2016 Example SCI TRANSMISSION EMCH 367 Fundamentals of Microcontrollers Dr. Victor Giurgiutiu Page 72/12/2016 Example SCI TRANSMISSION EMCH 367 Dr. Victor Giurgiutiu Fundamentals of Microcontrollers Page 1 Example SCI TRANSMISSION 2/12/2016