多谢指点,我看了你们的课件后,写了以下程序,
#include "uart.h"
//=============================================
#define BaudRate 115200
#define Fosc 14318180
#define VPB 1
#define MSEL 4
#define PSEL 2
#define cclk MSEL*Fosc/VPB
#define Uart0_value cclk/16/BaudRate
//=============================================
void uart0_isr(void)__irq
{
unsigned char U0IIR_value,test;
test = U0LSR;
U0IIR_value = U0IIR;
if(U0IIR_value&0x01)//为1时,没有中断挂起。
{
}
else
{
switch(U0IIR_value&0x07)
{
case 0x06: break;
case 0x04: //接收数据可用或FIFO到达触发点。
test = U0RBR;
U0THR = test;
break;
case 0x0C: break;//字符超时
case 0x02: break;//THER空
default: break;
}
}
}
void DefaultIRQ(void)__irq
{
}
void init_uart(void)
{
PINSEL0 = 0x01e00005; /* Enable RxD0 and TxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLL = Uart0_value; /* 115200Baud Rate */
U0LCR = 0x03; /* DLAB = 0 */
U0IER = 0x03; /* Enable UART0 intrrupt */
VICIntSelect = 0x00000000; /*Enable a Vic Channel as IRQ */
VICIntEnable = 1<<6; /* Set Default interrupt vector */
VICDefVectAddr = (unsigned long)DefaultIRQ; //非向量中断入口地址。
VICVectCntl0 = 0x26; //设置优先级0为第6中断源,并打开中断源6的中断允许。
VICVectAddr0 = (unsigned long)uart0_isr;/*把uart_isr函数的入口地址赋给优先为0的中断源的中断入口地址。*/
IODIR0 = 0x01e00000;
IOSET0 = 0x01e00000;
}
/*这是我写的串口测试程序,为什么PC只收到最开始的数据呢?到第二个数据就收不到了。我给他发了N个数据!*/
|