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

📄 serial1_driver.c

📁 lpc2148 programs from NXP
💻 C
字号:
/************************************************************/
/* 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 "gpio.h"
//#include "lcd.h"
//#include "common.h"
#include "serial1.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 char i,byte;
  byte = getCharS1();

  for(i=0;byte!=13;i++) 
  {
  	string[i] = byte;
    byte = getCharS1();
  }
  string[i] = '\0';	
 
}

/************************************************************/
void putHexS1(unsigned char dat)
{
 unsigned char msb=0x00,lsb=0x00;
msb=dat&0xf0;
 msb=msb>>4;
 if(msb<=0x09)
  msb=msb+0x30;
 else
   msb=msb+0x37;
  putCharS1(msb);
lsb=dat&0x0f;
  if(lsb<=0x09)
 lsb=lsb+0x30;
   else
  lsb=lsb+0x37;
   putCharS1(lsb);
} 
/************************************************************/ 	  
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
}
/*************************************************************/
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -