Trích:
Nguyên văn bởi spin
anh namqn giúp em với.. sửa mãi mà nó vẫn vậy.
code:
#include "p33FJ256GP710.h"
_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT);
// Clock Switching is enabled and Fail Safe Clock Monitor is disabled
// OSC2 Pin Function: OSC2 is Clock Output
// Primary Oscillator Mode: XT Crystanl
_FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
_FGS(GCP_OFF); //Turn off code protect
_FPOR(FPWRT_PWR1); //Turn off power up timer
//Cac prototype cho cac chuong trinh con
void Init_TMR1(void);
void Init_UART1_Module(void);
//Bang hang so trong ROM
const unsigned char __attribute__ ((space(psv), address (0xF000)))
Chuoi1[] = "Xin chao! \0";
//Cac bien toan cuc
unsigned char idx;
//------------------------------------------------------------------------------
//Chuong trinh chinh
int main(void)
{
CLKDIVbits.PLLPOST=0; // N1=2
CLKDIVbits.PLLPRE=0; // N2=2
Init_UART1_Module(); //Khoi tao module UART1
_PSV=1;
PSVPAG = __builtin_psvpage(Chuoi1);
while (1)
{
idx = 0;
while (Chuoi1[idx])
{ //Neu chua het chuoi thi
U1TXREG = Chuoi1[idx++]; //Xuat tiep 1 ky tu
while (!U1STAbits.TRMT); //Cho den khi truyen xong ky tu
};
};
}
//Chuong trinh con khoi tao module UART1
void Init_UART1_Module(void)
{
U2MODEbits.STSEL = 0; //Main I/O, 8-bit, no parity, 1 stop bit
U2STAbits.UTXEN = 1; // Enable UART Tx
U1BRG = (((4000000/9600)/16)-1); //9600 bps @ Fcy = 4 MHz
}
|
xem lại tấc độ truyền nhận trên chip và terminal trên máy tính xem thế nào, và kiểm tra như ban mtuankct đã nói.