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

📄 s3f9454.c

📁 三星单片机EEPROM驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
        SEG_A = 0xff;
        SEG_B = 0xff;
        SEG_C = 0xff;
        SEG_D = 0x3;
        goto  cvt_back;
    }
    DigitConvert();
cvt_back:
    ei;
    return;
}
//*************************************************************************
//错误显示代码转换子过程
void  ErrCodeConvert()
{
    DIGITA = 0xa;
    DIGITB = 0xb;
    DIGITC = ERRFLAG;
    DIGITD = 0xa;
    DigitConvert();
}
//*************************************************************************
//数码管显示转换子过程
void  DigitConvert()
{
    Clr_WatchDog;
    SEG_A = DigitCode[DIGITA];
    SEG_B = DigitCode[DIGITB];
    SEG_C = DigitCode[DIGITC];
    SEG_D = DigitCode[DIGITD];
    return;
}
//*************************************************************************
//自动泡茶控制子过程
void  AutoTea()
{
    if  ((Test_NoFz) || (!Test_OneSedA))
        goto  tea_back;
    Clr_OneSedA;
    if  (FUNC_LOOP & 0x1)
        goto  tea_start;
    if  (FUNC_LOOP & 0x2)
        goto  tea_second;
    if  (FUNC_LOOP & 0x4)
        goto  tea_third;
    if  (FUNC_LOOP == FUNC_OK)
        goto  tea_ok;
    goto  tea_back;
tea_start:
    FUNC_LOOP = 0x1;
    Set_FansPfd;
    Clr_ImMode;
    Set_NoFz;
    Clr_NoAd;
    FIRE_SELE = 0x2;
    DELAY_HOTA = 0;
    DELAY_HOTB = 0;
    DELAY_HOTC = 0;
    FUNC_LOOP <<= 1;
tea_second:
    //首先予加热1M    
    if  (DELAY_HOTC <= 0x3c)
    {
      DELAY_HOTC++;
      if  (DELAY_HOTC < 0x3c)
          goto  tea_back;
      if  ((!Test_HandStart)&&(HSRAD_DT < 0x8a))
          goto  hot_stop;
      goto  tea_back;
    }
    if  (HSRAD_DT >= 0x80)
    {
      //予加热6.5M
      DELAY_HOTA++;
      if  (DELAY_HOTA < 0xa)
          goto  tea_back;
      DELAY_HOTA = 0;
      DELAY_HOTB++;
      if  (DELAY_HOTB < 0x27)
          goto  tea_back;
    }
    DELAY_HOTA = 0x78;
    FUNC_LOOP <<= 1;
    
tea_third:
    //延时90S
    FIRE_SELE = 0x3;
    if  ((DELAY_HOTA--)&&(HSRAD_DT > 0x66))
        goto  tea_back;
hot_stop:
    Clr_HandStart;
    PWMDATA = 0;
    Clr_ImMode;
    Set_NoAd;
    Beep(0xf);
    FIRE_SELE = 0x4;
    FUNC_LOOP = FUNC_OK;
tea_ok:
    Com_AutoLed;
    if  (HSRAD_DT >= 0xa0)
    {
      FUNC_LOOP = 0x1;
      goto  tea_start; 
    }       
tea_back:
    ei;
    return;
}
//*************************************************************************
//按键扫描处理子过程
void  KeyScan()
{
    uchar key1,key2,key3;
    ///////////////
    di;
    Clr_WatchDog;
    key1 = KeyTest();
    Delay(2);
    key2 = KeyTest();
    if  (key1 != key2)
        goto  key_back;
    Delay(2);
    key3 = KeyTest();
    if  (key3 != key2)
        goto  key_back;
    if  (key3 == 0xff)
    {
        Clr_KeyDown;
        goto  key_back;
    }
    if  (Test_KeyDown)
        goto  key_back;
    Set_KeyDown;
    if  ((!Test_OnOff) && (key3 == OFF_KEY))
        goto  key_back;
    switch(key3)
    {
      case  FAST_KEY:
        goto  fast_key_set;
      case  AUTO_KEY:
        goto  auto_key_set;
      case  HAND_KEY:
        goto  hand_key_set;
      case  OFF_KEY:
        goto  off_key_set; 
      default:
        break;
    }
off_key_set:
    Clr_OnOff;
    ERRFLAG = 0;
    goto  key_back;
hand_key_set:
    if  (!Test_FastMode)
    {
      if  (KEY_CODE == HAND_KEY)
          goto  key_back;
      FUNC_LOOP = 0x1;
    }
    KEY_CODE = HAND_KEY;
    Set_HandLed;
    Clr_AutoLed;
    Clr_FastMode;
    Clr_FastLed;
    Set_OnOff;
    goto  key_press_back;
auto_key_set:
    if  (!Test_FastMode)
    {
      if  (FUNC_LOOP == FUNC_OK)
          KEY_CODE = 0;
      if  (KEY_CODE == AUTO_KEY)
          goto  key_back;
    }
    KEY_CODE = AUTO_KEY;
    FUNC_LOOP = 0x1;
    Set_HandStart;
    Clr_HandLed;
    Set_AutoLed;
    Clr_FastMode;
    Clr_FastLed;
    Set_OnOff;
    goto  key_press_back;  
fast_key_set:
    if  (!Test_OnOff)
    {
      Set_OnOff;
      KEY_CODE = AUTO_KEY;
      Set_AutoLed;
    }   
    TMR_FAST = 0;
    Com_FastLed;
    Com_FastMode;  
key_press_back:
    Beep(4);
    Set_NoFz;
    Clr_NoAd;
    Set_OnOff;
    DELAY_2H = 0;
    DELAY_3S = 0xf0;
    FUNC_LOOP = 0x1;
    FIRE_SELE = 0x2;
    Set_FansPfd;
key_back:
    ei;
    return;     
}
//*************************************************************************
//按键测试子过程(A/D转换方式进行)
uchar KeyTest()
{
    uchar times = 0x5;
    uchar high  = 0xff;
    di;
    while(times)
    {
      ADCON = 0x87;        //select P0.0 is as AD convert,input clock=Fosc/1     
      while(!Test_ADOK);
      if  (ADDATAH < high)
          high = ADDATAH;
      times--;
    }
    if  (high > 0xf5)
        return  NO_KEY;
    if  (high < 0x19)
        return  FAST_KEY;
    if  (high < 0x66)
        return  AUTO_KEY;
    if  (high < 0x85)
        return  HAND_KEY;
    if  (high < 0xb3)
        return  OFF_KEY;
    return  NO_KEY;
}
//*************************************************************************
//加锅检测子过程
void  FzCheck()
{
    uchar times;
    ////////////////
    Clr_WatchDog;
    if  (Test_NoAd)
        goto  fz_back;
    di;
    if  (!Test_NoFz)
        goto fz_test;
    Delay(10);
    DELAY_3S++;
    if  (DELAY_3S < 0x60)
        goto  fz_back;
    DELAY_3S = 0;
    PWMDATA = 0xa0;
    Delay(200);
    times = 0;
fz_test:
    while(times < 0x1)
    {
      Current_Check();
      if  (!Test_NoFz)
          break;
      times++;
    }  
    if  (Test_NoFz)
        goto  no_fz;
    ERRFLAG = 0;
    DELAY_2M = 0;
    goto fz_back;
no_fz:
    PWMDATA = 0;
    if  (DELAY_2M > 0x3c)
    {
      Clr_OnOff;
      goto  fz_back;
    } 
    DELAY_2M++;
    Beep(4);
fz_back:
    return;
}
//*************************************************************************
//加锅运行电流检查子过程
void  Current_Check()
{
    uchar times = 0x50;
    CURAD_DT = 0x33;
    while(times)
    {
      times--;
      di;
      Clr_WatchDog;
      ADCON = 0x73;
      while(!Test_ADOK);
      if  (ADDATAH < CURAD_DT)
          CURAD_DT = ADDATAH;
      ei;
    }
    Clr_NoFz;
    if  (CURAD_DT >= 0xe)
        Set_NoFz;
    return;
}
//*************************************************************************
//***延时子过程***//
//***以MS为单位,fosc=3.2MHZ,nop_cycle=1.25us
void  Delay(unsigned int time)
{
    uchar a,temp_sym;
    
    /////////////
    temp_sym = SYM;
    ei;
    while(time>0)
    {
      a = 123;
      Clr_WatchDog;
      while(a>0)
      {
        nop;
        nop;
        nop;
        nop;
        a--;
      }
      time--;
    }
    SYM = temp_sym;
}
//******************************************************************
//蜂鸣器驱动子过程,time为要鸣响的时间值以25MS为单位
void  Beep(uchar time)
{
    uchar timer;
       
    asm("push T0DATA");
    asm("push T0CON");
    asm("push P2");
    asm("push P2CONL");
    
    LedScan();
    P2CONL = P2CONL | 0x3;
    T0CON = 0x88;
    T0DATA = 0x32;
    BTCON = 0xa3;
    
    di;
    while(time>0)
    {    
      timer = 0;
      while(timer<0xa)        //每个计时周期为25MS
      {
        Clr_WatchDog;
        while(BTCNT<0x2);     //每上BT周期为2.56MS
        Clr_WatchDog;
        LedScan();
        timer++;
      }
      time--;
    }
    ei;
    Clr_WatchDog;
    asm("pop P2CONL");    
    asm("pop P2");
    asm("pop T0CON");
    asm("pop T0DATA");
    return;
}
//*************************************************************************
//电源电压检测子过程
void  PvCheck()
{
    uchar times,count,high,low;
    times = 5;
    high = 0x62;
    low = 0x46;
    if  (!Test_PvWait)
    {
      high = 0x6d;
      low = 0x3d;
    }
    while(times)
    {
      times--;
      PVAD_DT = 0;
      count = 0xa0;
      Clr_WatchDog;
      while(count)
      {
        di;
        ADCON = 0x55;
        while(!Test_ADOK);
        if  (ADDATAH > PVAD_DT)
            PVAD_DT = ADDATAH;
        ei;    
        count --;
      }
      if  (PVAD_DT > high)
      {
        ERRFLAG = ERC_PVH;
        continue;
      }
      if  (PVAD_DT < low)
      {
        ERRFLAG = ERC_PVL;
        continue;
      }
      ERRFLAG = 0;
      break;
    }
    return;
}
//*************************************************************************
//IGBT温度检测子过程
void  IgbtCheck()
{
    uchar times;
    times = 0;
    while(times<=0xa)
    {
      times++;
      di;
      ADCON = 0x43;           //select P0.4 as A/D,AD_CLK=Fosc/8
      Clr_WatchDog;
      while(!Test_ADOK);
      ei;
      ERRFLAG = ERC_IGBT_OPEN;
      if  ((ADDATAH != 0)&&(ADDATAH <= 0x80))
      {
          ERRFLAG = 0;
          break;
      }
    }
    IGBTAD_DT = ADDATAH;
    return;
}
//*************************************************************************
//热敏电阻检测子过程
void  HsrCheck()
{
    uchar times;
    times = 0;
    HSRAD_DT = 0;
    while(times<=0x5)
    {
      times++;
      di;
      Clr_WatchDog;
      ADCON = 0x31;           //select P0.3 as A/D,CLK=Fosc/16
      while(!Test_ADOK);
      ei;
      if  (ADDATAH < HSRAD_DT)
          continue;
      HSRAD_DT = ADDATAH;
    }
    if  (HSRAD_DT > 0xfd)
    {
        ERRFLAG = ERC_HSR_OPEN;
        goto hsr_exit;
    }
    if  (HSRAD_DT < 0x33)
    {
        ERRFLAG = ERC_HSR_HOT;
        goto hsr_exit;
    }
hsr_exit:    
    ei;
    return;
}
//*************************************************************************
//18V电源电压状态检查子过程
void  V18Check()
{
  uchar times;
  times = 0xa;
  while(times)
  {
    times--;
    di;
    ADCON = 0x23;       //select P0.2 as A/D,clk=Fosc/8
    while(!Test_ADOK);
    ERRFLAG = ERC_PVL;
    if  (ADDATAH < 0x26)
        continue;
    if  (ADDATAH > 0x3a)
        continue;
    ERRFLAG = 0;
    break;
  }
  ei;
  return;
}
//*************************************************************************
//LED扫描子过程
void  LedScan()
{
    //首先必须关闭所有LED显示
    Clr_LedACtrl;
    Set_LedBCtrl;
    Set_LedCCtrl;
    Set_LedDCtrl;
     
    LED_LOOP = LED_LOOP << 1;
    if  (LED_LOOP == 0x1)
        goto  scan_leda;
    if  (LED_LOOP == 0x2)
        goto  scan_ledb;
    if  (LED_LOOP == 0x4)
        goto  scan_ledc;
    if  (LED_LOOP == 0x8)
        goto  scan_ledd;
    LED_LOOP = 0x1;
scan_leda:  
    SendTo164(SEG_A);
    Set_LedACtrl;
    goto  scan_back;
scan_ledb:  
    SendTo164(SEG_B);
    Clr_LedBCtrl;
    goto  scan_back;
scan_ledc:  
    SendTo164(SEG_C);
    Clr_LedCCtrl;
    goto  scan_back;
scan_ledd:  
    SendTo164(SEG_D);
    Clr_LedDCtrl;
    
scan_back:
    return;
}
//*************************************************************************
//74HC164的数据刷亲子过程
void  SendTo164(uchar seg)
{
    uchar count;
    count = 0x8;
    Clr_164sdt;
    Clr_164sck;
    //seg = 0xc0;
    while(count)
    {
      if  (seg & 0x1)
        Set_164sdt;
      else
        Clr_164sdt;
      Set_164sck;
      nop;
      nop;
      nop;
      Clr_164sck;
      seg = seg >> 0x1;
      count--;
    }
    return;
}
//*************************************************************************
//**中断向量及服务程序定义********
#pragma vector=0x00
__interrupt void int_9454()
{
  T0CON = T0CON & 0xfe;     //必须清T0中断标志
  Clr_WatchDog;
  
  LedScan();
  
  TMR_1SH++;
  if  (TMR_1SH < 0xfa)
      return;
  TMR_1SH = 0;
  Set_OneSedA;
  Set_OneSedB;
  Set_OneSedC;
  Set_OneSedD;
  TMR_FAST++;
  SECOND++;
  if  (SECOND < 0x3c)
      return;
  SECOND = 0;
  DELAY_2H++;
}
//*************************************************************************




⌨️ 快捷键说明

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