新會員
Joined
: 2005/1/3 17:11 最後登入時間
: 2009/7/7 16:24
Group:
註冊會員
Level : 1 HP : 0 / 18 MP : 2 / 1061 EXP : 73
|
我測試 9600 ok 可是115200不行,請問有什麼要注意的嗎? // JTAG/Code Protect/Write Protect/Clip-on Emulation mode // Watchdog Timer/ICD pins select _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) // Disable CLK switch and CLK monitor, OSCO or Fosc/2, HS oscillator, // Primary oscillator _CONFIG2(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI)
UARTInit() { TRISFbits.TRISF3 = 0;
// This is an EXAMPLE, so brutal typing goes into explaining all bit sets //******************************************************************************** // STEP 1: configure U1MODE // No Flow Control Mode, No Loop-Back // No Auto-Baud, No Rx-Inversion // Low BaudRate, // 8-bit with no parity // 1 Stop-bit // bit 14, bit 10 no use //********************************************************************************/ U1MODEbits.UARTEN = 0; // Bit15 TX, RX DISABLED, ENABLE at end of func //= 0; // Bit14 no use U1MODEbits.USIDL = 0; // Bit13 Continue in Idle U1MODEbits.IREN = 0; // Bit12 No IR translation
U1MODEbits.RTSMD = 0; // Bit11 Simplex Mode //= 0; // Bit10 no use U1MODEbits.UEN = 0; // Bits8,9 TX,RX enabled, CTS,RTS not
U1MODEbits.WAKE = 0; // Bit7 No Wake up (since we don't sleep here) U1MODEbits.LPBACK = 0; // Bit6 No Loop Back U1MODEbits.ABAUD = 0; // Bit5 No Autobaud (would require sending '55') U1MODEbits.RXINV = 0; // Bit4 IdleState = 1
U1MODEbits.BRGH = 0; // Bit3 16 clocks per bit period U1MODEbits.PDSEL = 0; // Bits1,2 8bit, No Parity U1MODEbits.STSEL = 0; // Bit0 One Stop Bit //******************************************************************************** // STEP 2: // Load the count to get 300 baudrate // BRG = Fcy/(16*BaudRate)-1 where Fcy = Fosc/2 = 4MHz //********************************************************************************/ U1BRG = 0x01; //0x19;
//******************************************************************************** // STEP 3: // Tx Interrupt to interrupt when at least one location is free in Tx buffer // No Tx Inversion, Disable Sync Break // Enable Transmit, Disable Address Detect // Interrupt on every receive. // bit 12 no use //********************************************************************************/ U1STAbits.UTXISEL1 = 0; //Bit15 Int when Char is transferred (1/2 config!) U1STAbits.UTXINV = 0; //Bit14 N/A, IRDA config U1STAbits.UTXISEL0 = 0; //Bit13 Other half of Bit15 //= 0; //bit 12 no use
U1STAbits.UTXBRK = 0; //Bit11 Disabled U1STAbits.UTXEN = 0; //Bit10 TX pins controlled by UART1 U1STAbits.UTXBF = 0; //Bit9 *Read Only Bit* U1STAbits.TRMT = 0; //Bit8 *Read Only bit*
U1STAbits.URXISEL = 0; //Bits6,7 Int. on character recieved U1STAbits.ADDEN = 0; //Bit5 Address Detect Disabled U1STAbits.RIDLE = 0; //Bit4 *Read Only Bit*
U1STAbits.PERR = 0; //Bit3 *Read Only Bit* U1STAbits.FERR = 0; //Bit2 *Read Only Bit* U1STAbits.OERR = 0; //Bit1 *Read Only Bit* U1STAbits.URXDA = 0; //Bit0 *Read Only Bit*
IFS0bits.U1TXIF = 0; // Clear the Transmit Interrupt Flag IEC0bits.U1TXIE = 0; // Enable Transmit Interrupts IFS0bits.U1RXIF = 0; // Clear the Recieve Interrupt Flag IEC0bits.U1RXIE = 1; // Enable Recieve Interrupts
U1MODEbits.UARTEN = 1; // And turn the peripheral on U1STAbits.UTXEN = 1; }
發表於: 2009/7/7 16:28
|