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

📄 lc_meter.c

📁 电感表的程序和电路原理图。 ATmega8单片机。
💻 C
📖 第 1 页 / 共 2 页
字号:
     LCD_put_c(' ');
     LCD_put_c('u');
    }
else
    {
     if(lx<150000)
       {
        ftoa(lx/1000.0,3,str);
        LCD_put_str2(3,1,str); 
        LCD_put_c(' ');
        LCD_put_c('m');
       }
     else
       {
        LCD_put_c(' ');
        LCD_put_c(1);
        LCD_put_c(' ');
       }
   }    
LCD_put_c('H');
}

void disp_alarm_vol(void)
{
 ftoa(alarm[tempture_mode]/10.0,1,str);
 LCD_put_str2(9,1,str);
 LCD_put_c(0);
 LCD_put_c(' '); 
 LCD_put_c(' ');
 LCD_put_c(' ');
}

// Pin change 16-23 interrupt service routine
interrupt [PCINT2] void pin_change_isr2(void)
{
if(B3==0)
   {
    delay_ms(50);
    if(B3==0)
       {
        delay_ms(50);
        switch(mode)
           {
            case 0:
                {
                 time0_expend=trig_time-1;
                 mode=1;
                }break;
            case 1:
                { 
                 time0_expend=trig_time-1;
                 mode=0; 
                }break; 
            case 4:
                { 
                if(mode_using==0)
                   {
                    TCCR1B=0;
                    mode_using=1;
                   // LCD_put_str(10,0,"Paused");
                   } 
                else
                   {
                    TCCR1B=0x07;
                   // LCD_put_str(10,0,"      ");
                    mode_using=0; 
                   }   
                }break; 
            case 5:
                {
                 if(tempture_mode==ds18B20_devices*2)
                     mode=0;
                 
                 else
                     {
                      alarm[tempture_mode]-=1;;
                      delay_ms(300);  
                       while(B3==0)
                              {
                               delay_ms(100);
                               alarm[tempture_mode]-=1;
                               disp_alarm_vol();
                              }
                     }    
                }break;
            default:
                {
                 mode=0;
                }    
                       
           
           }
       }
   }    
}

// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
char i;
if(B1==0)
   {
    delay_ms(50);
    if(B1==0)
       {
        delay_ms(50);
        if(B1==0)
           {
            switch(mode)
               {
                case 0:
                     {
                      save_stray=1;
                     }break;
                case 1:
                     {
                      save_stray=1;
                     }break;
                case 2:
                     {
                      if(mode_using==0)
                          mode_using=1;
                      else
                          mode_using=0;    
                     }break;    
                case 3:
                     {
                      switch (mode_using)
                         {
                          case 0:
                              {
                               mode_using=1;
                              }break;
                          case 1:
                              {
                               mode_using=2;
                              }break;
                          default :
                               {
                               mode_using=0;
                               }break;            
                         }
                     
                     }break;
                case 4:
                     {
                      
                      TCCR1B=0;
                      count_h=0;
                      TCNT1H=0x00;
                      TCNT1L=0x00;
                      
                      if(mode_using==0)
                          TCCR1B=0x07;
                      zero=1;
                     }break;
                case 5:
                     {
                       
                       if(tempture_mode<(2+2*(ds18B20_devices-1)))
                            {
                             tempture_mode++;
                             if(tempture_mode==(2+2*(ds18B20_devices-1)))
                                {
                                 alarm_t1_max=alarm[0];
                                 alarm_t1_min=alarm[1];
                                 alarm_t2_max=alarm[2];
                                 alarm_t2_min=alarm[3];
                                 for(i=0;i<ds18B20_devices;i++)
                                    ds18b20_init(&rom_codes[i][0],alarm[i*2+1]/10.0,alarm[i*2]/10.0,DS18B20_11BIT_RES);
                                }
                            } 
                       
                       else
                            {
                             tempture_mode=0;
                             
                            }
                        

                                 
                     }break;
                default:break;     
               }
           }
       }
   }    


}

// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
if(B2==0)
   {
    delay_ms(50);
    if(B2==0)
       {
        delay_ms(50);
        if(B2==0)
           {
            switch(mode)
               {
                case 0:
                     {
                      time0_expend=trig_time-1;
                      mode=2;
                      
                     }break;
                case 1:
                     {
                      time0_expend=trig_time-1;
                      mode=2;
                      
                     }break;
                case 2:
                     {
                     time0_expend=trig_time-1;
                     mode=3;
                     //LCD_clear();
                     
                     }break;    
                case 3:
                     {
                      
                      mode=4;
                      count_test();
                     
                     }break;
                case 4:
                     {
                      mode=5;
                      ds18B20_devices=w1_search(0xF0,rom_codes);
                      tempture_mode=ds18B20_devices*2;
                      init_senor=1;
                     }break;
                case 5:
                     {
                      
                      if(tempture_mode==ds18B20_devices*2)
                         {
                          
                          mode=2;
                         }
                      else
                         {
                         alarm[tempture_mode]+=1;
                         delay_ms(300);
                         while(B2==0)
                              {
                               delay_ms(100);
                               alarm[tempture_mode]+=1;
                               disp_alarm_vol();
                              }
                         }
                      }break;
                default:break;     
               }
           }
       }
   }    

}

// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
 SET_T0_TIME;
 time0_expend++;
 if( time0_expend==trig_time)
     {
      T1_OFF; //定时器1 计数关闭
      T0_OFF;
      if(t1_over_flower==0)
          {
          if(TCNT1<0xFFFF/11)
             {
              lower_pri=1;
             }
          else
             {
              lower_pri=0;
             }   
          frequnce=(unsigned long)((float)TCNT1*1000/(trig_time*9.9816));
          error_over_flower=0;
          }
      else
          {
           error_over_flower=1;
          }    
     }
  TIFR0|=1;
   
}

interrupt [TIM1_CAPT] void timer1_capt_isr(void)
{
 //unsigned int temp;
 
 if(TCNT1==0)
    TCCR1B=temp_tp;
 else
    {   
     #asm
     LDI     R30,0x00 
     STS     0x0085,R30
     STS     0x0084,R30 
     #endasm
     //TCNT1H=0x00;
     //TCNT1L=0x00;
     if((TCCR1B&0x40)==0)
       {
        TCCR1B=0;
        top_time=ICR1;
        
        TIMSK1=0x00;
        test_complete=1;
        
       }
     else
       {
        TCCR1B=temp_bs;
        base_time=ICR1;
       }
    }
 
}

interrupt [ADC_INT] void adc_isr(void)
{
  unsigned int adc_data;
  ADCSRA&=~(1<<7);
  adc_data=ADCW;
  trig_voltage=4.79*adc_data/1024;
}
// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
  t1_over_flower=1;
  count_h++;
}

