![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
host/Source/App/uart.c@23:12e6183f04d4, 2016-02-03 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Feb 03 10:44:42 2016 +0300
- Revision:
- 23:12e6183f04d4
[thyz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kovalev_D |
23:12e6183f04d4 | 1 | /**************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 2 | * $Id:: uart.c 5751 2010-11-30 23:56:11Z usb00423 $ |
Kovalev_D |
23:12e6183f04d4 | 3 | * Project: NXP LPC17xx UART example |
Kovalev_D |
23:12e6183f04d4 | 4 | * |
Kovalev_D |
23:12e6183f04d4 | 5 | * Description: |
Kovalev_D |
23:12e6183f04d4 | 6 | * This file contains UART code example which include UART initialization, |
Kovalev_D |
23:12e6183f04d4 | 7 | * UART interrupt handler, and APIs for UART access. |
Kovalev_D |
23:12e6183f04d4 | 8 | * |
Kovalev_D |
23:12e6183f04d4 | 9 | ****************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 10 | #include "lpc17xx.h" |
Kovalev_D |
23:12e6183f04d4 | 11 | #include "uart.h" |
Kovalev_D |
23:12e6183f04d4 | 12 | |
Kovalev_D |
23:12e6183f04d4 | 13 | #define FOSC 12000000 /* Õñµ´Æ÷ƵÂÊ */ |
Kovalev_D |
23:12e6183f04d4 | 14 | |
Kovalev_D |
23:12e6183f04d4 | 15 | #define FCCLK (FOSC * 8) /* Ö÷ʱÖÓƵÂÊ<=100Mhz */ |
Kovalev_D |
23:12e6183f04d4 | 16 | /* FOSCµÄÕûÊý±¶ */ |
Kovalev_D |
23:12e6183f04d4 | 17 | #define FCCO (FCCLK * 3) /* PLLƵÂÊ(275Mhz~550Mhz) */ |
Kovalev_D |
23:12e6183f04d4 | 18 | /* ÓëFCCLKÏàͬ£¬»òÊÇÆäµÄżÊý±¶ */ |
Kovalev_D |
23:12e6183f04d4 | 19 | #define FPCLK (FCCLK / 4) /* ÍâÉèʱÖÓƵÂÊ,FCCLKµÄ1/2¡¢1/4*/ |
Kovalev_D |
23:12e6183f04d4 | 20 | /* »òÓëFCCLKÏàͬ */ |
Kovalev_D |
23:12e6183f04d4 | 21 | /***************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 22 | ** Function name: UARTInit |
Kovalev_D |
23:12e6183f04d4 | 23 | ** |
Kovalev_D |
23:12e6183f04d4 | 24 | ** Descriptions: Initialize UART port, setup pin select, |
Kovalev_D |
23:12e6183f04d4 | 25 | ** clock, parity, stop bits, FIFO, etc. |
Kovalev_D |
23:12e6183f04d4 | 26 | ** |
Kovalev_D |
23:12e6183f04d4 | 27 | ** parameters: portNum(0 or 1) and UART baudrate |
Kovalev_D |
23:12e6183f04d4 | 28 | ** Returned value: true or false, return false only if the |
Kovalev_D |
23:12e6183f04d4 | 29 | ** interrupt handler can't be installed to the |
Kovalev_D |
23:12e6183f04d4 | 30 | ** VIC table |
Kovalev_D |
23:12e6183f04d4 | 31 | ** |
Kovalev_D |
23:12e6183f04d4 | 32 | *****************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 33 | void UART2_Init (void) |
Kovalev_D |
23:12e6183f04d4 | 34 | { |
Kovalev_D |
23:12e6183f04d4 | 35 | uint16_t usFdiv; |
Kovalev_D |
23:12e6183f04d4 | 36 | /* UART2 */ |
Kovalev_D |
23:12e6183f04d4 | 37 | LPC_PINCON->PINSEL0 |= (1 << 20); /* Pin P0.10 used as TXD2 (Com2) */ |
Kovalev_D |
23:12e6183f04d4 | 38 | LPC_PINCON->PINSEL0 |= (1 << 22); /* Pin P0.11 used as RXD2 (Com2) */ |
Kovalev_D |
23:12e6183f04d4 | 39 | |
Kovalev_D |
23:12e6183f04d4 | 40 | LPC_SC->PCONP = LPC_SC->PCONP|(1<<24); /*´ò¿ªUART2µçÔ´¿ØÖÆλ */ |
Kovalev_D |
23:12e6183f04d4 | 41 | |
Kovalev_D |
23:12e6183f04d4 | 42 | LPC_UART2->LCR = 0x83; /* ÔÊÐíÉèÖò¨ÌØÂÊ */ |
Kovalev_D |
23:12e6183f04d4 | 43 | usFdiv = (FPCLK / 16) / 115200; /* ÉèÖò¨ÌØÂÊ */ |
Kovalev_D |
23:12e6183f04d4 | 44 | LPC_UART2->DLM = usFdiv / 256; |
Kovalev_D |
23:12e6183f04d4 | 45 | LPC_UART2->DLL = usFdiv % 256; |
Kovalev_D |
23:12e6183f04d4 | 46 | LPC_UART2->LCR = 0x03; /* Ëø¶¨²¨ÌØÂÊ */ |
Kovalev_D |
23:12e6183f04d4 | 47 | LPC_UART2->FCR = 0x06; |
Kovalev_D |
23:12e6183f04d4 | 48 | } |
Kovalev_D |
23:12e6183f04d4 | 49 | |
Kovalev_D |
23:12e6183f04d4 | 50 | /********************************************************************************************************* |
Kovalev_D |
23:12e6183f04d4 | 51 | ** Function name: UART2_SendByte |
Kovalev_D |
23:12e6183f04d4 | 52 | ** Descriptions: ´Ó´®¿Ú2·¢ËÍÊý¾Ý |
Kovalev_D |
23:12e6183f04d4 | 53 | ** input parameters: data: ·¢Ë͵ÄÊý¾Ý |
Kovalev_D |
23:12e6183f04d4 | 54 | ** output parameters: ÎÞ |
Kovalev_D |
23:12e6183f04d4 | 55 | ** Returned value: ÎÞ |
Kovalev_D |
23:12e6183f04d4 | 56 | *********************************************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 57 | int UART2_SendByte (int ucData) |
Kovalev_D |
23:12e6183f04d4 | 58 | { |
Kovalev_D |
23:12e6183f04d4 | 59 | while (!(LPC_UART2->LSR & 0x20)); |
Kovalev_D |
23:12e6183f04d4 | 60 | return (LPC_UART2->THR = ucData); |
Kovalev_D |
23:12e6183f04d4 | 61 | } |
Kovalev_D |
23:12e6183f04d4 | 62 | |
Kovalev_D |
23:12e6183f04d4 | 63 | /****************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 64 | ** End Of File |
Kovalev_D |
23:12e6183f04d4 | 65 | ******************************************************************************/ |