lecanhhuy
07-04-2009, 09:24 PM
#include "p30f4011.h"
_FOSC(CSW_FSCM_OFF & HS);
_FWDT(WDT_OFF);
_FBORPOR(MCLR_EN & PBOR_OFF & PWMxL_ACT_HI & PWMxH_ACT_HI);
_FGS(CODE_PROT_OFF);
//Cac prototype cho cac chuong trinh con
void Init_UART1_Module(void);
//Cac bien toan cuc
unsigned short temp=0;
//------------------------------------------------------------------------------
//Chuong trinh chinh
int main(void) {
Init_UART1_Module();
LATB=0x00FF;
while (1) {
if (U1STAbits.URXDA) { //Cho den khi nhan duoc mot ky tu
temp = U1RXREG;
//Doc ky tu da nhan duoc vao temp
U1TXREG = temp + 1; //Gui tra ky tu da duoc sua doi (cong 1 vao)
while(!U1STAbits.TRMT);
};
};
}
//Chuong trinh con khoi tao module UART1
void Init_UART1_Module(void) {
TRISB = 0xFF00;
TRISCbits.TRISC13 = 0; // U1TX
TRISCbits.TRISC14 = 1; // U1RX
U1MODE = 0x8000; //Main I/O, 8-bit, no parity, 1 stop bit
U1STA = 0x0400; //bit10=UTXEN
U1BRG = 11; //Baud rate = 9600 ZTAL=7.3728 MHZ
}
Em dùng Terminal để send kí tự nhưng kô thấy jì .Xin các cao thủ trợ giúp!!!
_FOSC(CSW_FSCM_OFF & HS);
_FWDT(WDT_OFF);
_FBORPOR(MCLR_EN & PBOR_OFF & PWMxL_ACT_HI & PWMxH_ACT_HI);
_FGS(CODE_PROT_OFF);
//Cac prototype cho cac chuong trinh con
void Init_UART1_Module(void);
//Cac bien toan cuc
unsigned short temp=0;
//------------------------------------------------------------------------------
//Chuong trinh chinh
int main(void) {
Init_UART1_Module();
LATB=0x00FF;
while (1) {
if (U1STAbits.URXDA) { //Cho den khi nhan duoc mot ky tu
temp = U1RXREG;
//Doc ky tu da nhan duoc vao temp
U1TXREG = temp + 1; //Gui tra ky tu da duoc sua doi (cong 1 vao)
while(!U1STAbits.TRMT);
};
};
}
//Chuong trinh con khoi tao module UART1
void Init_UART1_Module(void) {
TRISB = 0xFF00;
TRISCbits.TRISC13 = 0; // U1TX
TRISCbits.TRISC14 = 1; // U1RX
U1MODE = 0x8000; //Main I/O, 8-bit, no parity, 1 stop bit
U1STA = 0x0400; //bit10=UTXEN
U1BRG = 11; //Baud rate = 9600 ZTAL=7.3728 MHZ
}
Em dùng Terminal để send kí tự nhưng kô thấy jì .Xin các cao thủ trợ giúp!!!