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

📄 uart.c

📁 矿工定位系统单端
💻 C
字号:
//uart.c - code recommendation for C header file
/***********************************************************************
MODULE:    UART
VERSION:   1.04
CONTAINS:  Routines for controlling the UART peripheral on the Philips
           P89LPC932
COPYRIGHT: Embedded Systems Academy, Inc. - www.esacademy.com
LICENSE:   May be freely used in commercial and non-commercial code
           without royalties provided this copyright notice remains
           in this file and unaltered
WARNING:   IF THIS FILE IS REGENERATED BY CODE ARCHITECT ANY CHANGES
           MADE WILL BE LOST. WHERE POSSIBLE USE ONLY CODE ARCHITECT
           TO CHANGE THE CONTENTS OF THIS FILE
GENERATED: On "Feb 24 2004" at "11:46:47" by Code Architect 2.03
***********************************************************************/

// SFR description needs to be included
#include<REG922.h>
#include "uart.h"

// flag that indicates if the UART is busy transmitting or not
static bit mtxbusy;

/***********************************************************************
DESC:    Initializes UART for mode 1
         Baudrate: 19200
RETURNS: Nothing
CAUTION: If interrupts are being used then EA must be set to 1
         after calling this function
************************************************************************/
void user_uart_init(void)
{
  // configure UART
  // clear SMOD0
  PCON &= ~0x40;
  SCON = 0x50;
  // set or clear SMOD1
  PCON &= 0x7f;
  PCON |= (0 << 8);
  SSTAT = 0x00;

  // configure baud rate generator
  BRGCON = 0x00;
  BRGR0 = 0x70;  //19200
  BRGR1 = 0x01;

  //BRGR0 = 0xF0;   //9600
 // BRGR1 = 0x02;

  BRGCON = 0x03;

  // TxD = push-pull, RxD = input
  P1M1 &= ~0x01;
  P1M2 |= 0x01;
  P1M1 |= 0x02;
  P1M2 &= ~0x02;

  // initially not busy
  mtxbusy = 0;

  // set isr priority to 0
  IP0 &= 0xEF;
  IP0H &= 0xEF;
  // enable uart interrupt
  AUXR1 &= 0xbf;
  ES = 1;

} // user_uart_init


/***********************************************************************
DESC:    Transmits a 8-bit value via the UART in the current mode
         May result in a transmit interrupt if enabled.
RETURNS: Nothing
CAUTION: user_uart_init must be called first
************************************************************************/
void uart_transmit(unsigned char value )  // data to transmit
{
  while(mtxbusy);
  mtxbusy = 1;
  SBUF = value;
} // uart_transmit

/***********************************************************************
DESC:    Gets a received 8-bit value from the UART
RETURNS: Received data
CAUTION: user_uart_init must be called first
************************************************************************/
unsigned char uart_get (void)
{
  return SBUF;
} // uart_get

⌨️ 快捷键说明

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