PIC单片机异步串口通信只能发不能收
我用的是PIC16F877A,用的是开发板,串口的程序只能发送,不能接收,接收中断可以进去,但是数据不对,我是照着视频教程上的成功的例子做的,程序贴在下面,请参考,是不是我的开发板这块MAX232有问题啊,怎么调也调不出,我怀疑是MAX232及周边电路有问题,
请指点一下呀,谢谢!
// based on PIC16F877A
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
void init();
/////////////////////////////////////////////////////
void main()
{
init();
TXREG = 0x31; //Transmit register
while(!TRMT);
while(1)
{
}
}
////////////////////////////////////////////////////
void init()
{
TRISC=0xff;
TXSTA = 0x24; //Transmit status register
//BRGH =1 : High baud rate bit selected
//SYNC =0 : Asynchronous mode
RCSTA=0x90; //SPEN = 1 : serial port is enable
//CREN = 1 : continuous receive is enable
SPBRG = 25; //ste up baud rate to 9600 bps
GIE=1;
PEIE=1;
RCIE=1; //enable Receive SCI interrupt
}
////////////////////////////////////////////
void interrupt com()
{
unsigned char uchTemp;
if( RCIF )
//if ( RCIF )
{
TXREG = RCREG;
while(!TRMT);
}
} |