اطلاعیه

Collapse
No announcement yet.

یک سئوال

Collapse
این موضوع بسته شده است.
X
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    یک سئوال

    سلام
    من یک کد برای کنترل یک ترموستات با میکرو دارم که میتونه تو هر 450ثانیه دو تا کلید رو بزنه -مربوط به دکمه set ,و down ترموستات-
    من میخوام تو همون زمان بجای یک مرتبه دومرتبه کلیدِdown مورد نظر رو بزنه
    کدوم قسمت کد رو باید تغییر بدم؟
    کد:
    /*****************************************************
    This program was produced by the
    CodeWizardAVR V2.04.4a Advanced
    Automatic Program Generator
    © Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
    http://www.hpinfotech.com
    
    Project : 
    Version : 
    Date  : 2010/11/23
    Author : NeVaDa
    Company : Warner Brothers Movie World
    Comments: 
    
    
    Chip type        : ATmega16
    Program type      : Application
    AVR Core Clock frequency: 16.000000 MHz
    Memory model      : Small
    External RAM size    : 0
    Data Stack size     : 256
    *****************************************************/
    #include <mega16.h>
    #include <delay.h>
    //
    unsigned char i,flag=0;
    // Timer 0 output compare interrupt service routine
    interrupt [TIM0_COMP] void timer0_comp_isr(void)
    {
    // Place your code here
    
    }
    
    // Timer1 output compare A interrupt service routine
    interrupt [TIM1_COMPA] void timer1_compa_isr(void)
    {
    // Place your code here
    static unsigned int cnt;
      //cnt=0;
      PORTA.0=~PORTA.0;
      if (++cnt == 450)        // 450 sec
      {
        cnt=0;
        PORTA.1=~PORTA.1;        
        flag=1;
      }
    }
    
    // Declare your global variables here
    
    void main(void)
    {
    // Declare your local variables here
    
    // Input/Output Ports initialization
    // Port A initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTA=0xFF;
    DDRA=0xFF;
    
    // Port B initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTB=0x00;
    DDRB=0x00;
    
    // Port C initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTC=0x00;
    DDRC=0x81;
    
    // Port D initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTD=0x00;
    DDRD=0x00;
    
    // Timer/Counter 0 initialization
    // Clock source: System Clock
    // Clock value: 250.000 kHz
    // Mode: CTC top=OCR0
    // OC0 output: Disconnected
    TCCR0=0x0B;
    TCNT0=0x00;
    OCR0=0xFA;
    
    // Timer/Counter 1 initialization
    // Clock source: System Clock
    // Clock value: 15.625 kHz
    // Mode: CTC top=ICR1
    // OC1A output: Discon.
    // OC1B output: Discon.
    // Noise Canceler: Off
    // Input Capture on Falling Edge
    // Timer1 Overflow Interrupt: Off
    // Input Capture Interrupt: Off
    // Compare A Match Interrupt: On
    // Compare B Match Interrupt: Off
    TCCR1A=0x00;
    TCCR1B=0x1D;
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x3d;
    ICR1L=0x09;
    OCR1AH=0x00;
    OCR1AL=0x34;
    OCR1BH=0x00;
    OCR1BL=0x00;
    
    // Timer/Counter 2 initialization
    // Clock source: System Clock
    // Clock value: Timer2 Stopped
    // Mode: Normal top=FFh
    // OC2 output: Disconnected
    ASSR=0x00;
    TCCR2=0x00;
    TCNT2=0x00;
    OCR2=0x00;
    
    // External Interrupt(s) initialization
    // INT0: Off
    // INT1: Off
    // INT2: Off
    MCUCR=0x00;
    MCUCSR=0x00;
    
    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=0x12;
    
    // Analog Comparator initialization
    // Analog Comparator: Off
    // Analog Comparator Input Capture by Timer/Counter 1: Off
    ACSR=0x80;
    SFIOR=0x00;
    
    // Global enable interrupts
    #asm("sei")
    
    while (1)
       {
       // Place your code here
         if(flag == 1)
         {
          flag=0;
          for (i=0;i<5;i++)
          {
           PORTC.0=1;
           PORTA.7=0;
           delay_ms(300);
           PORTC.0=0;       
           PORTA.7=1;
           delay_ms(300);        
          }
          delay_ms(2000);
          //____________________
         PORTC.7=1;
         PORTA.5=0;
         delay_ms(250);
         PORTC.7=0;
         PORTA.5=1;
         //delay_ms(2000);      
    
         }   
       };
    }
لطفا صبر کنید...
X