#include <ioCC2530.h>
#include "type.h"
#include "hal_lcd.h"
//unsigned char uart[6]=0;
char tt[]="0103000c00020408";
//char TxData[TX_SIZE]; //存储发送字符串
char RxBuf=0;
char RxDate[51];
int count=0;
void HalLcd_HW_WaitUs(uint16 microSecs);
void InitUart(void)
{
PERCFG = 0x00; //外设控制寄存器 USART 0的IO位置:0为P0口位置1
P0SEL = 0x0c; //P0_2,P0_3用作串口(外设功能)
P2DIR &= ~0xC0; //P0优先作为UART0
U0CSR |= 0x80; //设置为UART方式
U0GCR |= 8;
U0BAUD |= 59; //波特率设为115200
UTX0IF = 0; //UART0 TX中断标志初始置位0
U0CSR |= 0x40; //允许接收
IEN0 |= 0x84; //开总中断允许接收中断
}
void UartSendString(char *Data, int len)
{
int i;
for(i=0; i<len; i++)
{
U0DBUF = *Data++;
while(UTX0IF == 0);
UTX0IF = 0;
}
}
#pragma vector = URX0_VECTOR
__interrupt void UART0_ISR(void)
{
URX0IF = 0; // 清中断标志
RxBuf= U0DBUF;
}
void main(void)
{
CLKCONCMD &= ~0x40; //设置系统时钟源为32MHZ晶振
while(CLKCONSTA & 0x40); //等待晶振稳定为32M
CLKCONCMD &= ~0x47; //设置系统主时钟频率为32MHZ
InitUart(); //调置串口相关寄存器
HalLcd_HW_Init(); //初始化LCD
//memset(uart, 0, 50); //数据清0
// memcpy(uart, tt, sizeof(tt)); //复制发送字符串到TxData
HalLcd_HW_WriteLine(1,tt);
UartSendString(tt, sizeof(tt)); //串口发送数据
/*
UartSendString("01", 2);
UartSendString("03", 2);
UartSendString("00", 2);
UartSendString("0c", 2);
UartSendString("00", 2);
UartSendString("02", 2);
UartSendString("04", 2);
UartSendString("08", 2);
*/
// HalLcd_HW_WaitUs(20);
while(RxBuf!='\0')
{
RxDate[count++]=RxBuf;
}
HalLcd_HW_WriteLine(2,RxDate);
// HalLcd_HW_WriteLine(3,"i am");
}
以上是我的程序 通过查仪表的说明书 发送 01 03 00 0c 00 02 04 08给仪表 然后接收仪表的回传数据显示到12864上 但是没有显示任何东西 |