对不起的。我用PIC18S做了几百次,只是不知道该如何思考BRG号。就像我的钟不是我想的那样。设置MPLAB中的配置位是可以确定的。谢谢。ABBPIC正在做9600个BPS 0x0200=512。19.66兆赫晶体。计算不起作用。公式说我需要127(512/4)?PC 1100MS650MS850MS -------------------------------920MS220MSPIC1MS540MS 740MS840MS --------------------------------------------------------950MS220MSiNT主(空隙)} {INTi;i=0;初始化();(i,lt;10000)++i;i=0;波形:“A”当(1){/*加载发送缓冲器并发送相同的空字符时,*//*PutSuth2((未签名的INT*)TxDATA);*//PUSUTART2();U* TXRGG=“A”;/*等待传输完成* /(BUYYART2());而(i(lt;10000)i i++;i=0;}静态空格初始化板(空隙){*”(如果是定义的)PIC33 FXYA)/定义(μ-PIC24HAXY)//160MHz VCO输出(8MHz XT振荡器)CLKDIV= 0x000;//FRC:除以2,PLLPOST:除以2,PLLPRE:除以2πNeNF// 16位C30和32位C32//FoSSEL(FNSCOSPLIPLL)/PLL启用//OFSFC(O)SCIOFCNCYOFF和/XT OSC//OFFDT(FWDTENYOFF)/禁用的看门狗定时器/JTAG应该被禁用,//dSPIC33 F处理器定义GETSealCyCord()(19662000 UL)/HZ,定义GeEngestCortCork()(GETSealCyCord())2定义GePuturalCorCord()GETEn指令CyCord()/Explorer 16 + PIC24FHJ256GP610/DSPIC3FJ256GP710 PIM +以太网PICTHOLD PL//Explorer 16 + PIC32 MX460F512L/PIC32 MX360F512L PIM+以太网PICTHOLL,定义了CNVSTTYTIS(TrISCITS.TrISC1)//γ定义CNVSTYOI(LATCITS.LATC1)定义RSTY-TIIS(TrISCITS.TrISC2)//γ定义RSTYO IO(LATCITS.LATC2)定义BSY1LT J128GA010/PIC247.定义BSy2O-TrI(TrasgButs.TrISG0)//*定义BSy2SO IO(PoxGbuts.Rg0)定义BSy3O-TrI(TrasgButo.TrISG1)//y定义BSy3AIO(PoxGbuts.Rg1)定义Cs1O-TrIS(TrISdBo.TrISD0)//*定义CS1SyIO(LabdBo.LATD0)定义C22TrIS(TrISDITS.TrISD1)//μDEFI RIS(TrasgButs.TrISG7)//y定义BSy1SyIO(PrtgButs.RG.)定义了CS3O-TrIS(TrISDITS.TrISD2)//~定义CS3SO IO(LATDITS.LATD2),定义SavaPiTrIS(TrISdBut.TrISD3)//*定义SWAPHOIO(LATDITS.LATD3)*定义BuSuthGET()(*((易失性无符号CHAR*)(ANP;PORTB))/ /γ定义LeDyPoT(A)(*((Valueun-ChrimeChar *)(&LATA))=(a))TrISB= 0xFF NE CS2IIO(LATDIT)LATD1IS=1;BSy2O-TrIS=1;CS13TrIS=0;CS2Y-TrIs= 0;CS3O-TrIS=0;S/AUTARTY=定义UARTXX-TIIS(TrISFBITS,TrISF5)*定义UARTXXIO(LATFITS.RF5)α定义UARTXXTIIS(TrISFBITS,TrISF4)*定义UARTXXIO(LATFBIT.R4)UARTXXTRIS=0;UART;;//数据BuCNVSTST-TrIS=0;RSTYTrIS=0;BSy1Tr.RXA TrIS=1;LATFBITS。LATF5=1;//uMODE=0x8000;/ /设置UARTEN。注意:这必须在定义UtxEn**之前进行(μ-C30Sy)//USTA= 0x0400;//utxon集定义定义CuffestuuBrgGULL((GETFEUTURARALCCORDER())+8UL*BaDyRATE)/ 16 / BUDYATRATE-1)定义BUDYAUTHORE(GETEnEurralCcOffice)(16)/(CouthestuBurgGy值+ 1)/*这是UART2发送ISR*/ValueAy属性这是UART2接收ISR*//ValueyAtEdTyTyx((α-IdultType))μu2RxCube(空隙)//{//IFS1BIT.U2RXIF=0;//}/*关闭UART2Mult**/CuLUEARTAR2();/*配置UART2接收和发送中断*///CONTICONTARTAR2(UARTHARXRXIN IDEA和A)MP;UARTHARRXYTIN PR6&/UARTARTXXIN IDES和UARTHARTXYTIN PR2);/*配置UART2模块,用一个Stbit传输8位数据。还启用回环模式*/BudValue= 0x33f;U2MODYOUTUENY00和UARTHYIDLYCON和UARTHYRADAY禁用和UARTHYDISHORACE和UARTHYDISCORBACKUP和UARTHYBRGHEX16和UARTJONIOPARPY8 8BIT和/ UUTARJY DISYABAUD和*/UARTHAR1停机器;U2Stavalue= /*UARTHYTIN TIXBUFIHOLL和AMPUARTHI IrDaLoPixIn0&AMP/*UXARTXPIPIORAND AND;*/UARTHEXTXION和//UARTZIN TIN RXY3G4LYONE&*/UARTHARADRIDECTORDESTODIS和UARTHARXRXORUNRUNIORILL;OpenUART2(U2MODEVALUE,U2Stavalue,BaUdValx);
以上来自于百度翻译
以下为原文
Sorry. I've done this hundreds of times with pic18s, just not sure what to think about the brg number. Almost like my clock isn't what I think it is. Set the config bits in mplab to be sure. Thanks.
ABB
Pic is doing 9600 bps 0x0200 = 512. 19.66 mhz crystal. Calculations aren't working. Formula says I should need 127 (512/4) ? Waveforms: 'a'
PC
110ms 650ms 850ms
------ ----------------------- -------
| | | | |
------ ------------- 950ms
220ms
pic
110ms 540ms 740ms 840ms
------ ------------- -------
| | | | |
--------------------- ---------- 950ms
220ms
int main(void)
#endif
{
int i;
i=0;
InitializeBoard();
while(i < 10000)
++i;
i=0;
while(1)
{
/* Load transmit buffer and transmit the same till null character is encountered */
/* putsUART2 ((unsigned int *)Txdata); */
// putsUART2();
U2TXREG = 'a';
/* Wait for transmission to complete */
while(BusyUART2());
while(i < 10000)
i++;
i=0;
}
}
static void InitializeBoard(void)
{
#if defined(__dsPIC33F__) || defined(__PIC24H__)
// Crank up the core frequency
// PLLFBD = 38; // Multiply by 40 for 160MHz VCO output (8MHz XT oscillator)
CLKDIV = 0x0000; // FRC: divide by 2, PLLPOST: divide by 2, PLLPRE: divide by 2
#endif
// 16-bit C30 and and 32-bit C32
// _FOSCSEL(FNOSC_PRIPLL) // PLL enabled
// _FOSC(OSCIOFNC_OFF & POSCMD_XT) // XT Osc
// _FWDT(FWDTEN_OFF) // Disable Watchdog timer
// JTAG should be disabled as well
// dsPIC33F processor
#define GetSystemClock() (19662000ul) // Hz
#define GetInstructionClock() (GetSystemClock()/2)
#define GetPeripheralClock() GetInstructionClock()
// Explorer 16 + PIC24FJ128GA010/PIC24HJ256GP610/dsPIC33FJ256GP710 PIM + Ethernet PICtail Plus
// Explorer 16 + PIC32MX460F512L/PIC32MX360F512L PIM + Ethernet PICtail Plus
#define CNVST_TRIS (TRISCbits.TRISC1) //
#define CNVST_IO (LATCbits.LATC1)
#define RST_TRIS (TRISCbits.TRISC2) //
#define RST_IO (LATCbits.LATC2)
#define BSY1_TRIS (TRISGbits.TRISG7) //
#define BSY1_IO (PORTGBITS.RG7)
#define BSY2_TRIS (TRISGbits.TRISG0) //
#define BSY2_IO (PORTGBITS.RG0)
#define BSY3_TRIS (TRISGbits.TRISG1) //
#define BSY3_IO (PORTGBITS.RG1)
#define CS1_TRIS (TRISDbits.TRISD0) //
#define CS1_IO (LATDbits.LATD0)
#define CS2_TRIS (TRISDbits.TRISD1) //
#define CS2_IO (LATDbits.LATD1)
#define CS3_TRIS (TRISDbits.TRISD2) //
#define CS3_IO (LATDbits.LATD2)
#define SWAP_TRIS (TRISDbits.TRISD3) //
#define SWAP_IO (LATDbits.LATD3)
#define BUS_GET() (*((volatile unsigned char*)(&PORTB)))
// #define LED_PUT(a) (*((volatile unsigned char*)(&LATA)) = (a))
TRISB = 0xff; // Data Bus
CNVST_TRIS = 0;
RST_TRIS = 0;
BSY1_TRIS = 1;
BSY2_TRIS = 1;
BSY3_TRIS = 1;
CS1_TRIS = 0;
CS2_TRIS = 0;
CS3_TRIS = 0;
SWAP_TRIS = 0;
// UART
#define UARTTX_TRIS (TRISFbits.TRISF5)
#define UARTTX_IO (LATFbits.RF5)
#define UARTRX_TRIS (TRISFbits.TRISF4)
#define UARTRX_IO (LATFbits.RF4)
UARTTX_TRIS = 0;
UARTRX_TRIS = 1;
LATFbits.LATF5 = 1;
// UMODE = 0x8000; // Set UARTEN. Note: this must be done before setting UTXEN
#if defined(__C30__)
// USTA = 0x0400; // UTXEN set
#define CLOSEST_UBRG_VALUE ((GetPeripheralClock()+8ul*BAUD_RATE)/16/BAUD_RATE-1)
#define BAUD_ACTUAL (GetPeripheralClock()/16/(CLOSEST_UBRG_VALUE+1))
/* This is UART2 transmit ISR */
void __attribute__((__interrupt__)) _U2TXInterrupt(void)
{
IFS1bits.U2TXIF = 0;
}
/* This is UART2 receive ISR */
// void __attribute__((__interrupt__)) _U2RXInterrupt(void)
// {
// IFS1bits.U2RXIF = 0;
// }
/* Turn off UART2module */
CloseUART2();
/* Configure uart2 receive and transmit interrupt */
// ConfigIntUART2(UART_RX_INT_DIS & UART_RX_INT_PR6 &
// UART_TX_INT_DIS & UART_TX_INT_PR2);
/* Configure UART2 module to transmit 8 bit data with one stopbit. Also Enable loopback mode */
baudvalue = 0x003f;
U2MODEvalue = UART_UEN_00 & UART_IDLE_CON & UART_IrDA_DISABLE &
UART_DIS_WAKE & UART_DIS_LOOPBACK & UART_BRGH_SIXTEEN &
UART_NO_PAR_8BIT & /*UART_DIS_ABAUD & */
UART_1STOPBIT;
U2STAvalue = /* UART_INT_TX_BUF_EMPTY & UART_IrDA_POL_INV_ZERO & */
/*UART_TX_PIN_NORMAL & */
UART_TX_ENABLE & /* UART_INT_RX_3_4_FUL & */
UART_ADR_DETECT_DIS &
UART_RX_OVERRUN_CLEAR;
OpenUART2(U2MODEvalue, U2STAvalue, baudvalue);
#endif
}