我使用pic 16f877a和Hc 06蓝牙模块来接收一个叫做蓝牙终端的Android应用程序的字符串。我收到一些带有问号的旗帜,这些问号没有接收的频率或节奏。我需要配置,以收到该应用程序的字符串。有人可以帮我解决这个问题。谢谢。
#include <stdio.h>
#include <xc.h>
#pragma config=0x2F0A
#define _XTAL_FREQ 8000000
#define BAUDRATE 9600
#include <stdlib.h>
#include "usart_pic16.h"
#include <math.h>
// BEGIN CONFIG
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config BOREN = ON
#pragma config LVP = OFF
#pragma config CPD = OFF
#pragma config WRT = OFF
#pragma config CP = OFF
void InitUART(void) {
BRGH = 1;
SPBRG = ((_XTAL_FREQ/16)/BAUDRATE) -1 ;
TRISC6 = 0; // TX Pin
TRISC7 = 1; // RX Pin
TXSTA = 0x24;
RCSTA = 0x90;
//SPBRG = 51;
}
// Writes a character to the serial port
void SendByteSerially(unsigned char Byte) {
if(!TXIF) ; // wait for previous transmission to finish
TXREG = Byte;
}
// Reads a character from the serial port
unsigned char ReceiveByteSerially(void) {
while(!RCIF)
continue; // Wait for transmission to receive
return RCREG;
}
void SendStringSerially(const unsigned char* st) {
if(*st)
SendByteSerially(*st++);
}
void ReceiveByteSerially(const unsigned char* st) {
while(*st)
ReceiveByteSerially(*st++);
void main (void) {
InitUART(); // Intialize UART
while(1){
SendStringSerially("Hello World");
}