165 lines
2.6 KiB
C
165 lines
2.6 KiB
C
#include "DSP2833x_Device.h" // DSP281x Headerfile Include File
|
|
#include "DSP2833x_SWPrioritizedIsrLevels.h"
|
|
#include "filter_bat2.h"
|
|
#include "measure.h"
|
|
|
|
#include "RS485.h"
|
|
#include "message.h"
|
|
#include "kanal.h"
|
|
#include "test.h"
|
|
#include "package.h"
|
|
#include "tools.h"
|
|
|
|
#include "peripher.h"
|
|
|
|
int digits[16] = {63,6,91,79,102,109,125,7,127,111,64,0,0,0,121,0};
|
|
|
|
void DCLK(int x)
|
|
{
|
|
if(x) GpioDataRegs.GPASET.bit.GPIO6=1;
|
|
else GpioDataRegs.GPACLEAR.bit.GPIO6=1;
|
|
DSP28x_usDelay(1L);
|
|
}
|
|
|
|
void DOUT(int x)
|
|
{
|
|
if(x) GpioDataRegs.GPASET.bit.GPIO8=1;
|
|
else GpioDataRegs.GPACLEAR.bit.GPIO8=1;
|
|
DSP28x_usDelay(1L);
|
|
}
|
|
|
|
void RESET()
|
|
{
|
|
DCLK(0); DOUT(1);
|
|
DCLK(0); DOUT(0);
|
|
}
|
|
|
|
void SENDBIT(int x)
|
|
{
|
|
DOUT(x); DCLK(1);
|
|
DOUT(0); DCLK(0);
|
|
}
|
|
|
|
void kanal_Send(int adr, long dat, int dot)
|
|
{
|
|
long Word,data,aliq_part,dg[4];
|
|
int i,j,bit,byt,addr,sgn=0,punkt=0,aliq_len=0,full_len;
|
|
|
|
if(adr>1) // Ëàìïî÷êè
|
|
{
|
|
Word =dat;
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
if(dot<0 || dot>13) // Îøèáêà: -Å...
|
|
{
|
|
dg[3] = 0xA; dg[2] = 0xE;
|
|
dg[1] = 0xF; dg[0] = 0xF;
|
|
punkt = 0x7;
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
if(dat<0) sgn=1;
|
|
data = labs(dat);
|
|
|
|
aliq_part = data;
|
|
for(i=0;i<dot;i++) aliq_part/=10;
|
|
|
|
dat = aliq_part;
|
|
while(dat>0)
|
|
{
|
|
aliq_len++; dat/=10;
|
|
}
|
|
|
|
if(aliq_len+sgn>4)
|
|
{
|
|
if(sgn) dg[3] = 0xA;
|
|
else dg[3] = 0xF;
|
|
|
|
dat = aliq_part;
|
|
for(i=1;i<aliq_len;i++) dat/=10;
|
|
|
|
dg[2] = dat;
|
|
dg[1] = 0xE;
|
|
dg[0] = aliq_len-1;
|
|
punkt=0;
|
|
}
|
|
else
|
|
{
|
|
dat = data;
|
|
|
|
full_len = aliq_len+sgn;
|
|
if(full_len==0) full_len=1;
|
|
full_len += dot;
|
|
|
|
for(i=0; i<(full_len-4);i++)
|
|
{
|
|
dot--; dat/=10;
|
|
}
|
|
if(dot<0) dot=0;
|
|
punkt = 1<<dot;
|
|
if(punkt==1) punkt=0;
|
|
|
|
dg[3] = (dat)/1000;
|
|
dg[2] = (dat%1000)/100;
|
|
dg[1] = (dat%100)/10;
|
|
dg[0] = (dat%10);
|
|
|
|
if(dg[0]+dg[1]+dg[2]+dg[3]==0)
|
|
{
|
|
punkt=0; dot=0; sgn=0;
|
|
}
|
|
|
|
for(i=3;i>0;i--)
|
|
{
|
|
if((dg[i]==0)&&(i!=dot))
|
|
dg[i]=0xF; // Ýòî çíà÷èò ïóñòî
|
|
else break;
|
|
}
|
|
|
|
if(sgn)
|
|
for(i=1;i<4;i++)
|
|
{
|
|
if( (dg[i]==0xF)||(i==3))
|
|
{
|
|
dg[i]=0xA; // Ýòî çíà÷èò ìèíóñ
|
|
break;
|
|
} } } }
|
|
|
|
for(i=0;i<4;i++)
|
|
{
|
|
dg[i] = digits[dg[i]];
|
|
if((punkt>>i)&1) dg[i]+= 128;
|
|
|
|
}
|
|
|
|
Word = ((dg[0] ) & 0x000000FF) | ((dg[1]<<8 ) & 0x0000FF00) |
|
|
((dg[2]<<16) & 0x00FF0000) | ((dg[3]<<24) & 0xFF000000);
|
|
}
|
|
|
|
for (i=0;i<4;i++)
|
|
{
|
|
if(addr>0x10) break;
|
|
|
|
for (j=0;j<8;j++)
|
|
{
|
|
bit = Word & 1; Word >>= 1;
|
|
SENDBIT(bit);
|
|
}
|
|
|
|
byt = addr;
|
|
for (j=0;j<6;j++)
|
|
{
|
|
bit = byt & 1; byt >>= 1;
|
|
SENDBIT(bit);
|
|
}
|
|
addr++;
|
|
|
|
RESET();
|
|
}
|
|
}
|