void main(void)
{

unsigned char i,j,k;



float tempture=0;
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In 
// State7=T State6=T State5=0 State4=0 State3=0 State2=0 State1=0 State0=P 
PORTB=0x01;
DDRB=0x3E;

// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=Out Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=Out 
// State7=0 State6=P State5=P State4=P State3=P State2=P State1=0 State0=0 
PORTD=0x7C;
DDRD=0x83;

DIDR0=0x00;
ADMUX=0xC6;
ADCSRA=0x0E;

int_inital_on();

LCD_inital();
write_user_capter(0,data);
write_user_capter(1,data1);
#asm("sei")
trig_time=1;
//alarm_t1_max=0;
//alarm_t1_min=0;
//alarm_t2_max=0;
//alarm_t2_min=0;
alarm[0]=alarm_t1_max;
alarm[1]=alarm_t1_min;
alarm[2]=alarm_t2_max;
alarm[3]=alarm_t2_min;
Capture_div=1;
while (1)
      {
        switch(mode)
            {
            case 0:
                 {
                  K2=0;
                  K1=1;
                  if(PIND.4==0)
                       {
                        self_Calibrating();
                       }
                  test_c();
                  delay_ms(200/trig_time);
                 }break; 
            case 1:
                 {
                  K2=0;
                  K1=0;
                  if(PIND.4==0)
                       {
                        K1=1;
                        self_Calibrating();
                       }
                  test_l();
                  delay_ms(200/trig_time);
                 }break;
            case 2:
                 {
                  K2=1;
                  K1=0;
                  frequnce_test();
                  AD_START;
                  if(mode_using==0)
                     disp_fr(); 
                  else
                     disp_cycle();   
                  disp_trig_vol();
                  if(mode==3)
                    {
                     disp_duty();
                    }
                 }break;
            case 3:
                 {
                  K2=1;
                  K1=0;
                  
                  duty_test();
                  
                  AD_START;
                  if(mode==4)
                     {
                      LCD_clear();
                      LCD_put_str(0,0,"Countting:Paused"); 
                      LCD_put_str(0,1,"Count="); 
                      zero=0;
                     }
                 }break;
            case 4:
                 {
                  K2=1;
                  K1=0;
                  if(zero==1)
                     {
                      LCD_put_str(6,1,"          ");
                      zero=0;
                     } 
                  if(mode_using==1)
                   {
                    LCD_put_str(10,0,"Paused");
                   } 
                  else
                   {
                    LCD_put_str(10,0,"      ");
                   }      
                  ftoa((unsigned long)count_h*0xFFFF+TCNT1,0,str);
                  LCD_put_str2(6,1,str);
                  
                 }break;
            case 5:
                 {
                  K2=0;
                  K1=0;
                  if(init_senor==1)
                    {
                     init_senor=0;
                     LCD_clear();
                     LCD_put_str(0,0,"Searching Device");
                     delay_ms(500);
                     ds18B20_devices=w1_search(0xF0,rom_codes);
                     LCD_goto_xy(0,1);
                     LCD_put_c(ds18B20_devices+48);
                     LCD_put_str(1,1," Senses Setted.");
                     delay_ms(500);
                     LCD_clear();
                     LCD_put_str(0,0,"Initaling Device");
                     delay_ms(500);
                     for(i=0;i<ds18B20_devices;i++)
                        {
                         LCD_put_str(0,1,"Sense [");
                         LCD_put_c(i+49);
                         LCD_put_c(']');
                         if (ds18b20_init(&rom_codes[i][0],alarm[i*2+1]/10.0,alarm[i*2]/10.0,DS18B20_11BIT_RES))
                                LCD_put_str(9,1," OK.");
                         else 
                                LCD_put_str(9,1," ERROR."); 
                         delay_ms(200);   
                         LCD_clear();
                        }    
                    }
                 
                  if(tempture_mode==ds18B20_devices*2)
                     { 
                      if(ds18B20_devices==1)
                          LCD_put_str(0,0,"Tempture:[T1]   ");
                      else     
                          LCD_put_str(0,0,"Tempture:[T1/T2]");
                      
                      for(i=0;i<ds18B20_devices;i++)
                         {
                          tempture=ds18b20_temperature(&rom_codes[i][0]);
                          ftoa(tempture,1,str);
                          LCD_put_str2(0+i*9,1,str);
                          LCD_put_c(0); //显示自定义图案
                         }
                      i=w1_search(0xEC,alarm_rom_codes);
                      LCD_goto_xy(15,1);
                      LCD_put_c(' '); 
                      LCD_goto_xy(6,1);
                      LCD_put_c(' '); 
                      while(i>0)
                       {
                        i--;
                        for(k=0;k<MAX_DS1820;k++)
                           {
                             for(j=0;j<9;j++)
                                {
                                 if(alarm_rom_codes[i][j]!=rom_codes[k][j])
                                     {
                                       break;
                                     }
                                 else
                                      if(j==8)
                                          {
                                           LCD_goto_xy(6+k*9,1);
                                           LCD_put_c(1); //显示自定义图案
                                      
                                          } 
                                }
                            }
                       }
                     }
                 else
                     {
                      LCD_put_str(0,0,"Tempture Alram:");
                      if((tempture_mode%2)==0)
                          LCD_put_str(0,1,"[MAX] T");
                      else
                          LCD_put_str(0,1,"[MIN] T");
                      LCD_put_c(tempture_mode/2+49);
                      LCD_put_c('=');
                      disp_alarm_vol();
                      if(tempture_mode==ds18B20_devices*2) 
                          LCD_clear();
                     }       
                 }break;    
            default:break;                         
            }
        
      };
}

⌨️ 快捷键说明

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