📄 usart.c
字号:
/*************************************************************************
*
* Used with ICCARM and AARM.
*
* (c) Copyright IAR Systems 2007
*
* File name : usart.c
* Description : Main file
*
* History :
* 1. Date : August 2, 2007
* Author : Stanimir Bonev
* Description : Create
*
* This example project shows how to use the IAR Embedded Workbench for ARM
* to develop code for the Samsung-S3F4A0K evaluation board. It shows
* basic use of USAR0 in asynchronous mode.
* The example return asterisk and echo of the received character
* UART setting : 115200, 8 bit, no parity, 1 stop bit
*
* Jumpers:
* J43 5-6 - filled
* J42 5-6 - filled
* All other jumpers are in default position regarding board's manual
*
* $Revision: 18083 $
**************************************************************************/
#include <samsung\ios3f4a0k.h>
#include "arm_comm.h"
#include "board.h"
/*************************************************************************
* Function Name: main
* Parameters: none
* Return: none
*
* Description: Main
*
*************************************************************************/
void main (void)
{
// Enable PIO0 blocks for USART0 I/O configuration
PIO0_ECR = 1;
// Disable PIO function for USART0 signals - RXD and TXD (P0.19, P0.20)
PIO0_PDR = (1UL<<19) | (1UL << 20);
// Disable PIO0 blocks
PIO0_DCR = 1;
// Set USART0 RX and TX functions
IOCONF_MR2_bit.PIO0_19_F3EN = 1;
IOCONF_MR2_bit.PIO0_20_F3EN = 1;
// Enable USART0 blocks
US0_ECR = 1 << 1;
// USART Software Reset
US0_CR = 1;
// Configure USART Mode
US0_MR_bit.LIN = 0; // Disable LIN protocol on USART
US0_MR_bit.CLKS = 0; // CLKS Clock = PCLK
US0_MR_bit.CHRL = 3; // 8 bits
US0_MR_bit.SYNC = 0; // USART operates in Asynchronous Mode
US0_MR_bit.PAR = 4; // No parity
US0_MR_bit.NBSTOP = 0; // 1 stop bit
US0_MR_bit.CHMODE = 0; // Normal Mode
US0_MR_bit.SMCARDPT = 0; // Disable smart card protocol on USART
US0_MR_bit.MODE9 = 0; // The CHRL field defines the character length
US0_MR_bit.CLKO = 0; // The USART does not drive the SCK pin
// Set Baudrate
// Baud = PCLK/(16*US0_BRGR)
US0_BRGR = 11; // Baud 113636 Error 1.36%
// Usart Rx and Tx enable
US0_CR = (1<<4) | (1<<6);
while(1)
{
// wait until character receiving
if(US0_SR_bit.RXRDY)
{
// Get received character
Int8U Data = US0_RHR;
while(!US0_SR_bit.TXRDY);
// Send asterisk
US0_THR = '*';
// wait until hold buffer is empty
while(!US0_SR_bit.TXRDY);
// send received character
US0_THR = Data;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -