00001 /* 00002 * $Id: uart.c,v 1 2005/03/10 17:30:00 BorisK Exp $ 00003 * 00004 * Copyright (C) 2004 ONTRACK s.r.o. 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00019 * 02111-1307, USA. 00020 * 00021 * [1] ARM-based Microcontroller LPC2119/2129/2194/2292/9994, "Preliminary User Manual", February 03, 2004 00022 * 00023 * Written by Boris Kralik <kralikbo@yahoo.com>, 2005 00024 * 00025 */ 00026 #include "uart.h" 00027 #include "./include/lpc2119.h" 00028 void 00029 UARTInitialize(void){ 00030 UART0_LCR = 0x83;/* 8 bit, 1 stop bit, no parity, enable DLAB */ 00031 UART0_IER = 0; 00032 PCB_PINSEL0 |= 0x5; 00033 PCB_PINSEL0 &= 0X5; 00034 UART0_IIR = 7; 00035 UART0_FCR = 1; 00036 UART0_DLL = 0x4E; 00037 UART0_DLM = 0; 00038 UART0_LCR = 0x03; 00039 #if 0 00040 UARTWriteStr("\n\ruart.c"); 00041 #else 00042 WD_Reset(); 00043 #endif 00044 } 00045 int UARTgetchar(int iType) { /* Read character from Serial Port */ 00046 if (iType == 1) //Wait 00047 while (!(UART0_LSR & 0x01)) 00048 #if 0 00049 printf("\n\rUARTgetchar(%d)",iType); 00050 #else 00051 WD_Reset(); 00052 #endif 00053 return (UART0_RBR); 00054 } 00055 00056 void UARTWriteChar(char ch){ 00057 while(!(UART0_LSR & 0x20)); 00058 UART0_THR = ch; 00059 } 00060 void UARTWriteStr(char *string){ 00061 int i=0; 00062 do{ 00063 UARTWriteChar(string[i++]); 00064 }while(string[i]!='\x0'); 00065 } 00066 unsigned char UARTReadChar(void){ 00067 while(!(UART0_LSR & 0x01)); 00068 #if 0 00069 printf("\n\r%c",UART0_RBR); 00070 #endif 00071 return UART0_RBR; 00072 } 00073
1.4.7