UART串口发送数据,这个串口程序编译成功,但用示波器测TX输出,没有输出,请帮帮忙看看。
#include <stdio.h>
#include <stdlib.h>
#include <p33FJ128MC706.h>
#include <time.h>
#include <math.h>
#include <string.h>
#define uint8 unsigned char
#define uint16 unsigned int
_FOSCSEL( FNOSC_FRC & IESO_OFF );
_FOSC( POSCMD_HS & OSCIOFNC_OFF & FCKSM_CSECMD );
_FWDT( WDTPOST_PS32768 & WDTPRE_PR128 & WINDIS_OFF & FWDTEN_OFF );
_FPOR( FPWRT_PWR128 & LPOL_OFF & HPOL_OFF );
#define FCY 40000000
#define BAUDRATE 9600
#define BRGVAL ((FCY/BAUDRATE)/16)-1
void InitClock();
void InitUART1();
unsigned int i;
/*************************************************************************************************************************************************************/
int main(void)
{
InitClock();
InitUART1();
for(i=0;i<4160;i++)
{
Nop();
}
U1TXREG=0x05;
while(1)
{
}
}
void InitClock()
{
PLLFBD = 38; // M = 40
CLKDIVbits.PLLPOST =0; // N1 = 2
CLKDIVbits.PLLPRE=0; // N2 = 2
OSCTUN =0;
RCONbits.SWDTEN=0;
// Clock switch to incorporate PLL
__builtin_write_OSCCONH(0x01); // Initiate Clock Switch to
__builtin_write_OSCCONL(0x01); // Start clock switching
while(OSCCONbits.COSC!=0b001); // Wait for Clock switch to occur
while(OSCCONbits.LOCK!=1){};
}
void InitUART1()
{
U1MODEbits.STSEL=0; //1 stop bit
U1MODEbits.PDSEL=0; //no parity,8 data bits
U1MODEbits.ABAUD=0; //auto-BAUD disable
U1MODEbits.BRGH=0; //low speed mode
/*U1MODEbits.UEN=0; */
U1BRG=BRGVAL; //BAUD rate setting for 9600
U1STAbits.UTXISEL0=0; //interrupt after one TX character is transmitted
U1STAbits.UTXISEL1=0;
IEC0bits.U1TXIE=1; //enable UART Tx interrupt
U1MODEbits.UARTEN=1; //enable UART
U1STAbits.UTXEN=1; //enable UART Tx
}
/*************************************************************************************************************************************************************/
void __attribute__((interrupt, no_auto_psv))__U1TXInterrupt(void)
{
IFS0bits.U1TXIF=0; //clear Tx interrupt flag
U1TXREG=0x05; //transmit one data
} |