#define BT_PIO0 LATCbits.LATC4
#define BT_PIO1 LATCbits.LATC5
#define BT_TX LATCbits.LATC6
#define BT_RX LATCbits.LATC7
unsigned char ReceiveFlag=1;
unsigned char GetReceiveData;
unsigned char receive_data[15];
unsigned char send_data[15];
unsigned int i=0;
void Delay10TCYx(unsigned char);
void Delay1KTCYx(unsigned char);
void BT_PORTinit(void)
{
TRISCbits.TRISC0=0;
LATCbits.LATC0=1;
TRISCbits.TRISC4=0;
TRISCbits.TRISC5=1;
TRISCbits.TRISC6=0;
TRISCbits.TRISC7=1;
BT_PIO0=0;
BT_PIO1=0;
}
void BT_URAT_Init(void)
{
BAUDCON1bits.BRG16=0;
TXSTA1bits.BRGH=1;
SPBRG1=71;
TXSTA1bits.TX9=0;
TXSTA1bits.SYNC=0;
TXSTA1bits.TXEN=1;
RCSTA1bits.CREN=1;
RCSTA1bits.RX9=0;
RCSTA1bits.ADDEN=1;
RCSTA1bits.SPEN=1;
}
void main(void)
{
unsigned int i=0;
unsigned char sendstr[]={'L','A','N',' ','Y','A',' ','M','O',' ','K','U','A','I'};
BT_PORTinit();
BT_URAT_Init();
// RCONbits.IPEN=0;
// INTCON|=0XC0;
while(1)
{
if(1==ReceiveFlag)
{
ReceiveFlag=0;
for(i=0;i<14;i++)
{
TXREG1=sendstr[i];
while(0==TXSTA1bits.TRMT);
sendstr[i]=0;
}
}
这是一个单片机串口发送字符程序,用的是查询方式,在PC上能正确显示数据,我想发送35,3.4,120.5,这样的数据该怎么改写啊,在我这个字符串里面unsigned char sendstr[]={35,3.4,120.5};这样收到的就是一串乱码,TXREG1=sendstr[i];,pic发送寄存器只能发一个字符啊,想要发数字的数据该怎么改写,求大侠给我指点怎么改写,万分感谢! |