#include <reg52.h>
sbit LED1 = P2^0;
sbit LED2 = P2^3;
unsigned char tempbuf;
/*初始化串口*/
void BlueteethInit()
{
SCON = 0x50;
TMOD = 0x20;
PCON = 0x00;
REN = 1;
TH1 = 0xfd; //設置波特率為9600
TL1 = 0xfd;
RI = 0;
EA = 1;
ES = 1;
TR1 = 1;
}
void main()
{
BlueteethInit();
LED1=1;
LED2=1;
TI = 0;
while(1)
{
if(tempbuf==1)
LED1=0;
if(tempbuf==2)
LED2=0;
}
}
void Serial(void) interrupt 4
{
tempbuf = SBUF;
RI = 0; //讀標志清零
SBUF = tempbuf; //將內容返回到手機端,可在手機查看發送的內容
while(!TI);
TI = 0; //寫標志清零
}
哪里的問題啊,接收到的都是亂碼,hc05默認的波特率9600,
|