KEIL版本,UVSION 4.03A,
程序如下,
#define uart2_c
#include "lpc23xx.h"
#include "uart2.h"
#include "ctrl.h"
#include "delay.h"
extern uint32 Fpclk;
void UART2_Init(uint32 baudrate)
{
uint32 Fdiv=0;
PCONP|=1<<24;
PINSEL0&=~(1<<23); //rxd2
PINSEL0|=1<<22;
PINSEL0&=~(1<<21);
PINSEL0|=(1<<20); //txd2
U2LCR=0x83;
Fdiv=(Fpclk/baudrate)/16 ;
U2DLM=Fdiv / 256;
U2DLL=Fdiv % 256;
U2LCR=0x03;
U2FCR=0x07;
U2IER=1; //打开接收中断
U2FCR=0x01; //接收FIFO为1个字节深度就产生中断
VICIntSelect&=~(1<<UART2_INT);
VICVectPri28 = 20;
VICVectAddr28 = (unsigned long)IRQ_UART2;
VICIntEnable |= 1<<UART2_INT;
}
void UART2_Send_Byte(uint8 dat)
{
U2THR = dat;
while ((U2LSR & 0x40) == 0); // 等待数据发送完毕
}
void UART2_Send_Buf(uint8 *dat,uint16 len)
{
uint16 i=0;
for(i=0;i<len;i++)
{
UART2_Send_Byte(*(dat+i));
}
}
__irq void IRQ_UART2(void)
{
uint32 IIR = 0;
uint8 temp=0;
IIR=U2IIR;
switch (IIR & 0x0e)
{
case 0x04: //接收中断
temp=U2RBR;
break;
default:
break;
}
VICVectAddr = 0x00;
}
#undef uart2_c
我测试过,把该程序里面的 UART2寄存器换成UART0和 UART1的,是可以的 ,,但UART2和UART3就是不行,妈妈的,不知道是怎么回事。。。。。。。。 |