serial0_driver.c

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

C
125
字号
/************************************************************/
/* PROJECT NAME: Serial 0 Driver                            */
/* Project:      LPC2129 Training course                    */
/* Engineer:     Y.Stalin        stalin@nstlindia.com       */
/* Filename:     SERIAL0_Driver.c                           */
/* Language:     C                      	                */
/* Compiler:     Keil ARM	GCC			                    */
/* Assembler:    				                            */
/*                                                          */
/************************************************************/
/* COPYRIGHT: NSTL 		2008		  						*/
/* LICENSE:   PROPRIETORY									*/
/************************************************************/
/* Function:                                                */
/*                                                          */
/* Example 									           		*/
/*															*/
/* Demonstrates Use of the LPC2129 GPIO						*/
/*															*/	
/* Oscillator frequency 12.000 Mhz							*/
/* Target board NSTL NST2100								*/
/************************************************************/


#include <LPC214X.H>
#include "serial0.h"

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

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

void InitSerial0 (unsigned long baudrate)  
{
  int val;

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

  VPBDIV  |= 0x000000002;

  val = Fpclk/(16 * baudrate);  

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

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

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

void putCharS0 (unsigned char ch)
{
  while (!(U0LSR & 0x20));
  U0THR = ch;
}
/************************************************************/

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

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

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

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

unsigned char getCharS0 (void)
{
  while (!(U0LSR & 0x01));
 
  return (U0RBR);
}	 

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

/************************************************************/ 
	  
void lineFeed0(void)
{
  putCharS0(0x0A);
  putCharS0(0x0D);
}

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

//************************************************************/ 
void InitSerial0Int(unsigned isrPtr)
{
  U0IER = 0x01;
  VICVectCntl0 	= 0x00000026;  						//select a priority slot for a given interrupt  
  VICVectAddr0 	= (unsigned long)isrPtr;		//pass the address of the IRQ into the VIC slot 
  VICIntEnable 	|= 0x00000040;						//enable interrupt2
}
/*************************************************************/
void setClock(void)
{
  unsigned int M,P = 2;

  M = F_CLK/F_XTAL;  
   
  PLL0CFG =(P << 4)|(M-1);

  PLL0FEED = 0xAA;
  PLL0FEED = 0x55;

  if(F_PCLK == (F_CLK / 4))
    VPBDIV = 0x00;
  else if(F_PCLK == F_CLK)
	VPBDIV = 0x01;
  else if(F_PCLK == (F_CLK / 2))
	VPBDIV = 0x02;
  else 
    VPBDIV = 0x01; 
}

⌨️ 快捷键说明

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