📄 flash.c.bak
字号:
#include <msp430x13x.h>
unsigned int flash_data_buff[10];
void write_flash ();
void read_flash (void);
void flash_init(void);
extern void clr_wdt(void); //复位看门狗
//////////////////////////////////////////////////////////
extern unsigned int ZB_Count;
extern unsigned int CT_current_A,CT_current_B,CT_current_C;
extern unsigned char two_CT_state; //二次CT状态字
extern unsigned char S331_341; //331与341选择 1:341 0 :331
unsigned char KL_ZBstart=1;//此位为0 则所有的判断程序不执行
unsigned char KL_ZBstate1A=0;
unsigned char KL_ZBstate05A=0;
unsigned char KL_ZBstate0A=0;
unsigned char KL_ZBstate5A=0;
#define ZB_state flash_data_buff[9] //电流屏蔽,为0则不屏蔽
unsigned char KL_ZBBB=0;
//////////////////////////////////////////////////////////
void flash_init(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FCTL2 = FWKEY + FSSEL0 + FN0; // MCLK/2 for Flash Timing Generator
}
void write_flash (void)
{ unsigned char temp3;
unsigned int temp;
unsigned char temp2;
unsigned char *Flash_ptr; // Flash pointer
unsigned char i;
Flash_ptr = (unsigned char *) 0x1000; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<10; i++)
{ clr_wdt();
temp=flash_data_buff[i];
temp3=temp;
temp2=(temp>>8);
*Flash_ptr++ = temp2; // Write value to flash
*Flash_ptr++ = temp3; // Write value to flash
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
}
void read_flash (void)
{
unsigned int temp1,temp2;
char *Flash_ptrA; // Segment A pointer
unsigned int i;
Flash_ptrA = (char *) 0x1000; // Initialize Flash segment A pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<10; i++)
{ temp1= *Flash_ptrA++; // copy value segment A to segment B
temp2= *Flash_ptrA++; // copy value segment A to segment B
flash_data_buff[i] = (temp2+(temp1<<8));
clr_wdt();
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
}
void KL_ZB (void)
{
if((S331_341)&&(ZB_state!=0)) //三相四线
{ if((KL_ZBstate1A==0)&&(CT_current_A>1500)&&(CT_current_B>1500)&&(CT_current_C>1500))
{
if(((CT_current_B-1000)<CT_current_A)&&((CT_current_B+1000)>CT_current_A)&&((CT_current_C-1000)<CT_current_A)&&((CT_current_C+1000)>CT_current_A))
{KL_ZBstate1A=1;ZB_Count=0;KL_ZBBB=1;}
}
if((KL_ZBstate1A)&&(KL_ZBstate05A==0))
{
if((5200>CT_current_A)&&(CT_current_A>4800)&&(5200>CT_current_B)&&(CT_current_B>4800)&&(5200>CT_current_C)&&(CT_current_C>4800)&&(500<ZB_Count)&&(ZB_Count<800))
{KL_ZBstate05A=1;ZB_Count=0;KL_ZBBB=2;}
}
if((KL_ZBstate05A)&&(KL_ZBstate0A==0))
{
if((CT_current_A<200)&&(CT_current_B<200)&&(CT_current_C<200)&&(ZB_Count<500))
{KL_ZBstate0A=1;ZB_Count=0;KL_ZBBB=3;}
}
if((KL_ZBstate0A)&&(200<ZB_Count)&&(KL_ZBstart==1))//现象出现200秒后输出
{two_CT_state=0x07;KL_ZBstart=0;KL_ZBBB=4;}
if((KL_ZBstart==0)&&((((CT_current_A>49000)&&(CT_current_B>49000)&&(CT_current_C>49000))&&(ZB_Count>700))||(ZB_Count>2200)))
{KL_ZBstate5A=1;ZB_Count=0;KL_ZBBB=5;}
if((KL_ZBstate5A)&&(ZB_Count>300))//现象出现200秒后输出
{two_CT_state=0;KL_ZBBB=6;}
if(ZB_Count>4000)
{KL_ZBstate1A=0;KL_ZBstate05A=0;KL_ZBstate0A=0;ZB_Count=0;KL_ZBBB=0;KL_ZBstart=1;}
}
}
/*
void KL_ZB (void)
{
if((S331_341==0)&&(ZB_state!=0))//三相三线
{ if(KL_ZBstate1A==0)
{
if(((CT_current_C-1000)<CT_current_A)&&((CT_current_C+1000)>CT_current_A))
{KL_ZBstate1A=1;ZB_Count=0;}
}
if((KL_ZBstate1A)&&(KL_ZBstate05A==0))
{
if((3300>CT_current_A)&&(CT_current_A>2900)&&(3300>CT_current_B)&&(CT_current_B>2900)&&(3300>CT_current_C)&&(CT_current_C>2900)&&(450<ZB_Count)&&(ZB_Count<800))
{KL_ZBstate05A=1;ZB_Count=0;}
}
if((KL_ZBstate05A)&&(KL_ZBstate0A==0))
{
if((CT_current_A<200)&&(CT_current_B<200)&&(CT_current_C<200)&&(ZB_Count<500))
{KL_ZBstate0A=1;ZB_Count=0;}
}
if((KL_ZBstate0A)&&(200<ZB_Count)&&(KL_ZBstart==1))//现象出现200秒后输出
{two_CT_state=0x05;KL_ZBstart=0;}
if((KL_ZBstart==0)&&((((CT_current_A>49000)&&(CT_current_B>49000)&&(CT_current_C>49000))&&(ZB_Count>700))||(ZB_Count>2200)))
{KL_ZBstate5A=1;ZB_Count=0;}
if((KL_ZBstate5A)&&(ZB_Count>200))
{two_CT_state=0;}
if(ZB_Count>3000)
{KL_ZBstate1A=0;KL_ZBstate05A=0;KL_ZBstate0A=0;ZB_Count=0;}
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -