uart1.c

来自「lpc2148 programs from NXP」· C语言 代码 · 共 100 行

C
100
字号
#include <LPC214X.H>
#include "uart1.h"

/************************************************************/

/************************************************************/

void InitSerial1 (unsigned long baudrate)  
{
  int val;

  PINSEL0 |= 0x00050000;	//Enable pin 0.0    as PWM1 

  //VPBDIV  |= 0x000000001;

  val = Fpclk/(16 * baudrate);  

  U1LCR = 0x83;                          /* 8 bits, no Parity, 1 Stop bit     */
	
  U1DLM = (val & 0xFF00) >> 8;
  U1DLL = (val & 0xFF);
	
  U1LCR = 0x03;                           /* DLAB = 0                         */
}

/************************************************************/

/************************************************************/

void putCharS1 (unsigned char ch)
{
  while (!(U1LSR & 0x20));
  U1THR = ch;
}
/************************************************************/

/************************************************************/

void putStrS1 (const unsigned char *string)
{
	 unsigned char ch;

  while ((ch = *string))
  {
 	putCharS1(ch);
	string++;		
  }
}	   
/************************************************************/

/************************************************************/

unsigned char getCharS1 (void)
{
  while (!(U1LSR & 0x01));
 
  return (U1RBR);
}	 

/************************************************************/

/************************************************************/ 
void getStrS1(unsigned char *string)
{ 
  unsigned int i;
  unsigned char byte;
  byte = getCharS1();
  putCharS1(byte);
  for(i=0;byte!=13;i++) 
  {
  	string[i] = byte;
    byte = getCharS1();
	putCharS1(byte);
  }
  string[i] = '\0';	
 
}

/************************************************************/

/************************************************************/ 	  
void lineFeed1(void)
{
  putCharS1(0x0A);
  putCharS1(0x0D);
}

/************************************************************/

/************************************************************/ 
void InitSerial1Int(unsigned isrPtr)
{
  U1IER = 0x01;
  VICVectCntl0 	= 0x00000027;  						//select a priority slot for a given interrupt  
  VICVectAddr0 	= (unsigned long)isrPtr;		//pass the address of the IRQ into the VIC slot 
  VICIntEnable 	|= 0x00000080;						//enable interrupt2
}
/*************************************************************/

⌨️ 快捷键说明

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