
AN1456 APPLICATION NOTE
10/13
A coefficients file is made of two comment lines at the top (comments begin with '#'), and a list of pair address-
value for every coefficient. Note that is not mandatory to put all the coefficients in the file, but only the needed
coefficient can be put. The numeric format for address and values can be either decimal or hexadecimal (ex.
0x1A). To have an example, the suggestion is to try to save the current coefficients, and to take a look to the
saved file.
The C code linked to the Download button is:
The whole coefficients table is parsed with the "for(int i…" loop. A coefficient is written using the procedure de-
scribed in Chapter 10 of the datasheet.
Regarding the read button, the code is:
In this case all the coefficients are read, and stored in the table m_coeff_list.
The code above is just to show the read/write coefficient procedure, is not intended to show a real application
code. Every application could have different code.
BOOL DownloadPage::DownloadCoeff()
{BOOL result=TRUE;
char elem[8];
int val;
for(int i=0;i<NCOEF;++i)
{m_coeff_list.GetItemText(i,1,elem,7);
sscanf(elem,"%x",&val);
result = result && WriteByte(0x78,(val & 0x0ff00)>>8);
result = result && WriteByte(0x79,(val & 0x000ff)>>0);
result = result && WriteByte(0x7A,(i+0x40));
result = result && WriteByte(0x7B,0x0f & ((val & 0xf0000)>>16));
}
return(result);
}
void DownloadPage::OnCoeffRead()
{// TODO: Add your control notification handler code here
int add,coe;
char st[6];
unsigned char dataL,dataM,dataH;
for(add=0;add<NCOEF;++add)
{WriteByte(Coefficent_1H_ADD,(unsigned char)add+0x40);
WriteByte(Coefficent_1L_ADD,(1<<7));
ReadByte(Coefficent_0H_ADD,&dataM);
ReadByte(Coefficent_0L_ADD,&dataL);
ReadByte(Coefficent_1L_ADD,&dataH);
dataH&=0xF;
coe=(unsigned int)dataL+((unsigned int)dataM *256)+
((unsigned int)dataH *256*256);
sprintf(st, "%05x", coe);
m_coeff_list.SetItemText(add,1,st);
}
}