www.pudn.com > FlashFS.rar > Serial.c, change:2008-06-23,size:2283b


/*---------------------------------------------------------------------------- 
 *      R T L   F l a s h   F i l e   S y s t e m   E x a m p l e 
 *---------------------------------------------------------------------------- 
 *      Name:    SERIAL.C 
 *      Purpose: Serial Input Output 
 *      Rev.:    V3.22 
 *---------------------------------------------------------------------------- 
 *      This code is part of the RealView Run-Time Library. 
 *      Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved. 
 *---------------------------------------------------------------------------*/ 
 
#include <LPC213x.H>                    /* LPC21xx definitions               */ 
 
#define CR     0x0D 
 
/*---------------------------------------------------------------------------- 
 *       init_serial:  Initialize Serial Interface 
 *---------------------------------------------------------------------------*/ 
void init_serial (void) { 
   PINSEL0 = 0x00050000;              /* Enable RxD1 and TxD1                */ 
   U1LCR = 0x83;                      /* 8 bits, no Parity, 1 Stop bit       */ 
   U1DLL = 0x04;                      /* 234 kBaud @ 15MHz VPB Clock         */ 
// U1DLL = 97;                        /* 9600 Baud Rate @ 15MHz VPB Clock    */ 
   U1LCR = 0x03;                      /* DLAB = 0                            */ 
} 
 
/*---------------------------------------------------------------------------- 
 *       sendchar:  Write a character to Serial Port 
 *---------------------------------------------------------------------------*/ 
int sendchar (int ch) { 
   if (ch == '\n') { 
      while (!(U1LSR & 0x20)); 
      U1THR = CR;                        /* output CR                        */ 
   } 
   while (!(U1LSR & 0x20)); 
   return (U1THR = ch); 
} 
 
/*---------------------------------------------------------------------------- 
 *       getkey:  Read a character from Serial Port 
 *---------------------------------------------------------------------------*/ 
int getkey (void) { 
   while (!(U1LSR & 0x01)); 
   return (U1RBR); 
} 
 
/*---------------------------------------------------------------------------- 
 * end of file 
 *---------------------------------------------------------------------------*/