13.7
Program Example for UART
This section provides program example for UART.
■
Program Example for UART
● Program specifications
•
Serial data transfer is implemented using the UART communication functions.
•
The P30/UCK/SCK, P31/UO/SO, and P32/UI/SI pins are used for communication.
•
The transfer rate is set to 300 bps using the internal baud rate generator.
•
13
is transmitted from the UO pin, and data is received by interrupts.
H
•
The baud rate is the oscillation frequency (F
cycle = 4/F
● Coding example
PDR3
DDR3
SSEL
SMC
SRC
SSD
SIDR
SODR
UPC
ILR2
INT_V
IRQ6
IRQ5
INT_V
;--------------------Main program---------------------------------------------------------------------------
). The clock divider is 2.5. (1/375 bps = 8320 t
CH
EQU
000CH
EQU
000DH
EQU
003BH
EQU
0028H
EQU
0029H
EQU
002AH
EQU
002BH
EQU
002BH
EQU
002CH
EQU
007CH
DSEG
ABS
ORG
0FFEEH
DW
WARI2
DW
WARI1
ENDS
CSEG
:
CLRI
MOV
ILR2,#11101011B
MOV
UPC,#11111010B
MOV
SSEL,#00000000B ; Select UART.
MOV
DDR3,#00000000B ; Set the UI pin as the input pin.
MOV
SMC,#01011011B
= 12.5 MHz) at the maximum gear speed (1 instruction
CH
)
INST
; Port data register address
; Port direction register address
; Serial selection register address
; Serial mode control register address
; Serial rate control register address
; Serial status and data register address
; Serial input data register address
; Serial output data register address
; Clock divider selection register address
; Interrupt level setting register address
; [DATA SEGMENT]
; Reception interrupt vector setting
; Transmission interrupt vector setting
; [CODE SEGMENT]
; The stack pointer (SP) and related components have to be
initialized.
; Disable interrupts.
; Set an interrupt level (level 1).
; Allow operation with the clock whose frequency is divided
by 2.5.
; Set non-parity, the number of stop bits 1, and operating
CHAPTER 13 UART
311