新手自己编写了一段接收串口数据,然后把接收到的数据显示在数码管上的程序。程序不能直接直接驱动74HC595是数码管显示,必须要运行其他能正常让数码管显示的程序后再运行我编的程序,数码管才能正常显示。简单而言,就是需要别的数码管程序跑一遍,再跑我的程序才能正常运行,但是一单断开仿真器在连接的话有需要跑一次其他程序。求大神指点
程序如下:
#include "DSP28_Device.h"
unsigned int Sci_VarRx[100];
unsigned int i;
unsigned int Send_Flag;
int A,B,C,D,E,F,X,Z,temp;
void delay(unsigned int);
void ldelay(unsigned int);
void WriteLED(unsigned int);
void main(void)
{
InitSysCtrl();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
InitGpio();
InitPeripherals();
for(i = 0; i < 100; i++)
{
Sci_VarRx = 0;
}
i = 0;
Send_Flag = 0;
for(;;)
{
if((SciaTx_Ready() == 1) && (Send_Flag == 1))
{
SciaRegs.SCITXBUF = Sci_VarRx;
X=Sci_VarRx;
WriteLED(temp);
ldelay(10);
Send_Flag = 0; //清标志位
i++;
if(i == 100)
{
i = 0;
}
}
if(SciaRx_Ready() == 1)
{
Sci_VarRx = SciaRegs.SCIRXBUF.all;
Send_Flag = 1;
}
}
}
/*判断中间变量X的值,并在数码管上显示对应值*/
void WriteLED(unsigned int index)
{
if(X==0){Z=0XF03F;}
else if (X==1){Z=0XFE7F;}
else if (X==2){Z=0XE93F;}
else if (X==3){Z=0XEC3F;}
else if (X==4){Z=0XE67F;}
else if (X==5){Z=0XE4BF;}
else if (X==6){Z=0XE0BF;}
else if (X==7){Z=0XFE3F;}
else if (X==8){Z=0XE03F;}
else if (X==9){Z=0XE43F;}
else if (X==0xA){Z=0XE23F;}
else if (X==0xB){Z=0XE0FF;}
else if (X==0xC){Z=0XF1BF;}
else if (X==0xD){Z=0XE87F;}
else if (X==0xE){Z=0XE1BF;}
else if (X==0xF){Z=0XE3BF;}
else{Z=0X3FC0;}
if(Spi_TxReady() == 1)
SpiaRegs.SPITXBUF = Z;
delay(50000);
GpioDataRegs.GPACLEAR.all|=0x8000;
delay(1000);
GpioDataRegs.GPASET.all|=0x8000;
}
void ldelay(unsigned int k)
{
while(k>0)
{
k--;
delay(50000);
}
}
void delay(unsigned int t)
{
while(t>0)
t--;
}
|