⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrflash.c

📁 采用430单片机完成的门禁控制器程序
💻 C
字号:
//------------------------------------------------------------------------------
//写flasha程序
//------------------------------------------------------------------------------
void flashwrite()
{
  if(FLAG1 & gb_flashw)
  {
    FLAG1 &=~gb_flashw;
    uchar i;
    uchar j;
    uchar flash[120];
    uchar  *Flash_ptr;
    j = 0;
    for(i=0; i<40; i++)
    {
      flash[j++] = holiday[i][0];
      flash[j++] = holiday[i][1];
    }
    flash[80] = (nvip >>8) & 0xff;
    flash[81] = nvip & 0xff;
    flash[82] = (nnom >>8) &0xff ;
    flash[83] = nnom & 0xff;
    flash[84] = (SAVEP >>8) & 0xff;
    flash[85] = SAVEP & 0xff;
    flash[86] = (LOADP >>8) &0xff ;
    flash[87] = LOADP & 0xff;
    flash[88] = MF;
    flash[89] = delay_cnt;
    flash[90]= wait_cnt;
    flash[91]= iren_cnt;
    flash[92]= alarm_cnt;
    flash[93]= restday1;
    flash[94]= restday2;
    flash[95] = (nyvip >>8) & 0xff;
    flash[96] = nyvip & 0xff;
    flash[97] = (nynom >>8) &0xff ;
    flash[98] = nynom & 0xff;
    flash[99] = conone & 0xff;
    flash[100]= (save_cnt >> 8) & 0xff;
    flash[101] = save_cnt & 0xff;
    flash[102] = msg_flag;
    flash[103] = irdly_cnt;
    j = 0;
    for(i=104; i<120; i++)
    {
      flash[i] = ircon[j++];
    }
    _DINT();
    Flash_ptr = (uchar *) 0x1080;              // 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<120; i++)
    {
      *Flash_ptr++ = flash[i];                   // Write value to flash
    }
    
    FCTL1 = FWKEY;                            // Clear WRT bit
    FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
    _EINT();
  }  
}
//------------------------------------------------------------------------------
//读flash程序
//------------------------------------------------------------------------------
void flashread()
{
  if(FLAG1 & gb_flashr)
  {
    FLAG1 &=~gb_flashr;
    uchar i;
    uchar j;
    uint flash[120];
    uchar  *Flash_ptrA;
    Flash_ptrA = (uchar *) 0x1080;             // Initialize Flash segment A pointer
    for(i=0; i<120; i++)
    {
      flash[i] = *Flash_ptrA++;           // Copy value segment A to segment B
    }
    j = 0;
    for(i=0; i<40; i++)
    {
      holiday[i][0] = flash[j++];
      holiday[i][1] = flash[j++];
    }
    nvip  = flash[80] << 8;
    nvip |=flash[81];
    nnom  =flash[82] <<8 ;
    nnom |=flash[83];
    SAVEP =flash[84] << 8;
    SAVEP |=flash[85];
    LOADP =flash[86] << 8;
    LOADP |=flash[87];
    MF  = flash[88];
    delay_cnt = flash[89];
    wait_cnt = flash[90];
    iren_cnt = flash[91];
    alarm_cnt= flash[92];
    restday1= flash[93];
    restday2= flash[94];
    nyvip   = flash[95] << 8;
    nyvip  |=flash[96];
    nynom   =flash[97] <<8 ;
    nynom  |=flash[98];
    conone  = flash[99];
    save_cnt =  flash[100] << 8;
    save_cnt |= flash[101];
    msg_flag = flash[102];
    irdly_cnt = flash[103];
    j = 0;
    for(i=104; i<120; i++)
    {
      ircon[j++] = flash[i];
    }
    if(nvip == 0xffff)
    {
      nvip =0;
      FLAG1 |=gb_flashw;
    }
    if(nnom == 0xffff)
    {
      nnom =0;
      FLAG1 |=gb_flashw;
    }
    if(nyvip == 0xffff)
    {
      nyvip =0;
      FLAG1 |=gb_flashw;
    }
    if(nynom == 0xffff)
    {
      nynom =0;
      FLAG1 |=gb_flashw;
    }
    if(SAVEP == 0xffff)
    {
      SAVEP = 0;
      FLAG1 |=gb_flashw;
    }
    if(LOADP == 0xffff)
    {
      LOADP = 0;
      FLAG1 |=gb_flashw;
    }
    if(MF == 0xff)
    {
      MF = 0;
      FLAG1 |=gb_flashw;
    }
    if(delay_cnt==0xff)
    {
      delay_cnt = 50;
      FLAG1 |=gb_flashw;
    }
    if(conone == 0xff)
    {
      conone = 32;
      FLAG1 |=gb_flashw;
    }
    if(conone & BIT3)
    {
      door_close = 0x00;
    }    
    else
    {
      door_close = 0x20;
    }
    if(conone & BIT2)
    {
      ir_close = 0x00;
    }    
    else
    {
      ir_close = 0x10;
    }
    if(save_cnt == 0xffff)
    {
      save_cnt = 0;
      FLAG1 |=gb_flashw;
    }
    if(msg_flag == 0xff)
    {
      msg_flag = 0;
      FLAG1 |=gb_flashw;
    }
  }  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -