Using the Serial Communications Interface (SCI) for the QE Microcontrollers
QE128 Quick Reference User Guide, Rev. 1.0
10-4
Freescale Semiconductor
Press any key and the character “1” appears.
10.3
SCI project for Demo board
10.3.1
Code Example and Explanation
This example code is available from the Freescale Web site www.freescale.com.
This section explains the differences of codes used in the EVB and Demo board. The codes are the same.
The project file contains the following functions:
•
main — Endless loop waiting for the SCI interrupt to occur.
•
MCU_Init – MCU initialization, watchdog disable and the SCI clock module enabled.
•
GPIO_Init – Configure PTC0-PTC5, PTE6 and PT7 as outputs.
•
SCI_Init – SCI module configuration.
•
SCI_RX_ISR — The data obtained by SCI module is display on eight LEDs and the character “1”
is send it by SCI.
This is the General Purpose Input/Output configuration. These code lines configure the direction for the
PTC port. Only six LEDs from the demo board are connected to the PTC port. The other two LEDs are
connected to the E port. In this example PTC0 to PTC5, and PTE6, PTE7 are configured as outputs in order
to drive LEDs.
void GPIO_Init(void) {
PTCDD = (UINT8) (PTCD | 0x3F); // Configure PTC0-PTC5 as outputs
PTEDD = (UINT8) (PTED | 0xC0); // Configure PTE6 and PTE7 pins as outputs
PTCD = 0x3F; // Put 1's in port C in order to turn off the LEDs
PTED = 0xC0; // Put 1's in port E port in order to turn off the LEDs
}
NOTE
This is the SCI service routine. Every time an SCI interrupt is detected, the
received data is displayed on eight LEDs and the character “1” is sent by
SCI. The VectorNumber_Vsci1rx can be replaced by the interrupt vector
number, this depends if the MCU is S08 or V1. Using this example makes
the code fully compatible for either MCU.
void interrupt VectorNumber_Vsci1rx SCI_RX_ISR(void) {
// SCI vector address = 15 (S08)
// SCI vector address = 77 (V1)
UINT8 temp;
SCI1S1_RDRF = 0; // Receive interrupt disable
temp = SCI1D; // Store the recieve value on temp variable
PTED = (UINT8) (temp & 0xC0); // Move the received value to port E
PTCD = (UINT8) (temp & 0x3F); // Move the received value to port C
while (SCI1S1_TDRE == 0); // Wait for the transmitter to be empty
SCI1D = '1'; // Send a character by SCI
}