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

📄 sendstr.c

📁 lpc2210串口发送程序
💻 C
字号:

#include  "config.h"


void  DelayNS(uint32  dly)
{  uint32  i;

   for(; dly>0; dly--) 
      for(i=0; i<5000; i++);
}


#define  UART_BPS	115200			/* 定义通讯波特率 */
/****************************************************************************
* 名称:UART0_Ini()
* 功能:初始化串口0。设置为8位数据位,1位停止位,无奇偶校验,波特率为115200
* 入口参数:无
* 出口参数:无
****************************************************************************/
void  UART0_Ini(void)
{  uint16 Fdiv;

   U0LCR = 0x83;		            // DLAB = 1,可设置波特率
   Fdiv = (Fpclk / 16) / UART_BPS;  // 设置波特率
   U0DLM = Fdiv / 256;							
   U0DLL = Fdiv % 256;						
   U0LCR = 0x03;
}
				
void  UART0_SendByte(uint8 data)
{  U0THR = data;				    // 发送数据

   while( (U0LSR&0x40)==0 );	    // 等待数据发送完毕
}

void  UART0_SendStr(uint8 const *str)
{  while(1)
   {  if( *str == '\0' ) break;
      UART0_SendByte(*str++);	    // 发送数据
   }
}


uint8 const  SEND_STRING[] = "Hello World!\r\n";

void __irq IRQ_UART(void)
{
  uint8 temp;
  if((U0IIR&0X0F)==0X04){
    temp=U0RBR;
    temp+='a';
    UART0_SendByte(temp);
    }
}
int  main(void)
{  PINSEL0 = 0x00000005;		    // 设置I/O连接到UART0
   PINSEL1=0X00;
   UART0_Ini();

   U0FCR=0X81;
   U0IER=0X01;
   
   VICIntSelect=0x0000;
   VICVectCntl0=0x26;
   VICVectAddr0=(int)IRQ_UART;
   VICIntEnable=0x40;
      
   while(1)	
   {  UART0_SendStr(SEND_STRING);
      DelayNS(10);
   }
   return(0);
}

⌨️ 快捷键说明

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