⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.c

📁 阿根廷教授编写的嵌入式internet的实验教程的高质量代码
💻 C
字号:
/******************************************************************************************
   Uart.c (v1.0)
-------------------------------------------------------------------------------------
This code is from the book:
"Embedded Internet: TCP/IP Basics, Implementation and Applications" by Sergio Scaglia
[Pearson Education, 2006 - ISBN: 0-32-130638-4]

This code is copyright (c) 2006 by Sergio Scaglia, and it may only be used for educational
purposes.  For commercial use, please contact me at sscaglia@intramarket.com.ar
For more information and updates, please visit www.embeddedinternet.org
******************************************************************************************/

#include "uart.h"
#include "sysClock.h"
#include <iolpc2129.h>

#define CR     0x0D


void UART_init(unsigned int baud) {
  unsigned int divisor = (pClkFreq()/4) / (16 * baud);

  U0LCR = 0x83; /* 8 bit, 1 stop bit, no parity, enable DLAB */
  U0DLL = divisor & 0xFF;
  U0DLM = (divisor >> 8) & 0xFF;
  U0LCR &= ~0x80; /* Disable DLAB */
  PINSEL0 = (PINSEL0 & ~0xF) | 0x5;
  U0FCR = 1;
}


int putchar(int ch) {

  if (ch == '\n')  {
    while (!(U0LSR & 0x20));
    U0THR = CR;
  }
  while (!(U0LSR & 0x20));
  return (U0THR = ch);
 }


int getchar (void) {
 				
  if (U0LSR & 0x01)
    return (U0RBR);
  else
    return (-1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -