本帖最后由 hotpower 于 2012-9-13 22:34 编辑
M051上有两个串口,接线没问题、然后串口配置如下:
#include "m051series.h"
#include "DrvUART.h"
#include "DrvGPIO.h"
#include "DrvSYS.h"
#include <stdio.h>
STR_UART_T sParam0;
STR_UART_T sParam1;
void uart0()
{
DrvGPIO_InitFunction(E_FUNC_UART0);
sParam0.u32BaudRate=9600;
sParam0.u8cDataBits=DRVUART_DATABITS_8;
sParam0.u8cStopBits=DRVUART_STOPBITS_1;
sParam0.u8cParity=DRVUART_PARITY_NONE;
sParam0.u8cRxTriggerLevel=DRVUART_FIFO_1BYTES;
DrvUART_Open(UART_PORT0,&sParam0);
}
void uart1()
{
DrvGPIO_InitFunction(E_FUNC_UART1);
sParam1.u32BaudRate=9600;
sParam1.u8cDataBits=DRVUART_DATABITS_8;
sParam1.u8cStopBits=DRVUART_STOPBITS_1;
sParam1.u8cParity=DRVUART_PARITY_NONE;
sParam1.u8cRxTriggerLevel=DRVUART_FIFO_1BYTES;
DrvUART_Open(UART_PORT1,&sParam1);
}
主函数是:
uint8_t buff[2]="hi";
int main()
{
Sys_Config();
Gpio_Config();
uart1();
while(1)
{
DrvGPIO_SetBit(E_PORT2,1);
delay();
DrvUART_Write(UART_PORT1,buff,2);
delay();
DrvGPIO_ClrBit(E_PORT2,1);
delay();
}
}
但是,我将串口号改为串口0就可以看到串口工具上不断显示hi,而在串口1就没看到任何现象。不知道是什么原因,求各位大虾解答呀。 |