EMCH 367 Fundamentals of MicrocontrollersExample 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
STARTLDX#REGBAS
LDAA#%00110000
STAABAUD,X
LDAA#%00000000
STAASCCR1,X
LDAA#%00001100
STAASCCR2,X
LABEL2LDAB#'T'
* Send the character to the terminal
LABEL3LDAASCSR,X
ANDA#%10000000
BEQLABEL3
* You are here when the transmission reg. is empty
STABSCDR,X
BRALABEL2
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:

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.

b)When the ‘check TDRE’ loop is exited, the program gets to the line

STABSCDR,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:

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.

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:

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 GiurgiutiuPage 1 10/21/2018

EMCH 367 Fundamentals of MicrocontrollersExample SCI TRANSMISSION

Dr. Victor GiurgiutiuPage 110/21/2018