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

📄 serial.c

📁 ADS1.2 samples
💻 C
字号:
/*
** Copyright (C) ARM Limited, 2002. All rights reserved.
*/

/* serial.c */

/*
** This implements a simple (polled) RS232 serial driver for the 
** ARM Integrator Board.
**
** It outputs single characters on Serial Port A at 38400 Baud, 
** 8 bit, no parity, 1 stop bit.
**
** Initialize the port with init_serial_A() before calling sendchar().
**
** To monitor the characters output, use a null-modem cable to
** connect Serial Port A to an RS232 terminal or PC running a
** terminal emulator, e.g. HyperTerminal.
*/

/* 
** Define SCATTER_PERIP if the UART register locations are
** defined in a scatter file
*/

#include "uart.h"

#ifdef SCATTER_PERIP
extern struct uart uart0;

#define UART0_DR   uart0.dr
#define UART0_RSR  uart0.ecr 
#define UART0_ECR  uart0.ecr
#define UART0_LCRH uart0.lcrh
#define UART0_LCRM uart0.lcrm
#define UART0_LCRL uart0.lcrl
#define UART0_CR   uart0.cr
#define UART0_FR   uart0.fr
#define UART0_IIR  uart0.iir
#define UART0_ICR  uart0.iir

#else
#include "intgrt.h"
#endif

void init_serial_A(void)
{
  /* First set the correct baud rate and word length */
  
  UART0_LCRL = LCRL_Baud_38400;       // LCRL and LCRM writes _MUST_
                                      // be performed before the LCRH
  UART0_LCRM = LCRM_Baud_38400;       // write as LCRH generates the
                                      // write strobe to transfer the
  UART0_LCRH = LCRH_Word_Length_8;    // data. FIFO disabled.  

  /* Now enable the serial port */
                                      
  UART0_CR   = CR_UART_Enable;        // Enable UART0 with no interrupts
}


void sendchar(unsigned char *ch)
{
  while (UART0_FR & FR_TX_Fifo_Full)
    ;
  if (*ch == '\n')                    // Replace line feed with '\r'
    *ch = '\r';
  UART0_DR = *ch;                     // Transmit next character
}

char receive_char(void)
{
  volatile char status;
  volatile char ch = '0';

  while (UART0_FR & FR_RX_Fifo_Empty) // wait until we receive a byte
    ;
  ch = UART0_DR;         // receive character
  status = UART0_RSR;    // read the status register
  
  /* Could check status receive status here */
  return ch;
}

⌨️ 快捷键说明

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