为了检测我的单片机接受数据能正常显示,修改了原本只能从串口一次读单个字节的程序,其实很简单,但是折腾挺久的。
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "key.h"
#include "leds.h"
#include "time.h"
#include "uart.h"
#include "stdio.h"
#include "lcd1602.h"
void main()
{
char *msg;
Uint16 num=0;
char key=0;
InitSysCtrl();
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
KEY_Init();
UARTa_Init(9600);
LCD1602_Init();
while(1)
{
key=KEY_Scan(1);
switch(key)
{
case KEY1_PRESS:
msg = "begin";
UARTa_SendString(msg);//发送启动消息给上位机
break;
case KEY2_PRESS:
msg = "ending";
UARTa_SendString(msg);//发送结束消息给上位机
break;
case KEY3_PRESS:
LED4_TOGGLE;
msg = "L15000";
UARTa_SendString(msg);//发送绳长给上位机
}
char sdataB[8];
Uint16 empty_fifo_number,i;
if(SciaRegs.SCIFFRX.bit.RXFFST > 0)
{
empty_fifo_number = SciaRegs.SCIFFRX.bit.RXFFST;
for(i=0;i<empty_fifo_number;i++)
{
sdataB[i] = SciaRegs.SCIRXBUF.all;//从上位机通过串口获取数据
}
}
if(num==100)
{
LCD1602_DispString(1,sdataB);//发送给LCD1602
num=0;
DELAY_US(1000);
num++;
}
}