Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LGstaandart by
Diff: host/Source/App/uart.c
- Revision:
- 23:12e6183f04d4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/host/Source/App/uart.c Wed Feb 03 10:44:42 2016 +0300
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * $Id:: uart.c 5751 2010-11-30 23:56:11Z usb00423 $
+ * Project: NXP LPC17xx UART example
+ *
+ * Description:
+ * This file contains UART code example which include UART initialization,
+ * UART interrupt handler, and APIs for UART access.
+ *
+****************************************************************************/
+#include "lpc17xx.h"
+#include "uart.h"
+
+#define FOSC 12000000 /* Õñµ´Æ÷ƵÂÊ */
+
+#define FCCLK (FOSC * 8) /* Ö÷ʱÖÓÆµÂÊ<=100Mhz */
+ /* FOSCµÄÕûÊý±¶ */
+#define FCCO (FCCLK * 3) /* PLLƵÂÊ(275Mhz~550Mhz) */
+ /* ÓëFCCLKÏàͬ£¬»òÊÇÆäµÄżÊý±¶ */
+#define FPCLK (FCCLK / 4) /* ÍâÉèʱÖÓÆµÂÊ,FCCLKµÄ1/2¡¢1/4*/
+ /* »òÓëFCCLKÏàͬ */
+/*****************************************************************************
+** Function name: UARTInit
+**
+** Descriptions: Initialize UART port, setup pin select,
+** clock, parity, stop bits, FIFO, etc.
+**
+** parameters: portNum(0 or 1) and UART baudrate
+** Returned value: true or false, return false only if the
+** interrupt handler can't be installed to the
+** VIC table
+**
+*****************************************************************************/
+void UART2_Init (void)
+{
+ uint16_t usFdiv;
+ /* UART2 */
+ LPC_PINCON->PINSEL0 |= (1 << 20); /* Pin P0.10 used as TXD2 (Com2) */
+ LPC_PINCON->PINSEL0 |= (1 << 22); /* Pin P0.11 used as RXD2 (Com2) */
+
+ LPC_SC->PCONP = LPC_SC->PCONP|(1<<24); /*´ò¿ªUART2µçÔ´¿ØÖÆÎ» */
+
+ LPC_UART2->LCR = 0x83; /* ÔÊÐíÉèÖò¨ÌØÂÊ */
+ usFdiv = (FPCLK / 16) / 115200; /* ÉèÖò¨ÌØÂÊ */
+ LPC_UART2->DLM = usFdiv / 256;
+ LPC_UART2->DLL = usFdiv % 256;
+ LPC_UART2->LCR = 0x03; /* Ëø¶¨²¨ÌØÂÊ */
+ LPC_UART2->FCR = 0x06;
+}
+
+/*********************************************************************************************************
+** Function name: UART2_SendByte
+** Descriptions: ´Ó´®¿Ú2·¢ËÍÊý¾Ý
+** input parameters: data: ·¢Ë͵ÄÊý¾Ý
+** output parameters: ÎÞ
+** Returned value: ÎÞ
+*********************************************************************************************************/
+int UART2_SendByte (int ucData)
+{
+ while (!(LPC_UART2->LSR & 0x20));
+ return (LPC_UART2->THR = ucData);
+}
+
+/******************************************************************************
+** End Of File
+******************************************************************************/
