我写了个简单的UART 和PC的RS232通信的程序,现在问题是PC给MCU发数据接收是正常的,可是MCU就是不能给PC发数据,用串口调试精灵,看不到结果!请大家帮帮我,我搞了几天了,没有搞定!
#include "p30f4013.h" #define FCY 14745600 _FOSC(CSW_FSCM_OFF & XT_PLL8);//use a external crystal ,the instruction cycle =1/(FOSC*PLL/4) _FWDT(WDT_OFF); _FBORPOR(PBOR_OFF & MCLR_EN);//disable power off pretect,enable MCLR _FGS(CODE_PROT_OFF);//disable code pretect
void ini232(void); void __attribute__((__interrupt__)) _U1RXInterrupt(void); /*Declare 232 interrupt ISRs*/
unsigned char rxdata;
int main (void) { unsigned char i; ini232(); /* Call function to initialize the 232 Interrupts */ for(i=32;i!=0;i--); while(1) { U1TXREG=0x66; while(U1STAbits.TRMT==0); IFS0bits.U1TXIF=0; } }
void ini232(void) { TRISFbits.TRISF2 =1; TRISFbits.TRISF3 =0;
U1BRG =95; //9600 baud rate
IPC2bits.U1RXIP=7; IEC0bits.U1TXIE=0; IEC0bits.U1RXIE=1;
U1MODE =0x8020; U1STAbits.UTXEN =1; }
void __attribute__((__interrupt__)) _U1RXInterrupt(void) { IFS0bits.U1RXIF = 0; rxdata=(char)U1RXREG; }
|