int8 UART1_Init(uint32 baud,uint8 datab,uint8 stopb,uint8 parity)
{
uint32 tmp;
PINSEL0 = (PINSEL0 & 0xfff0ffff) | 0x50000; // (先清零,再赋值) P0.8 、.P0.9
PINSEL2 = (PINSEL2 & (~0x08)); //P1.24 为 GPIO
IO1DIR |= (1<<24); //P1.24为输出口
if ((baud==0) || (baud>115200)) return 0;
if ((datab<5) || (datab>8)) return 0;
if ((stopb==0)|| (stopb>2)) return 0;
if (parity>4) return 0;
U1LCR = 0x80; // Enable access to Divisor Latches
tmp = (Fpclk >> 4) / baud;
U1DLM = tmp >> 8;
U1DLL = tmp & 0xFF;
tmp = datab - 5; // 设置字长
if (stopb==2) tmp |= 0x04; // 设置停止位
if (parity!=0) // 设置奇偶校验位
{
parity--;
tmp |= 0x08;
}
tmp |= parity << 4;
U1LCR = tmp;
U1FCR = 0x81; //使能FIFO,并设置触发点为8字节
U1IER = 0x01; //允许RBR中断,即接收中断
rcv_new1 = 0;
return 1;
}
int main(void)
{
/* 设置中断允许 */
VICIntSelect = 0x00000000; // 设置所有通道为IRQ中断
VICVectAddr6 = (uint32)Uart1_Handler;
VICVectCntl6 = (0x20 | 0x07);
VICIntEnable |= (1 << 0x07); // 使能UART1
VICVectAddr4 = (uint32)Uart0_Handler;
VICVectCntl4 = (0x20 | 0x06);
VICIntEnable |= (1 << 0x06); // 使能UART0
UART0_Init(9600, 8, 1, 0);
UART1_Init(9600, 8, 1, 0);
while(1) // 等待中断
{
if(1==rcv_new0)
{
UART0_SendStr("\r\n123456789!!!\r\n"); // 将接收到的数据发送回主机
rcv_new0 = 0;
}
if(1==rcv_new1)
{
UART1_SendStr("\r\n567891234!!!\r\n"); // 将接收到的数据发送回主机
rcv_new1 = 0;
}
}
return(0);
}
------------------------------------------------------
'UART1_Init(9600,8,1,0);' 这句话加上的话 ,UART0就收不到 数据了. 没有这句,一切正常.
能看看上面的代码吗?
------解决方案--------------------
中断表里,对应的中断开了没?