📄 disp.c
字号:
}
}
}
return t_data[2];
}
/*
***********************************************************************************************************
**函数原型 : get_spi_data()
**参数说明 :
:
**返回值 :
**说 明 : 本函数用于采集7022B的具体数据,并在精度和稳定行上对他们进行调整
340和7022B采用SPI主从模式传输,340是主机,所以先对SPI0DAT写入数据,才开始发送
************************************************************************************************************/
void clear_7022B_data()
{//清校表数据
SPI_DATA_START();
SPI_CS_LOW_LEVEL();
spi_delay(200);
SPI0DAT = COMMAND_CLEAR_DATA;//命令字
spi_delay(30);
while(!SPIF);
spi_delay(60);
SPIF = 0;
SPI0DAT= 0x00;//24数据位
spi_delay(30);
while(!SPIF);
spi_delay(60);
SPIF = 0;
SPI0DAT = 0x00;
spi_delay(30);
while(!SPIF);
spi_delay(60);
SPIF = 0;
SPI0DAT = 0x00;
spi_delay(30);
while(!SPIF);
spi_delay(60);
SPIF = 0;
spi_delay(200);
SPI_CS_HIGH_LEVEL();
}
void get_spi_chksum_data()
{
spi_delay(150);
SPI_DATA_START();
SPI_CS_LOW_LEVEL();
SPI0DAT = r_ChkSum1;//校验和
read_spi_data();
if(0 == first_power_on){//新上电或者复位
first_power_on = 1;
ChkSum1_high_byte8 = original_high_byte;
ChkSum1_middle_byte8 = original_middle_byte;
ChkSum1_low_byte8 = original_low_byte;
}
else{
if((original_high_byte == RESET_ChkSum1_HIGH8) && (original_middle_byte == RESET_ChkSum1_MIDDLE8) && (original_low_byte == RESET_ChkSum1_LOW8)){
//三相四线,校表数据校验和等于7022B复位值,三相四线等于0x043d03.三相三线等于0x16bd03
init_7022B(); //写入校表数据后,1/3秒后7022B才更新校验和数据
first_power_on = 0;
}
else if((original_high_byte != ChkSum1_high_byte8) || (original_middle_byte != ChkSum1_middle_byte8) || (original_low_byte != ChkSum1_low_byte8)){
//校验和错误
init_7022B(); //写入校表数据后,1/3秒后7022B才更新校验和数据
first_power_on = 0;
}
}
}
void get_spi_U_data(){
int ppt;
uint line_vol;
uint average;
spi_delay(150);
SPI_DATA_START();
SPI_CS_LOW_LEVEL();//CS片选下降沿表示SPI操作,上升沿表示操作结束
SPI0DAT = r_URmsa;/*U,先写入7022B中Ua寄存器的地址*/
read_spi_data();
average = COMBINE_2UCHAR_TO_16UINT(original_high_byte,original_middle_byte);
if((original_high_byte == Ua.high_byte8) && (original_middle_byte == Ua.low_byte8)){//如果和当前值想相等
Ua.filter_number = 0;//过滤计数器
}
else if((original_high_byte == Ua.high_byte8) && ((abs(original_middle_byte - Ua.low_byte8)) > 9) &&
((abs(original_middle_byte - Ua.low_byte8)) < 100)){//限幅,避免干扰
_nop_();
}
else{//消抖
++Ua.filter_number;
}
if(Ua.filter_number > FILTER_DITHERING_TIMES){//将本次的值和当前值取平均值作为当前值
ppt = average * 0.5 + COMBINE_2UCHAR_TO_16UINT(Ua.high_byte8,Ua.low_byte8) * 0.5;
original_high_byte = ppt >>8;
original_middle_byte = ppt;
if(((original_high_byte == 0x00) && (original_middle_byte < VAL_TO_ZERO_UA_LOW))
|| ((original_high_byte == 0xff) && (original_middle_byte > VAL_TO_ZERO_NEGATIVE_UI))){
Ua.high_byte8 = 0;
Ua.low_byte8 = 0;
}
else{
if((original_high_byte == Ua.high_byte8) && (abs(Ua.low_byte8 - original_middle_byte) < 10))_nop_();
else if(abs(Ua.high_byte8 - original_high_byte) > DISTURB_WARP_VALUE){
if(++Ua.burr > STRONG_DISTURB_TIMES){//过滤强干扰
Ua.burr = 0;
Ua.high_byte8 = original_high_byte;
Ua.low_byte8 = original_middle_byte;
}
else { _nop_();
}
}
else{//屏蔽码值小于10的数
Ua.burr = 0;//强干扰计数器清零
Ua.high_byte8 = original_high_byte;
Ua.low_byte8 = original_middle_byte;
}
}
}
SPI_DATA_START();
SPI_CS_LOW_LEVEL();
SPI0DAT = r_URmsb;
read_spi_data();
average = COMBINE_2UCHAR_TO_16UINT(original_high_byte,original_middle_byte);;
if((original_high_byte == Ub.high_byte8) && (original_middle_byte == Ub.low_byte8)){//如果和当前值想相等
Ub.filter_number = 0;//过滤计数器
}
else if((original_high_byte == Ub.high_byte8) && ((abs(original_middle_byte - Ub.low_byte8)) > 9) &&
((abs(original_middle_byte - Ub.low_byte8)) < 100)){//限幅,避免干扰
_nop_();
}
else{//消抖
++Ub.filter_number;
}
if(Ub.filter_number > FILTER_DITHERING_TIMES){//将本次的值和当前值取平均值作为当前值
ppt = average * 0.5 + COMBINE_2UCHAR_TO_16UINT(Ub.high_byte8,Ub.low_byte8) * 0.5;
original_high_byte = ppt >>8;
original_middle_byte = ppt;
if(((original_high_byte == 0x00) && (original_middle_byte < VAL_TO_ZERO_UB_LOW))
|| ((original_high_byte == 0xff) && (original_middle_byte > VAL_TO_ZERO_NEGATIVE_UI))){
Ub.high_byte8 = 0;
Ub.low_byte8 = 0;
}
else{
if((original_high_byte == Ub.high_byte8) && (abs(Ub.low_byte8 - original_middle_byte) < 10))_nop_();
else if(abs(Ub.low_byte8 - original_high_byte) > DISTURB_WARP_VALUE){
if(++Ub.burr > STRONG_DISTURB_TIMES){//过滤强干扰
Ub.burr = 0;
Ub.high_byte8 = original_high_byte;
Ub.low_byte8 = original_middle_byte;
}
else { _nop_();
}
}
else{//屏蔽码值小于10的数
Ub.burr = 0;
Ub.high_byte8 = original_high_byte;
Ub.low_byte8 = original_middle_byte;
}
}
}
SPI_DATA_START();
SPI_CS_LOW_LEVEL();
SPI0DAT = r_URmsc;
read_spi_data();
average = COMBINE_2UCHAR_TO_16UINT(original_high_byte,original_middle_byte);
if((original_high_byte == Uc.high_byte8) && (original_middle_byte == Uc.low_byte8)){//如果和当前值想相等
Uc.filter_number = 0;//过滤计数器
}
else if((original_high_byte == Uc.high_byte8) && ((abs(original_middle_byte - Uc.low_byte8)) > 9) &&
((abs(original_middle_byte - Uc.low_byte8)) < 100)){//限幅,避免干扰
_nop_();
}
else{//消抖
++Uc.filter_number;
}
if(Uc.filter_number > FILTER_DITHERING_TIMES){//将本次的值和当前值取平均值作为当前值
ppt = average * 0.5 + COMBINE_2UCHAR_TO_16UINT(Uc.high_byte8,Uc.low_byte8) * 0.5;
original_high_byte = ppt >> 8;
original_middle_byte = ppt;
if(((original_high_byte == 0x00) && (original_middle_byte < VAL_TO_ZERO_UC_LOW))
|| ((original_high_byte == 0xff) && (original_middle_byte > VAL_TO_ZERO_NEGATIVE_UI))){
Uc.high_byte8 = 0;
Uc.low_byte8 = 0;
}
else{
if((original_high_byte == Uc.high_byte8) && (abs(Uc.low_byte8 - original_middle_byte) < 10))_nop_();
else if(abs(Uc.high_byte8 - original_high_byte) > DISTURB_WARP_VALUE){
if(++Uc.burr > STRONG_DISTURB_TIMES){//过滤强干扰
Uc.burr = 0;
Uc.high_byte8 = original_high_byte;
Uc.low_byte8 = original_middle_byte;
}
else { _nop_();
}
}
else{//屏蔽码值小于10的数
Uc.burr = 0;
Uc.high_byte8 = original_high_byte;
Uc.low_byte8 = original_middle_byte;
}
}
}
if(((Ua.high_byte8 == 0) && (Ua.low_byte8 == 0)) || ((Ub.high_byte8 == 0) && (Ub.low_byte8 == 0)) || ((Uc.high_byte8 == 0) && (Uc.low_byte8 == 0))){
if(((Ua.high_byte8 == 0) && (Ua.low_byte8 == 0)) && ((Ub.high_byte8 == 0) && (Ub.low_byte8 == 0))){
Uab.high_byte8 = 0; Uab.low_byte8 = 0;
Ubc.high_byte8 = Uc.high_byte8; Ubc.low_byte8 = Uc.low_byte8;
Uca.high_byte8 = Uc.high_byte8; Uca.low_byte8 = Uc.low_byte8;
}
else if(((Ub.high_byte8 == 0) && (Ub.low_byte8 == 0)) && ((Uc.high_byte8 == 0) && (Uc.low_byte8 == 0))){
Uab.high_byte8 = Ua.high_byte8; Uab.low_byte8 = Ua.low_byte8;
Ubc.high_byte8 = 0; Ubc.low_byte8 = 0;
Uca.high_byte8 = Ua.high_byte8; Uca.low_byte8 = Ua.low_byte8;
}
else if(((Ua.high_byte8 == 0) && (Ua.low_byte8 == 0)) && ((Uc.high_byte8 == 0) && (Uc.low_byte8 == 0))){
Uab.high_byte8 = Ub.high_byte8; Uab.low_byte8 = Ub.low_byte8;
Ubc.high_byte8 = Ub.high_byte8; Ubc.low_byte8 =Ub.low_byte8 ;
Uca.high_byte8 = 0; Uca.low_byte8 = 0;
}
else if((Ua.high_byte8 == 0) && (Ua.low_byte8 == 0)){
Uab.high_byte8 = Ub.high_byte8 ; Uab.low_byte8 = Ub.low_byte8;
line_vol = ((0 | Ub.high_byte8 )<<8 | Ub.low_byte8) * 1.732;
Ubc.high_byte8 = line_vol >> 8;
Ubc.low_byte8 = line_vol;
Uca.high_byte8 = Uc.high_byte8 ; Uca.low_byte8 = Uc.low_byte8;
}
else if((Ub.high_byte8 == 0) && (Ub.low_byte8 == 0)){
Uab.high_byte8 = Ua.high_byte8 ; Uab.low_byte8 = Ua.low_byte8;
Ubc.high_byte8 = Uc.high_byte8 ; Ubc.low_byte8 = Uc.low_byte8;
line_vol = ((0 | Uc.high_byte8)<<8 | Uc.low_byte8) * 1.732;
Uca.high_byte8 = line_vol >> 8;
Uca.low_byte8 = line_vol;
}
else if((Uc.high_byte8 == 0) && (Uc.low_byte8 == 0)){
line_vol = ((0 | Ua.high_byte8)<<8 | Ua.low_byte8) * 1.732;
Uab.high_byte8 = line_vol >> 8;
Uab.low_byte8 = line_vol;
Ubc.high_byte8 = Ub.high_byte8; Ubc.low_byte8 = Ub.low_byte8;
Uca.high_byte8 = Ua.high_byte8; Uca.low_byte8 = Ua.low_byte8;
}
}
else{
line_vol = ((0 | Uc.high_byte8)<<8 | Uc.low_byte8) * 1.732;
Uca.high_byte8 = line_vol >> 8;
Uca.low_byte8 = line_vol;
line_vol = ((0 | Ua.high_byte8)<<8 | Ua.low_byte8) * 1.732;
Uab.high_byte8 = line_vol >> 8;
Uab.low_byte8 = line_vol;
line_vol = ((0 | Ub.high_byte8)<<8 | Ub.low_byte8) * 1.732;
Ubc.high_byte8 = line_vol >> 8;
Ubc.low_byte8 = line_vol;
}
}
void get_spi_I_data(){
uchar kt1 = 0;
int ppt;
uint average;
SPI_DATA_START();
SPI_CS_LOW_LEVEL();
SPI0DAT = r_IRmsa;/*I*/
read_spi_data();
recombine_i_data();
average = COMBINE_2UCHAR_TO_16UINT(new_recombine_high,new_recombine_low);
if((new_recombine_high == Ia.high_byte8) && (abs((new_recombine_low - Ia.low_byte8)<5))){//如果和当前值想相等
Ia.filter_number = 0;//过滤计数器
}
else if((new_recombine_high == Ia.high_byte8) && ((abs(new_recombine_low - Ia.low_byte8)) > 15) &&
((abs(new_recombine_low - Ia.low_byte8)) < 100)){//限幅,避免干扰
_nop_();
}
else{//消抖
++Ia.filter_number;
}
if(Ia.filter_number > FILTER_DITHERING_TIMES){//将本次的值和当前值取平均值作为当前值
ppt = average * 0.5 + COMBINE_2UCHAR_TO_16UINT(Ia.high_byte8,Ia.low_byte8) * 0.5;
new_recombine_high = ppt >>8;
new_recombine_low = ppt;
if(((new_recombine_high == 0x00) && (new_recombine_low < VAL_TO_ZERO_IA_LOW))
||((new_recombine_high == 0xff) && (new_recombine_low > VAL_TO_ZERO_NEGATIVE_UI))){ //正负0.5
Ia.high_byte8 = 0;
Ia.low_byte8 = 0;
}
else{
if((new_recombine_high == Ia.high_byte8) && (abs(Ia.low_byte8 - new_recombine_low) < 25))_nop_();
else if(abs(Ia.high_byte8 - new_recombine_high) > DISTURB_WARP_VALUE){
if(++Ia.burr > STRONG_DISTURB_TIMES){//过滤强干扰
Ia.burr = 0;
Ia.high_byte8 = new_recombine_high;
Ia.low_byte8 = new_recombine_low;
}
else {
_nop_();
}
}
else{//屏蔽码值小于10的数
Ia.burr = 0;
Ia.high_byte8 = new_recombine_high;
Ia.low_byte8 = new_recombine_low;
}
}
}
SPI_DATA_START();
SPI_CS_LOW_LEVEL();
SPI0DAT = r_IRmsb;
read_spi_data();
recombine_i_data();
average = COMBINE_2UCHAR_TO_16UINT(new_recombine_high,new_recombine_low);
if((new_recombine_high == Ib.high_byte8) && (abs((new_recombine_low - Ib.low_byte8)<5))){//如果和当前值想相等
Ib.filter_number = 0;//过滤计数器
}
else if((new_recombine_high == Ib.high_byte8) && ((abs(new_recombine_low - Ib.low_byte8)) > 15) &&
((abs(new_recombine_low - Ib.low_byte8)) < 100)){//限幅,避免干扰
_nop_();
}
else{//消抖
++Ib.filter_number;
}
if(Ib.filter_number > FILTER_DITHERING_TIMES){//将本次的值和当前值取平均值作为当前值
ppt = average * 0.5 + COMBINE_2UCHAR_TO_16UINT(Ib.high_byte8,Ib.low_byte8) * 0.5;
new_recombine_high = ppt >>8;
new_recombine_low = ppt;
if(((new_recombine_high == 0x00) && (new_recombine_low < VAL_TO_ZERO_IA_LOW))
||((new_recombine_high == 0xff) && (new_recombine_low > VAL_TO_ZERO_NEGATIVE_UI))){
Ib.high_byte8 = 0;
Ib.low_byte8 = 0;
}
else{
if((ne
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -