اطلاعیه

Collapse
No announcement yet.

سوال در مورد watchdag timer در avr

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    سوال در مورد watchdag timer در avr

    سلام دوستان،واچ داگ تایمر رو فعال کردم در پروژم،در شبیه ساز اجرا میکنم اجرا میشه ولی در عمل میکرو رو هی ریست میکنه،مشکل از چی میتونه باشه؟

    #2
    پاسخ : سوال در مورد watchdag timer در avr

    واچ داگ رو درون برنامه ریست میکنی!؟

    دیدگاه


      #3
      پاسخ : سوال در مورد watchdag timer در avr

      نوشته اصلی توسط mojalan نمایش پست ها
      واچ داگ رو درون برنامه ریست میکنی!؟
      بله،در یه تایمر دارم،داخل اون ریست میکنم،داخل while هم گذاشتم بازم ریست میشد،در شبیه ساز درست کار میکنه

      دیدگاه


        #4
        پاسخ : سوال در مورد watchdag timer در avr

        این تایمر نگهبان رو که برمیدارم،میکرو دیگه هیچ کاری نمیکنه،ولی این کدی که نوشتم رو در شبیه ساز بدون هیچ ریستی انجام میشه،مشکل از چی میتونه باشه؟

        دیدگاه


          #5
          پاسخ : سوال در مورد watchdag timer در avr

          [FONT=Yekan]/*[/FONT] * dht11.c
          *
          * Created: 5/10/2018 9:37:21 AM
          * Author : Mgh
          */
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=ifndef]#ifndef[/URL] F_CPU
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] F_CPU 1000000UL
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=endif]#endif[/URL]


          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <avr/io.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <stdlib.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <stdio.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <util/delay.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <avr/interrupt.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <avr/sleep.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] "LCD_16x2_H_file.h"
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] "DHT.h"


          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] SLEEP_MODE_IDLE 0


          double hum,temp;
          char buffer[17];
          double arr_ave_h[10]={ 0 },arr_ave_t[10]={ 0 };
          volatile int count = 0,sec = 0,min = 0,hour = 0,day = 0,i=0,Rotate_flag=0,display_flag=0;
          char str[10];
          double humidity,Temperature;


          /*
          PORTA:
          lcd setting
          PORTD:
          0=>turn on Heater
          1=>turn on Fan
          2=>Rotation interrupt
          3=>display on - start duration interrupt
          4=>Rotation
          5=>sensor dht11
          */
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] EMPTY 0
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] HALF 1
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] FULL 2
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] FAN 3
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] HEATER 4
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] ERROR 5


          void WDT_ON()
          {
          /*
          Watchdog timer enables with typical timeout period 2.1
          second.
          */
          WDTCR = ( 1<<WDE)|( 1<<WDP2)|( 1<<WDP1)|(1<<WDP0);
          }
          void WDT_OFF()
          {
          /*
          This function use for disable the watchdog timer.
          */
          WDTCR = ( 1<<WDTOE)|( 1<<WDE);
          WDTCR = 0x00;
          }


          ISR(TIMER1_COMPA_vect)
          {
          WDT_OFF();
          count++;
          if (count >= 10)
          {
          sec++;
          count = 0;
          if (sec >= 60)
          {
          min++;
          PORTD |= (1 << 4);
          sec = 0;
          if (min >= 60)
          {
          hour++;

          min = 0;
          if (hour >= 24)
          {
          day++;
          hour = 0;
          }
          }
          }
          }
          }


          ISR(TIMER2_COMP_vect)
          {
          sprintf(buffer,"T=%0.1fC H=%0.1f%%",avreage(arr_ave_t),avreage(arr_ave_h));
          sprintf(str,"%02d:%02d:%02d:%02d",day,hour,min,sec);
          LCD_String_xy(0,0,buffer);
          LCD_String_xy(1,0,str);

          if (day <= 18)
          {
          humidity = 60;
          Temperature = 37.7;
          }
          else
          {
          humidity = 73;
          Temperature = 37.3;
          }


          //if (avreage(arr_ave_h) < humidity-5)
          //{
          //PORTD |= (1 << 0) | (1 << 1);
          //LCD_GotoXY(1,14);
          //LCD_Char(FAN);
          //LCD_GotoXY(1,15);
          //LCD_Char(HEATER);
          //}
          //else if(avreage(arr_ave_h) < humidity+5)
          //{
          //PORTD &= ~(1 << 0) & ~(1 << 1);
          //}


          }


          ISR(INT0_vect)
          {


          PORTD &= ~(1 << 4);


          }


          ISR(INT1_vect)
          {


          PORTD |= (1 << 4);


          }




          int main(void)
          {


          LCD_Init();
          lcd_built();
          DHT_Setup();


          WDT_ON();


          DDRD = 0b00010011;


          timer2_init();
          timer1_init();


          int0_init();
          int1_init();

          sei();


          set_sleep_mode(SLEEP_MODE_IDLE);
          sleep_mode();

          while(1)
          {


          DHT_Read(&temp,&hum);
          arr_ave_t[i]=temp;
          arr_ave_h[i]=hum;
          i++;
          if(i == 10){
          i=0;
          }
          _delay_ms(1000);

          }
          }


          void timer1_init()
          {
          TCCR1B |= (1 << WGM12) | (1 << CS11);
          OCR1A = 12499;
          TIMSK |= (1 << OCIE1A);
          }


          void timer2_init()
          {
          TCCR2 |= (1 << WGM21) | (1 << CS20) | (1 << CS22);
          OCR2 = 0x60;
          TIFR |= (1 << OCF2);
          TIMSK |= (1 << OCIE2);
          TCNT2 = 0;
          }


          void int0_init()
          {
          GICR |= 1<<INT0;
          MCUCR |= 1<<ISC01;
          }


          void int1_init()
          {
          GICR |= 1<<INT1 ;
          MCUCR |= 1<<ISC11;
          }


          void lcd_built(void)
          {
          unsigned char empty[ 8] = { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,0x1F, 0x1F };
          unsigned char half[ 8] = { 0x11, 0x11, 0x11, 0x1F, 0x1F, 0x1F,0x1F, 0x1F };
          unsigned char full[ 8] = { 0x11, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,0x1F, 0x1F };
          unsigned char fan[ 8] = { 0x0C,0x05,0x1F,0x14,0x06, 0x00,0x00, 0x00 };
          unsigned char heater[ 8] = { 0x00,0x0A,0x14,0x0A,0x1F,0x1F,0x00,0x00 };
          unsigned char error[ 8] = { 0x0F,0x08,0x0F,0x08,0x0F,0x00,0x00,0x00 };


          LCD_Custom_Char( EMPTY, empty);
          LCD_Custom_Char( HALF, half);
          LCD_Custom_Char( FULL, full);
          LCD_Custom_Char( FAN, fan);
          LCD_Custom_Char( HEATER, heater);
          LCD_Custom_Char( ERROR, error);
          }



          این کدم،کسی نیس کمکم کنه؟

          دیدگاه

          لطفا صبر کنید...
          X