اطلاعیه

Collapse
No announcement yet.

چگونه همه پایه های میکروکنترلر AVR را PWM کنیم ؟؟

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

    چگونه همه پایه های میکروکنترلر AVR را PWM کنیم ؟؟

    درود بر دوستان
    امیدوارم حال همتون عالی باشه

    من امروز میخوام PWM نرم افزاری رو به شما معرفی کنم
    چون خیلی از دوستان دیدم که گذرشون به این کارها میخوره
    همون طور که میدونید اکثر میکروهای AVR هشت بیتی PWM سخت افزاری محدودی دارند و اگر بخواهیم که آنها را به کار بگیریم باید از همون پایه ای که مشخص شده PWM بگیریم ...
    بنابراین اگر کسی بخواهد که از پایه های دیگه PWM بگیرد باید به صورت نرم افزاری تعریف کند تا پایه دلخواه را PWM کند ...
    همانطور که می دانید برای هر PWM نیاز به یک تایمر دارد . البته در بعضی از تایمرها هستند که 3تا PWM تولید میکنند . اما در این برنامه ای که میخواهم برای شما معرفی کنم تنها یک تایمر بکار رفته است . تایمر صفر رو انتخاب کردم که امکاتاتش کمه و به کارمون میاد !! دلیل اینکه چرا از تایمر های دیگه استفاده نکردم اینه که گفتم شاید کسی از تایمر های دیگه که خیلی امکاناتش بالاتره بخواهد استفاده کند .
    با استفاده از تایمر 0 میکروهای 128-64-ATmega16-32 این قابلیت را دارند که انجام مقایسه ای مقدار تایمر را انجام دهد(در بعضی از تایمر0 میکرو ها فقط این قابلیت رو دارند که Overflow کنند مثل ATmega8 ) . پس میتوانیم در این تایمر فرکانس را کم و زیاد کنیم . اگر فرکانس را بالا ببریم (مقدار OCR0 را کم کنیم) پردازش زیادتر میشود و دقت پایین می آید و اگر فرکانس رو کم کنیم دقت زیاد میشود . ما در این پروژه نیازی به این دو داریم ولی تا یک حدی !!! این تایمر در مد CTC تنظیم شده است .
    اگر برایتان فرکانس زیاد مهم نیست مقدار OCR0 را زیادتر کنید تا پردازش کمتر شود . دلیل اینکه روی بحث پردازش تاکید میکنم این هست که روی دستورات تاخیری تاثیر میگذارد و این باعث میشود که تاخیرات نرم افزاری دیرتر صورت بگیرد .

    خب بریم سر اصل مطلب
    هدف از این پروژه این بود که یک LED بارانی یا به قول بچه ها شهاب سنگ LED بسازم ولی از اونجایی که صفحه 5 این تاپیک رو نخونده بودم فکر میکردم که کسی برنامش رو نگذاشته .
    این هم بگم که قبلا دو تا تاپیک دیدم که درباره این موضوع بحث شده
    http://www.eca.ir/forum2/index.php?topic=66771.15
    http://www.eca.ir/forum2/index.php?topic=64272.60
    ولی چون کاربرد PWM فقط در LED بارانی نیست من این تاپیک رو باز کردم تا همه استفاده کنند .
    ================================================== ==================
    برنامه ها را در لینکهای تعیین شده "موضوعات بحث شده" بیابید.
    ================================================== ==================
    یک توضیح مختصر در مورد برنامه :
    برنامه طوری طراحی شده که با استفاده از آرایه میتوانیم مقدار تک تک PWM ها را تغییر بدهیم
    آرایه ای که []pwm نام دارد را میتوانید اندیس آن را برای PWM دلخواهتان تنظیم کنید
    بازه مقدار آرایه PWM از 0 تا 99 است که نشانگر دیوتی سایکل است :biggrin:
    این آرایه یه جورایی میشه گفت که مثل رجیستر عمل میکنه . یعنی اینکه تا مقدار به آن بدهیم PWM تنظیم میشود .
    ================================================== ==================
    برنامه ATmega64-128 :
    در این دو میکرو به دلیل اینکه دستور PORTx.y فقط برای پورتهای A,B,C,D کاربرد دارد گفتم چه بهتر که همه رو با استفاده از دستورات کتابخانه ای خود کدویژن به کار بگیرم .
    از لحاظ پردازش هم با این فرکانس و این تقسیم کننده فرکانس در تایمر ، در میکروی اتمگا 16 و 32 تقریبا 15.75% و در میکرو های اتمگا 64 و 128 تقریبا 24.67% پردازش میکرو را میگیرد . (البته این محاسبات در بدترین شرایط در نظر گرفته شده است .)
    اگر بخواهید از تمام PWM های نرم افزاری استفاده نکنید میتوانید یکسری تنظیمات را تغییر دهید ...
    البته که اگر PWM های کمتری را به کار بگیرید پردازش کمتری خواهد گرفت .

    راستی بچه ها من این برنامه رو که براتون گذاشتم 16 تا LED بهش وصل کردم برای تست .
    این هم کلیپ ( 1.5 مگابایت)
    http://s5.picofile.com/file/8115298350/MOV03572.mp4.html
    LED بیشتر هم داشتم ولی سه میلیمتری نبودند
    برنامه ای که درون حلقه While نوشتم اینکار را انجام میدهد
    البته افکتهای بیشتر رو هم میتونستم بگذارم ولی وقت نکردم

    دوستان سوالی بود در خدمتم
    موفق باشید



    موضوعات بحث شده در این تاپیک

    چگونه تمام پایه های میکروکنترلر را PWM کنیم؟؟؟ (با کدویژن)
    چگونه تمام پایه های میکروکنترلر را PWM کنیم؟؟؟ (با بسکام)
    چگونه تمام پایه های میکروکنترلر را PWM کنیم؟؟؟ (با اتمل استودیو)
    کتابخانه IObits برای زبان C
    چگونه با دو ولوم میتوان فرکانس و دیوتی سایکل PWM سخت افزاری را تغییر داد ؟؟
    ساخت LED بارانی
    کنترل سرعت چندین موتور DC به طور همزمان !!! (قابل ارتقاع تا ۵۳ موتور)
    نمونه برنامه ای برای کنترل LED RGB
    چگونه PWM را به ولتاژ DC تبدیل کنیم ؟؟


    ساخت 7 RGB و 22 PWM با ATmega8 و ساخت 10 RGB و 32 PWM با ATmega16,32 (با بسکام)
    ساخت 17 RGB و 53 PWM با میکروهای ATmega64,128
    ساخت 28 RGB و 86 PWM با میکروهای ATmega640,1280,2560

    ساخت 7 RGB و 22 PWM با Mega8 و ساخت 10 RGB و 32 PWM با Mega16,32 (با کدویژن)
    ساخت 17 RGB و 53 PWM با Mega64,128
    ساخت 28 RGB و 86 PWM با Mega640,1280,2560


    ساخت 7 RGB و 22 PWM با Mega8 و ساخت 10 RGB و 32 PWM با Mega16,32 (با اتمل استودیو)
    ساخت 17 RGB و 53 PWM با Mega64,128
    ساخت 28 RGB و 86 PWM با Mega640,1280,2560

    مقایسه سه نرم افزار کدویژن و اتمل استودیو و بسکام
    ساخت 5 PWM با ATtiny13A (با دقت 50 پله و 250 هرتز)(کدویژن)
    ساخت 5 PWM با ATtiny13A (با دقت 50 پله و 250 هرتز)(بسکام)
    چگونه بعضی از پایه های میکروکنترلر AVR را به صورت دلخواه PWM کنیم ؟؟
    توضیح خط به خط و بلوک به بلوک برنامه pwm مربوط به LED بارانی (به همت آقای سید محمد علوی )



    فیلمهای گرفته شده توسط دوستان

    کنترل دور موتور DC به وسیله PWM توسط آقای علی اکبری
    افکتهای طراحی شده توسط آقای کوروش شفیع زاده پارت 1
    افکتهای طراحی شده توسط آقای کوروش شفیع زاده پارت 2
    افکتهای طراحی شده توسط آقای کوروش شفیع زاده پارت 3
    افکتهای طراحی شده توسط آقای کوروش شفیع زاده پارت 4
    افکتهای طراحی شده توسط آقای کوروش شفیع زاده پارت 5
    افکتهای طراحی شده توسط آقای کوروش شفیع زاده پارت 6
    [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
    معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
    معرفی نرم افزار Codewizard PWM
    با من بیشتر آشنا شوید

    #2
    (برنامه اصلاح شد) چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!

    درود بر دوستان
    من دوباره برنامه رو بررسی کردم و برای کاهش پردازش قسمتی از کدها را تغییراتی اعمال کردم
    توضیح خط به خط و بلوک به بلوک برنامه pwm مربوط به LED بارانی (به همت آقای سید محمد علوی )

    سورس کد برای میکروهای ATmega16-32 به زبان C کدویژن
    کد:
    /*****************************************************
    This program was produced by the
    CodeWizardAVR V2.05.3 Standard
    Automatic Program Generator
    © Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
    http://www.hpinfotech.com
    Project : 32-channel PWM (Rain LED)
    Version : 2.1
    Date  : 2/27/2014
    Author : Saman.Asadi
    www.ECA.ir
    Chip type        : ATmega16
    Program type      : Application
    AVR Core Clock frequency: 8.000000 MHz
    Memory model      : Small
    External RAM size    : 0
    Data Stack size     : 256
    *****************************************************/
    #include <mega16a.h>
    #include <delay.h>
    
    #define led1    PORTA.0
    #define led2    PORTA.1
    #define led3    PORTA.2
    #define led4    PORTA.3
    #define led5    PORTA.4
    #define led6    PORTA.5
    #define led7    PORTA.6
    #define led8    PORTA.7
    #define led9    PORTC.7
    #define led10    PORTC.6
    #define led11    PORTC.5
    #define led12    PORTC.4
    #define led13    PORTC.3
    #define led14    PORTC.2
    #define led15    PORTC.1
    #define led16    PORTC.0
    #define led17    PORTD.7
    #define led18    PORTD.6
    #define led19    PORTD.5
    #define led20    PORTD.4
    #define led21    PORTD.3
    #define led22    PORTD.2
    #define led23    PORTD.1
    #define led24    PORTD.0
    #define led25    PORTB.7
    #define led26    PORTB.6
    #define led27    PORTB.5
    #define led28    PORTB.4
    #define led29    PORTB.3
    #define led30    PORTB.2
    #define led31    PORTB.1
    #define led32    PORTB.0
    #define byte    unsigned char
    #define max_var_PWM 99
    #define factor
    byte    a = max_var_PWM;
    byte    pwm[35];
    flash byte rain1[25]={99,70,40,20,10,5,4,3,2,1,0};
    flash byte rain2[40]={0,1,2,3,4,5,10,20,40,70,99,70,40,20,10,5,4,3,2,1,0};
    flash byte rain3[35]={0,1,2,3,4,5,10,20,40,70,99};
    flash byte rain4[40]={1,2,3,4,5,10,20,40,70,99,70,40,20,10,5,4,3,2,1,0};
    
    // Timer 0 output compare interrupt service routine
    interrupt [TIM0_COMP] void timer0_comp_isr(void)
    {  if(a)
      {  if(a == pwm[1] )led1=1;
        if(a == pwm[2] )led2=1;
        if(a == pwm[3] )led3=1;
        if(a == pwm[4] )led4=1;
        if(a == pwm[5] )led5=1;
        if(a == pwm[6] )led6=1;
        if(a == pwm[7] )led7=1;
        if(a == pwm[8] )led8=1;
        if(a == pwm[9] )led9=1;
        if(a == pwm[10])led10=1;
        if(a == pwm[11])led11=1;
        if(a == pwm[12])led12=1;
        if(a == pwm[13])led13=1;
        if(a == pwm[14])led14=1;
        if(a == pwm[15])led15=1;
        if(a == pwm[16])led16=1;
        if(a == pwm[17])led17=1;
        if(a == pwm[18])led18=1;
        if(a == pwm[19])led19=1;
        if(a == pwm[20])led20=1;
        if(a == pwm[21])led21=1;
        if(a == pwm[22])led22=1;
        if(a == pwm[23])led23=1;
        if(a == pwm[24])led24=1;
        if(a == pwm[25])led25=1;
        if(a == pwm[26])led26=1;
        if(a == pwm[27])led27=1;
        if(a == pwm[28])led28=1;
        if(a == pwm[29])led29=1;
        if(a == pwm[30])led30=1;
        if(a == pwm[31])led31=1;
        if(a == pwm[32])led32=1;
      }
      if(--a == 255)
      {  a = max_var_PWM;
        PORTA=0;
        PORTB=0;
        PORTC=0;
        PORTD=0;
      }
    }
    
    void main(void)
    {
      byte x1,x2,x3;
      //Config all
      //Config timers
      //Config PORTS
      {
        DDRA=255;
        DDRB=255;
        DDRC=255;
        DDRD=255;
        // Timer/Counter 0 initialization
        // Clock source: System Clock
        // Clock value: 1000.000 kHz
        // Mode: CTC top=OCR0
        // OC0 output: Disconnected
        TCCR0=0x0A;
        OCR0=150;
        // Timer(s)/Counter(s) Interrupt(s) initialization
        TIMSK=0x02;
        // Global enable interrupts
        #asm("sei")
      }
      //End Config ......
      while(1)
      {
        /////////////////////////////////////////
        for(x1=0;x1<25;x1++)
        {  pwm[1]=rain1[x1];
          for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
          delay_ms(40);
        }
        for(x1=0;x1<35;x1++)
        {  pwm[1]=rain2[x1];
          for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
          delay_ms(40);
        }
        for(x1=0;x1<25;x1++)
        {  pwm[1]=rain3[x1];
          for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
          delay_ms(40);
        }
        /////////////////////////////////////////
        for(x1=0;x1<25;x1++)
        {  pwm[17]=rain1[x1];
          for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
          delay_ms(40);
        }
        for(x1=0;x1<35;x1++)
        {  pwm[17]=rain2[x1];
          for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
          delay_ms(40);
        }
        for(x1=0;x1<25;x1++)
        {  pwm[17]=rain3[x1];
          for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
          delay_ms(40);
        }
        //////////////////////////////////////////
        for(x3=0;x3<3;x3++)
        for(x1=0;x1<14;x1++)
        {  for(x2=0;x2<8;x2++)pwm[x2]=pwm[x2+1];
          for(x2=17;x2>9;x2--)pwm[x2]=pwm[x2-1];
          pwm[8]=rain1[x1];
          pwm[9]=rain1[x1];
          delay_ms(40);
        }
        for(x3=0;x3<3;x3++)
        for(x1=0;x1<14;x1++)
        {  for(x2=8;x2>00;x2--)pwm[x2]=pwm[x2-1];
          for(x2=9;x2<17;x2++)pwm[x2]=pwm[x2+1];
          pwm[0]=rain1[x1];
          pwm[17]=rain1[x1];
          delay_ms(40);
        }
        //////////////////////////////////////////
        for(x3=0;x3<4;x3++)
        for(x1=0;x1<19;x1++)
        {  for(x2=0;x2<8;x2++)pwm[x2]=pwm[x2+1];
          for(x2=17;x2>9;x2--)pwm[x2]=pwm[x2-1];
          pwm[8]=rain4[x1];
          pwm[9]=rain4[x1];
          delay_ms(40);
        }
        for(x3=0;x3<4;x3++)
        for(x1=0;x1<19;x1++)
        {  for(x2=8;x2>00;x2--)pwm[x2]=pwm[x2-1];
          for(x2=9;x2<17;x2++)pwm[x2]=pwm[x2+1];
          pwm[0]=rain4[x1];
          pwm[17]=rain4[x1];
          delay_ms(40);
        }
        //////////////////////////////////////////
      }
    }
    سورس کد برای میکروهایATmega64-128 به زبان C کدویژن
    کد:
    /*****************************************************
    This program was produced by the
    CodeWizardAVR V2.05.3 Standard
    Automatic Program Generator
    © Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
    http://www.hpinfotech.com
    Project : 53-channel PWM (Rain LED)
    Version : 3.1
    Date  : 2/27/2014
    Author : Saman.Asadi
    www.ECA.ir
    Chip type        : ATmega64A
    Program type      : Application
    AVR Core Clock frequency: 8.000000 MHz
    Memory model      : Small
    External RAM size    : 0
    Data Stack size     : 2048
    *****************************************************/
    
    #include <mega64a.h>
    #include <delay.h>
    
    #define setled1   PORTF = PINF | 0x01
    #define setled2   PORTF = PINF | 0x02
    #define setled3   PORTF = PINF | 0x04
    #define setled4   PORTF = PINF | 0x08
    #define setled5   PORTF = PINF | 0x10
    #define setled6   PORTF = PINF | 0x20
    #define setled7   PORTF = PINF | 0x40
    #define setled8   PORTF = PINF | 0x80
    #define setled9   PORTA = PINA | 0x01
    #define setled10  PORTA = PINA | 0x02
    #define setled11  PORTA = PINA | 0x04
    #define setled12  PORTA = PINA | 0x08
    #define setled13  PORTA = PINA | 0x10
    #define setled14  PORTA = PINA | 0x20
    #define setled15  PORTA = PINA | 0x40
    #define setled16  PORTA = PINA | 0x80
    #define setled17  PORTG = PING | 0x04
    #define setled18  PORTC = PINC | 0x80
    #define setled19  PORTC = PINC | 0x40
    #define setled20  PORTC = PINC | 0x20
    #define setled21  PORTC = PINC | 0x10
    #define setled22  PORTC = PINC | 0x08
    #define setled23  PORTC = PINC | 0x04
    #define setled24  PORTC = PINC | 0x02
    #define setled25  PORTC = PINC | 0x01
    #define setled26  PORTG = PING | 0x02
    #define setled27  PORTG = PING | 0x01
    #define setled28  PORTD = PIND | 0x80
    #define setled29  PORTD = PIND | 0x40
    #define setled30  PORTD = PIND | 0x20
    #define setled31  PORTD = PIND | 0x10
    #define setled32  PORTD = PIND | 0x08
    #define setled33  PORTD = PIND | 0x04
    #define setled34  PORTD = PIND | 0x02
    #define setled35  PORTD = PIND | 0x01
    #define setled36  PORTG = PING | 0x10
    #define setled37  PORTG = PING | 0x08
    #define setled38  PORTB = PINB | 0x80
    #define setled39  PORTB = PINB | 0x40
    #define setled40  PORTB = PINB | 0x20
    #define setled41  PORTB = PINB | 0x10
    #define setled42  PORTB = PINB | 0x08
    #define setled43  PORTB = PINB | 0x04
    #define setled44  PORTB = PINB | 0x02
    #define setled45  PORTB = PINB | 0x01
    #define setled46  PORTE = PINE | 0x80
    #define setled47  PORTE = PINE | 0x40
    #define setled48  PORTE = PINE | 0x20
    #define setled49  PORTE = PINE | 0x10
    #define setled50  PORTE = PINE | 0x08
    #define setled51  PORTE = PINE | 0x04
    #define setled52  PORTE = PINE | 0x02
    #define setled53  PORTE = PINE | 0x01
    
    #define byte    unsigned char
    #define max_var_PWM 99
    
    byte    a = max_var_PWM;
    byte    pwm[55];
    flash byte rain1[25]={99,70,40,20,10,5,4,3,2,1,0};
    flash byte rain2[40]={0,1,2,3,4,5,10,20,40,70,99,70,40,20,10,5,4,3,2,1,0};
    flash byte rain3[35]={0,1,2,3,4,5,10,20,40,70,99};
    flash byte rain4[40]={1,2,3,4,5,10,20,40,70,99,70,40,20,10,5,4,3,2,1,0};
    
    // Timer 0 output compare interrupt service routine
    interrupt [TIM0_COMP] void timer0_comp_isr(void)
    {
      if(a)
      {  if(a == pwm[1] )setled1;
        if(a == pwm[2] )setled2;
        if(a == pwm[3] )setled3;
        if(a == pwm[4] )setled4;
        if(a == pwm[5] )setled5;
        if(a == pwm[6] )setled6;
        if(a == pwm[7] )setled7;
        if(a == pwm[8] )setled8;
        if(a == pwm[9] )setled9;
        if(a == pwm[10])setled10;
        if(a == pwm[11])setled11;
        if(a == pwm[12])setled12;
        if(a == pwm[13])setled13;
        if(a == pwm[14])setled14;
        if(a == pwm[15])setled15;
        if(a == pwm[16])setled16;
        if(a == pwm[17])setled17;
        if(a == pwm[18])setled18;
        if(a == pwm[19])setled19;
        if(a == pwm[20])setled20;
        if(a == pwm[21])setled21;
        if(a == pwm[22])setled22;
        if(a == pwm[23])setled23;
        if(a == pwm[24])setled24;
        if(a == pwm[25])setled25;
        if(a == pwm[26])setled26;
        if(a == pwm[27])setled27;
        if(a == pwm[28])setled28;
        if(a == pwm[29])setled29;
        if(a == pwm[30])setled30;
        if(a == pwm[31])setled31;
        if(a == pwm[32])setled32;
        if(a == pwm[33])setled33;
        if(a == pwm[34])setled34;
        if(a == pwm[35])setled35;
        if(a == pwm[36])setled36;
        if(a == pwm[37])setled37;
        if(a == pwm[38])setled38;
        if(a == pwm[39])setled39;
        if(a == pwm[40])setled40;
        if(a == pwm[41])setled41;
        if(a == pwm[42])setled42;
        if(a == pwm[43])setled43;
        if(a == pwm[44])setled44;
        if(a == pwm[45])setled45;
        if(a == pwm[46])setled46;
        if(a == pwm[47])setled47;
        if(a == pwm[48])setled48;
        if(a == pwm[49])setled49;
        if(a == pwm[50])setled50;
        if(a == pwm[51])setled51;
        if(a == pwm[52])setled52;
        if(a == pwm[53])setled53;
      }
      a-=1;
      if(a == 255)
      {  a = max_var_PWM;
        PORTA=0;
        PORTB=0;
        PORTC=0;
        PORTD=0;
        PORTE=0;
        PORTF=0;
        PORTG=0;
      }
    }
    
    void main(void)
    {
      byte x1,x2,x3;
      //Config all
      //Config timers
      //Config PORTS
      {
        DDRA=255;
        DDRB=255;
        DDRC=255;
        DDRD=255;
        DDRE=255;
        DDRF=255;
        DDRG=31;
        // Timer/Counter 0 initialization
        // Clock source: System Clock
        // Clock value: 1000.000 kHz
        // Mode: CTC top=OCR0
        // OC0 output: Disconnected
        TCCR0=0x0A;
        OCR0=150;
        // Timer(s)/Counter(s) Interrupt(s) initialization
        TIMSK=0x02;
        // Global enable interrupts
        #asm("sei")
      }
      //End Config ......
      while(1)
      {
        /////////////////////////////////////////
        for(x1=0;x1<25;x1++)
        {  pwm[1]=rain1[x1];
          for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
          delay_ms(40);
        }
        for(x1=0;x1<35;x1++)
        {  pwm[1]=rain2[x1];
          for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
          delay_ms(40);
        }
        delay_ms(500);
        for(x1=0;x1<25;x1++)
        {  pwm[1]=rain3[x1];
          for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
          delay_ms(40);
        }
        /////////////////////////////////////////
        for(x1=0;x1<25;x1++)
        {  pwm[17]=rain1[x1];
          for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
          delay_ms(40);
        }
        for(x1=0;x1<35;x1++)
        {  pwm[17]=rain2[x1];
          for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
          delay_ms(40);
        }
        for(x1=0;x1<25;x1++)
        {  pwm[17]=rain3[x1];
          for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
          delay_ms(40);
        }
        //////////////////////////////////////////
        for(x3=0;x3<3;x3++)
        for(x1=0;x1<14;x1++)
        {  for(x2=0;x2<8;x2++)pwm[x2]=pwm[x2+1];
          for(x2=17;x2>9;x2--)pwm[x2]=pwm[x2-1];
          pwm[8]=rain1[x1];
          pwm[9]=rain1[x1];
          delay_ms(40);
        }
        for(x3=0;x3<3;x3++)
        for(x1=0;x1<14;x1++)
        {  for(x2=8;x2>00;x2--)pwm[x2]=pwm[x2-1];
          for(x2=9;x2<17;x2++)pwm[x2]=pwm[x2+1];
          pwm[0]=rain1[x1];
          pwm[17]=rain1[x1];
          delay_ms(40);
        }
        //////////////////////////////////////////
        for(x3=0;x3<4;x3++)
        for(x1=0;x1<19;x1++)
        {  for(x2=0;x2<8;x2++)pwm[x2]=pwm[x2+1];
          for(x2=17;x2>9;x2--)pwm[x2]=pwm[x2-1];
          pwm[8]=rain4[x1];
          pwm[9]=rain4[x1];
          delay_ms(40);
        }
        for(x3=0;x3<4;x3++)
        for(x1=0;x1<19;x1++)
        {  for(x2=8;x2>00;x2--)pwm[x2]=pwm[x2-1];
          for(x2=9;x2<17;x2++)pwm[x2]=pwm[x2+1];
          pwm[0]=rain4[x1];
          pwm[17]=rain4[x1];
          delay_ms(40);
        }
        //////////////////////////////////////////
      }
    }
    به دلیل درخواست زیاد برنامه برای ATmega8 ، این برنامه در تاریخ 93/2/10 اضاف شد

    سورس کد برای میکروهای ATmega8 به زبان C کدویژن
    کد:
    #include <mega8.h>
    #include <delay.h>
    
    #define Set_LED1    PORTC.5 = 1
    #define Set_LED2    PORTC.4 = 1
    #define Set_LED3    PORTC.3 = 1
    #define Set_LED4    PORTC.2 = 1
    #define Set_LED5    PORTC.1 = 1
    #define Set_LED6    PORTC.0 = 1
    #define Set_LED7    PORTB.5 = 1
    #define Set_LED8    PORTB.4 = 1
    #define Set_LED9    PORTB.3 = 1
    #define Set_LED10    PORTB.2 = 1
    #define Set_LED11    PORTB.1 = 1
    #define Set_LED12    PORTB.0 = 1
    #define Set_LED13    PORTD.7 = 1
    #define Set_LED14    PORTD.6 = 1
    #define Set_LED15    PORTD.5 = 1
    #define Set_LED16    PORTB.7 = 1
    #define Set_LED17    PORTB.6 = 1
    #define Set_LED18    PORTD.4 = 1
    #define Set_LED19    PORTD.3 = 1
    #define Set_LED20    PORTD.2 = 1
    #define Set_LED21    PORTD.1 = 1
    #define Set_LED22    PORTD.0 = 1
    
    #define byte      unsigned char
    #define max_var_PWM   99
    #define Max_LED     22
    #define Delay1     30 //ms
    #define Delay2     200 //ms
    
    byte  a = max_var_PWM , pwm[Max_LED+3];
    flash byte rain1[50]=
    {99,80,70,60,40,20,15,9,7,5,3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    
    interrupt [TIM0_OVF] void timer0_comp_isr(void)
    {
      TCNT0 = 105;
      if(a)
      {
        if(a == pwm[22])Set_LED22;
        if(a == pwm[21])Set_LED21;
        if(a == pwm[20])Set_LED20;
        if(a == pwm[19])Set_LED19;
        if(a == pwm[18])Set_LED18;
        if(a == pwm[17])Set_LED17;
        if(a == pwm[16])Set_LED16;
        if(a == pwm[15])Set_LED15;
        if(a == pwm[14])Set_LED14;
        if(a == pwm[13])Set_LED13;
        if(a == pwm[12])Set_LED12;
        if(a == pwm[11])Set_LED11;
        if(a == pwm[10])Set_LED10;
        if(a == pwm[9 ])Set_LED9;
        if(a == pwm[8 ])Set_LED8;
        if(a == pwm[7 ])Set_LED7;
        if(a == pwm[6 ])Set_LED6;
        if(a == pwm[5 ])Set_LED5;
        if(a == pwm[4 ])Set_LED4;
        if(a == pwm[3 ])Set_LED3;
        if(a == pwm[2 ])Set_LED2;
        if(a == pwm[1 ])Set_LED1;
      }
      if(--a == 255)
      {
        a = max_var_PWM;
        PORTB=0;
        PORTC=0;
        PORTD=0;
      }
    }
    
    void main(void)
    {
      byte y1=Max_LED-1 ,y2= Max_LED+Max_LED ,x1 ,x2;
      //Config all
      //Config timers
      //Config PORTS
      {
        DDRB=255;
        DDRC=255;
        DDRD=255;
        // Timer/Counter 0 initialization
        // Clock source: System Clock
        // Clock value: 1000.000 kHz
        TCNT0=105;
        TCCR0=2;
        // Timer(s)/Counter(s) Interrupt(s) initialization
        TIMSK=1;
        // Global enable interrupts
        #asm("sei")
      }
      //End Config ......
      while(1)
      {
        for(x1=0;x1<y2;x1++)
        {
          for(x2=y1;x2>0;x2--)pwm[x2+1]=pwm[x2];
          pwm[1]=rain1[x1];
          delay_ms(Delay1);
        }
        delay_ms(Delay2);
      }
    }
    دوستان
    اگر اشتباهی دیدید حتما بگید :applause:
    با سپاس
    موفق باشید
    [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
    معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
    معرفی نرم افزار Codewizard PWM
    با من بیشتر آشنا شوید

    دیدگاه


      #3
      (برنامه بسکام)چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آموزشی]

      پیش خودم گفتم که این سورس که اینقدر خوب جواب داده چرا با زبانهای دیگه (مثل بیسیک) ارائه ندادم ؟؟؟
      به خاطر همین رفتم کدها رو به زبان بیسیک تبدیل کردم
      با این وجود که خیلی وقت بود طرف بیسیک نرفته بودم و کلا" یادم رفته بود ولی آخرش موفق شدم کدها رو تبدیل کنم

      سورس کد برای میکروهای ATmega16-32 به زبان بیسیک (بسکام)
      کد:
       $regfile = "m16def.dat"
       $crystal = 8000000
       Led1 Alias Porta.0
       Led2 Alias Porta.1
       Led3 Alias Porta.2
       Led4 Alias Porta.3
       Led5 Alias Porta.4
       Led6 Alias Porta.5
       Led7 Alias Porta.6
       Led8 Alias Porta.7
       Led9 Alias Portc.7
       Led10 Alias Portc.6
       Led11 Alias Portc.5
       Led12 Alias Portc.4
       Led13 Alias Portc.3
       Led14 Alias Portc.2
       Led15 Alias Portc.1
       Led16 Alias Portc.0
       Led17 Alias Portd.7
       Led18 Alias Portd.6
       Led19 Alias Portd.5
       Led20 Alias Portd.4
       Led21 Alias Portd.3
       Led22 Alias Portd.2
       Led23 Alias Portd.1
       Led24 Alias Portd.0
       Led25 Alias Portb.7
       Led26 Alias Portb.6
       Led27 Alias Portb.5
       Led28 Alias Portb.4
       Led29 Alias Portb.3
       Led30 Alias Portb.2
       Led31 Alias Portb.1
       Led32 Alias Portb.0
       Max_var_pwm Alias 99
      
       Dim Pwm(35) As Byte , A As Byte , X1 As Byte , X2 As Byte , X3 As Byte , X As Byte
       A = Max_var_pwm
        'Config All =============================================
        'Config Timers
        'Config Ports
         Config Timer0 = Timer , Prescale = 8
         Enable Compare0
         On Compare0 T0
         Ddra = 255
         Ddrb = 255
         Ddrc = 255
         Ddrd = 255
         ' Timer/Counter 0 initialization
         ' Clock source: System Clock
         ' Clock value: 1000.000 kHz
         ' Mode: CTC top=OCR0
         Tccr0 = &H0A
         Ocr0 = 150
         ' Global enable interrupts
         Enable Interrupts
        'End Config ============================================
        Do
         For X1 = 0 To 24
           Pwm(1) = Lookup(x1 , Rain1)
           For X2 = 17 To 1 Step -1
            X = X2 + 1
            Pwm(x) = Pwm(x2)
           Next X2
           Waitms 40
         Next X1
         For X1 = 0 To 34
           Pwm(1) = Lookup(x1 , Rain2)
           For X2 = 17 To 1 Step -1
            X = X2 + 1
            Pwm(x) = Pwm(x2)
           Next X2
           Waitms 40
         Next X1
         For X1 = 0 To 24
           Pwm(1) = Lookup(x1 , Rain3)
           For X2 = 17 To 1 Step -1
            X = X2 + 1
            Pwm(x) = Pwm(x2)
           Next X2
           Waitms 40
         Next X1
         For X1 = 1 To 24
           Pwm(17) = Lookup(x1 , Rain1)
           For X2 = 1 To 16
            X = X2 + 1
            Pwm(x2) = Pwm(x)
           Next X2
           Waitms 40
         Next X1
         For X1 = 0 To 34
           Pwm(17) = Lookup(x1 , Rain2)
           For X2 = 1 To 16
            X = X2 + 1
            Pwm(x2) = Pwm(x)
           Next X2
           Waitms 40
         Next X1
         For X1 = 0 To 24
           Pwm(17) = Lookup(x1 , Rain3)
           For X2 = 1 To 16
            X = X2 + 1
            Pwm(x2) = Pwm(x)
           Next X2
           Waitms 40
         Next X1
         For X3 = 1 To 3
           For X1 = 0 To 13
            For X2 = 1 To 7
              X = X2 + 1
              Pwm(x2) = Pwm(x)
            Next X2
            For X2 = 17 To 10 Step -1
              X = X2 - 1
              Pwm(x2) = Pwm(x)
            Next X2
            Pwm(8) = Lookup(x1 , Rain1)
            Pwm(9) = Lookup(x1 , Rain1)
            Waitms 40
           Next X1
         Next X3
         For X3 = 1 To 3
           For X1 = 0 To 13
            For X2 = 8 To 2 Step -1
              X = X2 - 1
              Pwm(x2) = Pwm(x)
            Next
            For X2 = 9 To 16
              X = X2 + 1
              Pwm(x2) = Pwm(x)
            Next
            Pwm(17) = Lookup(x1 , Rain1)
            Waitms 40
            Pwm(1) = Lookup(x1 , Rain1)
           Next
         Next
         For X3 = 0 To 3
           For X1 = 0 To 18
            For X2 = 1 To 7
              X = X2 + 1
              Pwm(x2) = Pwm(x)
            Next
            For X2 = 17 To 10 Step -1
              X = X2 - 1
              Pwm(x2) = Pwm(x)
            Next
            Pwm(8) = Lookup(x1 , Rain4)
            Pwm(9) = Lookup(x1 , Rain4)
            Waitms 40
           Next
         Next
         For X3 = 0 To 3
           For X1 = 0 To 18
            For X2 = 8 To 2 Step -1
              X = X2 - 1
              Pwm(x2) = Pwm(x)
            Next
            For X2 = 9 To 17
              X = X2 - 1
              Pwm(x2) = Pwm(x2 + 1)
            Next
            Pwm(1) = Lookup(x1 , Rain2)
            Pwm(17) = Lookup(x1 , Rain2)
            waitms 40
           Next
         Next
      
        Loop
      End                             'end program
      
      
       T0:
        If A > 0 Then
         If A = Pwm(1) Then Led1 = 1
         If A = Pwm(2) Then Led2 = 1
         If A = Pwm(3) Then Led3 = 1
         If A = Pwm(4) Then Led4 = 1
         If A = Pwm(5) Then Led5 = 1
         If A = Pwm(6) Then Led6 = 1
         If A = Pwm(7) Then Led7 = 1
         If A = Pwm(8) Then Led8 = 1
         If A = Pwm(9) Then Led9 = 1
         If A = Pwm(10) Then Led10 = 1
         If A = Pwm(11) Then Led11 = 1
         If A = Pwm(12) Then Led12 = 1
         If A = Pwm(13) Then Led13 = 1
         If A = Pwm(14) Then Led14 = 1
         If A = Pwm(15) Then Led15 = 1
         If A = Pwm(16) Then Led16 = 1
         If A = Pwm(17) Then Led17 = 1
         If A = Pwm(18) Then Led18 = 1
         If A = Pwm(19) Then Led19 = 1
         If A = Pwm(20) Then Led20 = 1
         If A = Pwm(21) Then Led21 = 1
         If A = Pwm(22) Then Led22 = 1
         If A = Pwm(23) Then Led23 = 1
         If A = Pwm(24) Then Led24 = 1
         If A = Pwm(25) Then Led25 = 1
         If A = Pwm(26) Then Led26 = 1
         If A = Pwm(27) Then Led27 = 1
         If A = Pwm(28) Then Led28 = 1
         If A = Pwm(29) Then Led29 = 1
         If A = Pwm(30) Then Led30 = 1
         If A = Pwm(31) Then Led31 = 1
         If A = Pwm(32) Then Led32 = 1
        End If
        Decr A
        If A = 255 Then
         A = Max_var_pwm
         Porta = 0
         Portb = 0
         Portc = 0
         Portd = 0
        End If
      Return
      
       Rain1:
       Data 0 , 99 , 70 , 40 , 20 , 10 , 5 , 4 , 3 , 2 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
       Rain2:
       Data 0 , 1 , 2 , 3 , 4 , 5 , 10 , 20 , 40 , 70 , 99 , 70 , 40 , 20 , 10 , 5 , 4 , 3 , 2 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
       Rain3:
       Data 0 , 1 , 2 , 3 , 4 , 5 , 10 , 20 , 40 , 70 , 99 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
       Rain4:
       Data 1 , 2 , 3 , 4 , 5 , 10 , 20 , 40 , 70 , 99 , 70 , 40 , 20 , 10 , 5 , 4 , 3 , 2 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
      سورس کد برای ATmega64-128 به زبان بیسیک(بسکام)
      کد:
       $regfile = "m64def.dat"
       $crystal = 8000000
      
       LED1 Alias Portf.0
       LED2 Alias Portf.1
       LED3 Alias Portf.2
       LED4 Alias Portf.3
       LED5 Alias Portf.4
       LED6 Alias Portf.5
       LED7 Alias Portf.6
       LED8 Alias Portf.7
       LED9 Alias Porta.0
       LED10 Alias Porta.1
       LED11 Alias Porta.2
       LED12 Alias Porta.3
       LED13 Alias Porta.4
       LED14 Alias Porta.5
       LED15 Alias Porta.6
       LED16 Alias Porta.7
       LED17 Alias Portg.2
       LED18 Alias Portc.7
       LED19 Alias Portc.6
       LED20 Alias Portc.5
       LED21 Alias Portc.4
       LED22 Alias Portc.3
       LED23 Alias Portc.2
       LED24 Alias Portc.1
       LED25 Alias Portc.0
       LED26 Alias Portg.1
       LED27 Alias Portg.0
       LED28 Alias Portd.7
       LED29 Alias Portd.6
       LED30 Alias Portd.5
       LED31 Alias Portd.4
       LED32 Alias Portd.3
       LED33 Alias Portd.2
       LED34 Alias Portd.1
       LED35 Alias Portd.0
       LED36 Alias Portg.4
       LED37 Alias Portg.3
       LED38 Alias Portb.7
       LED39 Alias Portb.6
       LED40 Alias Portb.5
       LED41 Alias Portb.4
       LED42 Alias Portb.3
       LED43 Alias Portb.2
       LED44 Alias Portb.1
       LED45 Alias Portb.0
       LED46 Alias Porte.7
       LED47 Alias Porte.6
       LED48 Alias Porte.5
       LED49 Alias Porte.4
       LED50 Alias Porte.3
       LED51 Alias Porte.2
       LED52 Alias Porte.1
       LED53 Alias Porte.0
      
       Max_var_pwm Alias 99
      
       Dim Pwm(55) As Byte , A As Byte , X1 As Byte , X2 As Byte , X3 As Byte , X As Byte
       A = Max_var_pwm
        'Config All =============================================
        'Config Timers
        'Config Ports
         Config Timer0 = Timer , Prescale = 8
         Enable Compare0
         On Compare0 T0
         Ddra = 255
         Ddrb = 255
         Ddrc = 255
         Ddrd = 255
         Ddre = 255
         Ddrf = 255
         Ddrg = 31
         ' Timer/Counter 0 initialization
         ' Clock source: System Clock
         ' Clock value: 1000.000 kHz
         ' Mode: CTC top=OCR0
         Tccr0 = &H0A
         Ocr0 = 150
         ' Global enable interrupts
         Enable Interrupts
        'End Config ============================================
        Do
         For X1 = 0 To 24
           Pwm(1) = Lookup(x1 , Rain1)
           For X2 = 17 To 1 Step -1
            X = X2 + 1
            Pwm(x) = Pwm(x2)
           Next X2
           Waitms 40
         Next X1
         For X1 = 0 To 34
           Pwm(1) = Lookup(x1 , Rain2)
           For X2 = 17 To 1 Step -1
            X = X2 + 1
            Pwm(x) = Pwm(x2)
           Next X2
           Waitms 40
         Next X1
         For X1 = 0 To 24
           Pwm(1) = Lookup(x1 , Rain3)
           For X2 = 17 To 1 Step -1
            X = X2 + 1
            Pwm(x) = Pwm(x2)
           Next X2
           Waitms 40
         Next X1
         For X1 = 1 To 24
           Pwm(17) = Lookup(x1 , Rain1)
           For X2 = 1 To 16
            X = X2 + 1
            Pwm(x2) = Pwm(x)
           Next X2
           Waitms 40
         Next X1
         For X1 = 0 To 34
           Pwm(17) = Lookup(x1 , Rain2)
           For X2 = 1 To 16
            X = X2 + 1
            Pwm(x2) = Pwm(x)
           Next X2
           Waitms 40
         Next X1
         For X1 = 0 To 24
           Pwm(17) = Lookup(x1 , Rain3)
           For X2 = 1 To 16
            X = X2 + 1
            Pwm(x2) = Pwm(x)
           Next X2
           Waitms 40
         Next X1
         For X3 = 1 To 3
           For X1 = 0 To 13
            For X2 = 1 To 7
              X = X2 + 1
              Pwm(x2) = Pwm(x)
            Next X2
            For X2 = 17 To 10 Step -1
              X = X2 - 1
              Pwm(x2) = Pwm(x)
            Next X2
            Pwm(8) = Lookup(x1 , Rain1)
            Pwm(9) = Lookup(x1 , Rain1)
            Waitms 40
           Next X1
         Next X3
         For X3 = 1 To 3
           For X1 = 0 To 13
            For X2 = 8 To 2 Step -1
              X = X2 - 1
              Pwm(x2) = Pwm(x)
            Next
            For X2 = 9 To 16
              X = X2 + 1
              Pwm(x2) = Pwm(x)
            Next
            Pwm(17) = Lookup(x1 , Rain1)
            Waitms 40
            Pwm(1) = Lookup(x1 , Rain1)
           Next
         Next
         For X3 = 0 To 3
           For X1 = 0 To 18
            For X2 = 1 To 7
              X = X2 + 1
              Pwm(x2) = Pwm(x)
            Next
            For X2 = 17 To 10 Step -1
              X = X2 - 1
              Pwm(x2) = Pwm(x)
            Next
            Pwm(8) = Lookup(x1 , Rain4)
            Pwm(9) = Lookup(x1 , Rain4)
            Waitms 40
           Next
         Next
         For X3 = 0 To 3
           For X1 = 0 To 18
            For X2 = 8 To 2 Step -1
              X = X2 - 1
              Pwm(x2) = Pwm(x)
            Next
            For X2 = 9 To 17
              X = X2 - 1
              Pwm(x2) = Pwm(x2 + 1)
            Next
            Pwm(1) = Lookup(x1 , Rain2)
            Pwm(17) = Lookup(x1 , Rain2)
            waitms 40
           Next
         Next
      
        Loop
      End                             'end program
      
      
       T0:
        If A > 0 Then
         If A = Pwm(1) Then LED1 = 1
         If A = Pwm(2) Then LED2 = 1
         If A = Pwm(3) Then LED3 = 1
         If A = Pwm(4) Then LED4 = 1
         If A = Pwm(5) Then LED5 = 1
         If A = Pwm(6) Then LED6 = 1
         If A = Pwm(7) Then LED7 = 1
         If A = Pwm(8) Then LED8 = 1
         If A = Pwm(9) Then LED9 = 1
         If A = Pwm(10) Then LED10 = 1
         If A = Pwm(11) Then LED11 = 1
         If A = Pwm(12) Then LED12 = 1
         If A = Pwm(13) Then LED13 = 1
         If A = Pwm(14) Then LED14 = 1
         If A = Pwm(15) Then LED15 = 1
         If A = Pwm(16) Then LED16 = 1
         If A = Pwm(17) Then LED17 = 1
         If A = Pwm(18) Then LED18 = 1
         If A = Pwm(19) Then LED19 = 1
         If A = Pwm(20) Then LED20 = 1
         If A = Pwm(21) Then LED21 = 1
         If A = Pwm(22) Then LED22 = 1
         If A = Pwm(23) Then LED23 = 1
         If A = Pwm(24) Then LED24 = 1
         If A = Pwm(25) Then LED25 = 1
         If A = Pwm(26) Then LED26 = 1
         If A = Pwm(27) Then LED27 = 1
         If A = Pwm(28) Then LED28 = 1
         If A = Pwm(29) Then LED29 = 1
         If A = Pwm(30) Then LED30 = 1
         If A = Pwm(31) Then LED31 = 1
         If A = Pwm(32) Then LED32 = 1
         If A = Pwm(33) Then LED33 = 1
         If A = Pwm(34) Then LED34 = 1
         If A = Pwm(35) Then LED35 = 1
         If A = Pwm(36) Then LED36 = 1
         If A = Pwm(37) Then LED37 = 1
         If A = Pwm(38) Then LED38 = 1
         If A = Pwm(39) Then LED39 = 1
         If A = Pwm(40) Then LED40 = 1
         If A = Pwm(41) Then LED41 = 1
         If A = Pwm(42) Then LED42 = 1
         If A = Pwm(43) Then LED43 = 1
         If A = Pwm(44) Then LED44 = 1
         If A = Pwm(45) Then LED45 = 1
         If A = Pwm(46) Then LED46 = 1
         If A = Pwm(47) Then LED47 = 1
         If A = Pwm(48) Then LED48 = 1
         If A = Pwm(49) Then LED49 = 1
         If A = Pwm(50) Then LED50 = 1
         If A = Pwm(51) Then LED51 = 1
         If A = Pwm(52) Then LED52 = 1
         If A = Pwm(53) Then LED53 = 1
        End If
        Decr A
        If A = 255 Then
         A = Max_var_pwm
         Porta = 0
         Portb = 0
         Portc = 0
         Portd = 0
         Porte = 0
         Portf = 0
         Portg = 0
        End If
      Return
      
       Rain1:
       Data 0 , 99 , 70 , 40 , 20 , 10 , 5 , 4 , 3 , 2 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
       Rain2:
       Data 0 , 1 , 2 , 3 , 4 , 5 , 10 , 20 , 40 , 70 , 99 , 70 , 40 , 20 , 10 , 5 , 4 , 3 , 2 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
       Rain3:
       Data 0 , 1 , 2 , 3 , 4 , 5 , 10 , 20 , 40 , 70 , 99 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
       Rain4:
       Data 1 , 2 , 3 , 4 , 5 , 10 , 20 , 40 , 70 , 99 , 70 , 40 , 20 , 10 , 5 , 4 , 3 , 2 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
      به دلیل درخواست زیاد برنامه برای ATmega8 ، این برنامه در تاریخ 93/2/11 اضاف شد
      سورس کد برای ATmega8 به زبان بیسیک(بسکام)
      کد:
      $regfile = "m8def.dat"
       $crystal = 8000000
      
      
       Led1 Alias portd.0
       Led2 Alias portd.1
       Led3 Alias portd.2
       Led4 Alias portd.3
       Led5 Alias portd.4
       Led6 Alias Portb.6
       Led7 Alias Portb.7
       Led8 Alias Portd.5
       Led9 Alias Portd.6
       Led10 Alias Portd.7
       Led11 Alias Portb.0
       Led12 Alias Portb.1
       Led13 Alias Portb.2
       Led14 Alias Portb.3
       Led15 Alias Portb.4
       Led16 Alias Portb.5
       Led17 Alias Portc.0
       Led18 Alias Portc.1
       Led19 Alias Portc.2
       Led20 Alias Portc.3
       Led21 Alias Portc.4
       Led22 Alias Portc.5
      
       Max_var_pwm Alias 99
       Max_led Alias 22
       Delay1 Alias 20
       'ms
       Delay2 Alias 200
       'ms
       Dim Pwm(35) As Byte , A As Byte , _
       Y2 As Byte , _
       X1 As Byte , X2 As Byte , X3 As Byte
       Y2 = Max_led + Max_led
       A = Max_var_pwm
      
        'Config All =============================================
        'Config Timers
        'Config Ports
         Config Timer0 = Timer , Prescale = 8
         Enable Interrupts
         Enable Timer0
         On Ovf0 T0
         Tcnt0 = 105
         Start Timer0
         Ddrb = 255
         Ddrc = 63
         Ddrd = 255
        'End Config ============================================
      
        Do
         X1 = 0
         While X1 < Y2
           X2 = Max_led
           While X2 > 1
            X3 = X2 - 1
            Pwm(x2) = Pwm(x3)
            Decr X2
           Wend
           Pwm(1) = Lookup(x1 , Rain)
           Waitms Delay1
           Incr X1
         Wend
         Waitms Delay2
        Loop
      End                             'end program
      
      
      T0:
        Tcnt0 = 105
        If A > 0 Then
         If A = Pwm(1) Then Led1 = 1
         If A = Pwm(2) Then Led2 = 1
         If A = Pwm(3) Then Led3 = 1
         If A = Pwm(4) Then Led4 = 1
         If A = Pwm(5) Then Led5 = 1
         If A = Pwm(6) Then Led6 = 1
         If A = Pwm(7) Then Led7 = 1
         If A = Pwm(8) Then Led8 = 1
         If A = Pwm(9) Then Led9 = 1
         If A = Pwm(10) Then Led10 = 1
         If A = Pwm(11) Then Led11 = 1
         If A = Pwm(12) Then Led12 = 1
         If A = Pwm(13) Then Led13 = 1
         If A = Pwm(14) Then Led14 = 1
         If A = Pwm(15) Then Led15 = 1
         If A = Pwm(16) Then Led16 = 1
         If A = Pwm(17) Then Led17 = 1
         If A = Pwm(18) Then Led18 = 1
         If A = Pwm(19) Then Led19 = 1
         If A = Pwm(20) Then Led20 = 1
         If A = Pwm(21) Then Led21 = 1
         If A = Pwm(22) Then Led22 = 1
      
        End If
        Decr A
        If A = 255 Then
         A = Max_var_pwm
         Portb = 0
         Portc = 0
         Portd = 0
        End If
      Return
      
       Rain:
       Data 99 , 80 , 70 , 60 , 40 , 20 , 15 , 9 , 7 , 5 , _
          3 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , _
          0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,_
          0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,_
          0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
      یه موضوع خیلی مهم
      دقیقا دو برنامه مثل هم هستند ولی موقع کامپایل کردن ، حافظه فلشی که برنامه بسکام اشغال میکنه تقریبا" دو برابر کدویژن هست
      چراااااااا ؟؟؟؟

      دوستان
      اگر اشتباهی دیدید حتما بگید :applause:
      با سپاس

      موفق باشید
      [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
      معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
      معرفی نرم افزار Codewizard PWM
      با من بیشتر آشنا شوید

      دیدگاه


        #4
        پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آموزشی]

        درود دوستان
        طبق وعده ای که به دوستان داده بودم کد این برنامه را برای اتمل هم نوشتم

        سورس کد برای میکروی ATmega8 به زبان C با نرم افزار ATmel Studio 6.1
        کد:
        /*
         * ATmega8.c
         *
         * Created: 4/6/2014 9:42:15 PM
         * Author: Saman.Asadi
         */ 
        
        #define F_CPU			8000000UL
        #include <avr/io.h>
        #include <avr/interrupt.h>
        #include </Library/iobits4ATmel_Studio.h>
        #include <avr/iom8.h>
        
        #define Set_LED1    Set_D0
        #define Set_LED2    Set_D1
        #define Set_LED3    Set_D2
        #define Set_LED4    Set_D3
        #define Set_LED5    Set_D4
        #define Set_LED6    Set_B6
        #define Set_LED7    Set_B7
        #define Set_LED8    Set_D5
        #define Set_LED9    Set_D6
        #define Set_LED10    Set_D7
        #define Set_LED11    Set_B0
        #define Set_LED12    Set_B1
        #define Set_LED13    Set_B2
        #define Set_LED14    Set_B3
        #define Set_LED15    Set_B4
        #define Set_LED16    Set_B5
        #define Set_LED17    Set_C0
        #define Set_LED18    Set_C1
        #define Set_LED19    Set_C2
        #define Set_LED20    Set_C3
        #define Set_LED21    Set_C4
        #define Set_LED22    Set_C5
        
        #define max_var_PWM		99
        uint8_t	a = max_var_PWM ,
        		pwm[25]={0,1,3,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,99};
        		
        ISR(TIMER0_OVF_vect)
        {  
        	TCNT0 = 105;
        	if(a)
        	{  
        		if(a == pwm[1] )Set_LED1;
        		if(a == pwm[2] )Set_LED2;
        		if(a == pwm[3] )Set_LED3;
        		if(a == pwm[4] )Set_LED4;
        		if(a == pwm[5] )Set_LED5;
        		if(a == pwm[6] )Set_LED6;
        		if(a == pwm[7] )Set_LED7;
        		if(a == pwm[8] )Set_LED8;
        		if(a == pwm[9] )Set_LED9;
        		if(a == pwm[10])Set_LED10;
        		if(a == pwm[11])Set_LED11;
        		if(a == pwm[12])Set_LED12;
        		if(a == pwm[13])Set_LED13;
        		if(a == pwm[14])Set_LED14;
        		if(a == pwm[15])Set_LED15;
        		if(a == pwm[16])Set_LED16;
        		if(a == pwm[17])Set_LED17;
        		if(a == pwm[18])Set_LED18;
        		if(a == pwm[19])Set_LED19;
        		if(a == pwm[20])Set_LED20;
        		if(a == pwm[21])Set_LED21;
        		if(a == pwm[22])Set_LED22;
        	}
        	if(--a == 255)
        	{  a = max_var_PWM;
        		PORTB=0;
        		PORTC=0;
        		PORTD=0;
        	}
        }
        
        int main(void)
        {
        	//Config all
        	//Config timers
        	//Config PORTS
        	{
        		Config_ioPORTB(1,1,1,1,1,1,1,1);
        		Config_ioPORTC(0,0,1,1,1,1,1,1);
        		Config_ioPORTD(1,1,1,1,1,1,1,1);
        		// Timer/Counter 0 initialization
        		// Clock source: System Clock
        		// Clock value: 1000.000 kHz
        		TCNT0=105;
        		TCCR0=2;
        		// Timer(s)/Counter(s) Interrupt(s) initialization
        		TIMSK=1;
        		// Global enable interrupts
        		sei();
        	}
        	//End Config ......
        	
        	while(1);
        }
        سورس کد برای میکروی ATmega16,32 به زبان C با نرم افزار ATmel Studio 6.1
        کد:
        /*
         * Rain_LED For ATmega16 and ATmega32
         * Created: 4/30/2014 4:06:07 PM
         * Author: Saman.Asadi
         */ 
        
        #include <avr/io.h>
        #define	F_CPU			8000000UL
        #include <util/delay.h>
        #include <avr/interrupt.h>
        #include </Library/iobits4ATmel_Studio.h>
        
        #define Set_LED1    Set_A0
        #define Set_LED2    Set_A1
        #define Set_LED3    Set_A2
        #define Set_LED4    Set_A3
        #define Set_LED5    Set_A4
        #define Set_LED6    Set_A5
        #define Set_LED7    Set_A6
        #define Set_LED8    Set_A7
        #define Set_LED9    Set_C7
        #define Set_LED10    Set_C6
        #define Set_LED11    Set_C5
        #define Set_LED12    Set_C4
        #define Set_LED13    Set_C3
        #define Set_LED14    Set_C2
        #define Set_LED15    Set_C1
        #define Set_LED16    Set_C0
        #define Set_LED17    Set_D7
        #define Set_LED18    Set_D6
        #define Set_LED19    Set_D5
        #define Set_LED20    Set_D4
        #define Set_LED21    Set_D3
        #define Set_LED22    Set_D2
        #define Set_LED23    Set_D1
        #define Set_LED24    Set_D0
        #define Set_LED25    Set_B7
        #define Set_LED26    Set_B6
        #define Set_LED27    Set_B5
        #define Set_LED28    Set_B4
        #define Set_LED29    Set_B3
        #define Set_LED30		Set_B2
        #define Set_LED31    Set_B1
        #define Set_LED32		Set_B0
        #define max_var_PWM		99
        uint8_t					a = max_var_PWM;
        uint8_t					pwm[35];
        const	uint8_t			rain1[25]={99,70,40,20,10,5,4,3,2,1,0};
        const	uint8_t			rain2[40]={0,1,2,3,4,5,10,20,40,70,99,70,40,20,10,5,4,3,2,1,0};
        const	uint8_t			rain3[35]={0,1,2,3,4,5,10,20,40,70,99};
        const	uint8_t			rain4[40]={1,2,3,4,5,10,20,40,70,99,70,40,20,10,5,4,3,2,1,0};
        
        // Timer 0 output compare interrupt service routine
        ISR(TIMER0_COMP_vect)
        {
        	if(a)
        	{  if(a == pwm[1] )Set_LED1;
        		if(a == pwm[2] )Set_LED2;
        		if(a == pwm[3] )Set_LED3;
        		if(a == pwm[4] )Set_LED4;
        		if(a == pwm[5] )Set_LED5;
        		if(a == pwm[6] )Set_LED6;
        		if(a == pwm[7] )Set_LED7;
        		if(a == pwm[8] )Set_LED8;
        		if(a == pwm[9] )Set_LED9;
        		if(a == pwm[10])Set_LED10;
        		if(a == pwm[11])Set_LED11;
        		if(a == pwm[12])Set_LED12;
        		if(a == pwm[13])Set_LED13;
        		if(a == pwm[14])Set_LED14;
        		if(a == pwm[15])Set_LED15;
        		if(a == pwm[16])Set_LED16;
        		if(a == pwm[17])Set_LED17;
        		if(a == pwm[18])Set_LED18;
        		if(a == pwm[19])Set_LED19;
        		if(a == pwm[20])Set_LED20;
        		if(a == pwm[21])Set_LED21;
        		if(a == pwm[22])Set_LED22;
        		if(a == pwm[23])Set_LED23;
        		if(a == pwm[24])Set_LED24;
        		if(a == pwm[25])Set_LED25;
        		if(a == pwm[26])Set_LED26;
        		if(a == pwm[27])Set_LED27;
        		if(a == pwm[28])Set_LED28;
        		if(a == pwm[29])Set_LED29;
        		if(a == pwm[30])Set_LED30;
        		if(a == pwm[31])Set_LED31;
        		if(a == pwm[32])Set_LED32;
        	}
        	a-=1;
        	if(a == 255)
        	//
        	{  a = max_var_PWM;
        		PORTA=0;
        		PORTB=0;
        		PORTC=0;
        		PORTD=0;
        	}
        }
        
        int main(void)
        {
        	uint8_t		x1,x2,x3;
        	//Config all
        	//Config timers
        	//Config PORTS
        	{
        		DDRA=255;
        		DDRB=255;
        		DDRC=255;
        		DDRD=255;
        		// Timer/Counter 0 initialization
        		// Clock source: System Clock
        		// Clock value: 1000.000 kHz
        		// Mode: CTC top=OCR0
        		// OC0 output: Disconnected
        		TCCR0=0x0A;
        		OCR0=150;
        		// Timer(s)/Counter(s) Interrupt(s) initialization
        		TIMSK=0x02;
        		// Global enable interrupts
        		sei();
        	}
        	//End Config ......
        	while(1)
        	//
        	{
        		/////////////////////////////////////////
        		for(x1=0;x1<25;x1++)
        		{  pwm[1]=rain1[x1];
        			for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
        			_delay_ms(40);
        		}
        		for(x1=0;x1<35;x1++)
        		{  pwm[1]=rain2[x1];
        			for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
        			_delay_ms(40);
        		}
        		_delay_ms(500);
        		for(x1=0;x1<25;x1++)
        		{  pwm[1]=rain3[x1];
        			for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
        			_delay_ms(40);
        		}
        		/////////////////////////////////////////
        		for(x1=0;x1<25;x1++)
        		{  pwm[17]=rain1[x1];
        			for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			_delay_ms(40);
        		}
        		for(x1=0;x1<35;x1++)
        		{  pwm[17]=rain2[x1];
        			for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			_delay_ms(40);
        		}
        		for(x1=0;x1<25;x1++)
        		{  pwm[17]=rain3[x1];
        			for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			_delay_ms(40);
        		}
        		//////////////////////////////////////////
        		for(x3=0;x3<3;x3++)
        		for(x1=0;x1<14;x1++)
        		{  for(x2=0;x2<8;x2++)pwm[x2]=pwm[x2+1];
        			for(x2=17;x2>9;x2--)pwm[x2]=pwm[x2-1];
        			pwm[8]=rain1[x1];
        			pwm[9]=rain1[x1];
        			_delay_ms(40);
        		}
        		for(x3=0;x3<3;x3++)
        		for(x1=0;x1<14;x1++)
        		{  for(x2=8;x2>00;x2--)pwm[x2]=pwm[x2-1];
        			for(x2=9;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			pwm[0]=rain1[x1];
        			pwm[17]=rain1[x1];
        			_delay_ms(40);
        		}
        		//////////////////////////////////////////
        		for(x3=0;x3<4;x3++)
        		for(x1=0;x1<19;x1++)
        		{  for(x2=0;x2<8;x2++)pwm[x2]=pwm[x2+1];
        			for(x2=17;x2>9;x2--)pwm[x2]=pwm[x2-1];
        			pwm[8]=rain4[x1];
        			pwm[9]=rain4[x1];
        			_delay_ms(40);
        		}
        		for(x3=0;x3<4;x3++)
        		for(x1=0;x1<19;x1++)
        		{  for(x2=8;x2>00;x2--)pwm[x2]=pwm[x2-1];
        			for(x2=9;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			pwm[0]=rain4[x1];
        			pwm[17]=rain4[x1];
        			_delay_ms(40);
        		}
        		//////////////////////////////////////////
        	}
        }
        سورس کد برای میکروی ATmega64,128 به زبان C با نرم افزار ATmel Studio 6.1
        کد:
        /*
         * Rain_LED For ATmega64 and ATmega128
         * Created: 4/30/2014 3:21:07 PM
         * Author: Saman.Asadi
         */ 
        
        #include <avr/io.h>
        #define	F_CPU			8000000UL
        #include <util/delay.h>
        #include <avr/interrupt.h>
        #include </Library/iobits4ATmel_Studio.h>
        
        #define Set_LED1		Set_F0
        #define Set_LED2		Set_F1
        #define Set_LED3		Set_F2
        #define Set_LED4		Set_F3
        #define Set_LED5		Set_F4
        #define Set_LED6		Set_F5
        #define Set_LED7		Set_F6
        #define Set_LED8		Set_F7
        #define Set_LED9		Set_A0
        #define Set_LED10		Set_A1
        #define Set_LED11		Set_A2
        #define Set_LED12		Set_A3
        #define Set_LED13		Set_A4
        #define Set_LED14		Set_A5
        #define Set_LED15		Set_A6
        #define Set_LED16		Set_A7
        #define Set_LED17		Set_G2
        #define Set_LED18		Set_C7
        #define Set_LED19		Set_C6
        #define Set_LED20		Set_C5
        #define Set_LED21		Set_C4
        #define Set_LED22		Set_C3
        #define Set_LED23		Set_C2
        #define Set_LED24		Set_C1
        #define Set_LED25		Set_C0
        #define Set_LED26		Set_G1
        #define Set_LED27		Set_G0
        #define Set_LED28		Set_D7
        #define Set_LED29		Set_D6
        #define Set_LED30		Set_D5
        #define Set_LED31		Set_D4
        #define Set_LED32		Set_D3
        #define Set_LED33		Set_D2
        #define Set_LED34		Set_D1
        #define Set_LED35		Set_D0
        #define Set_LED36		Set_G4
        #define Set_LED37		Set_G3
        #define Set_LED38		Set_B7
        #define Set_LED39		Set_B6
        #define Set_LED40		Set_B5
        #define Set_LED41		Set_B4
        #define Set_LED42		Set_B3
        #define Set_LED43		Set_B2
        #define Set_LED44		Set_B1
        #define Set_LED45		Set_B0
        #define Set_LED46		Set_E7
        #define Set_LED47		Set_E6
        #define Set_LED48		Set_E5
        #define Set_LED49		Set_E4
        #define Set_LED50		Set_E3
        #define Set_LED51		Set_E2
        #define Set_LED52		Set_E1
        #define Set_LED53		Set_E0
        #define max_var_PWM		99
        uint8_t					a = max_var_PWM;
        uint8_t					pwm[55];
        const	uint8_t			rain1[25]={99,70,40,20,10,5,4,3,2,1,0};
        const	uint8_t			rain2[40]={0,1,2,3,4,5,10,20,40,70,99,70,40,20,10,5,4,3,2,1,0};
        const	uint8_t			rain3[35]={0,1,2,3,4,5,10,20,40,70,99};
        const	uint8_t			rain4[40]={1,2,3,4,5,10,20,40,70,99,70,40,20,10,5,4,3,2,1,0};
        
        // Timer 0 output compare interrupt service routine
        ISR(TIMER0_COMP_vect)
        {
        	if(a)
        	{  if(a == pwm[1] )Set_LED1;
        		if(a == pwm[2] )Set_LED2;
        		if(a == pwm[3] )Set_LED3;
        		if(a == pwm[4] )Set_LED4;
        		if(a == pwm[5] )Set_LED5;
        		if(a == pwm[6] )Set_LED6;
        		if(a == pwm[7] )Set_LED7;
        		if(a == pwm[8] )Set_LED8;
        		if(a == pwm[9] )Set_LED9;
        		if(a == pwm[10])Set_LED10;
        		if(a == pwm[11])Set_LED11;
        		if(a == pwm[12])Set_LED12;
        		if(a == pwm[13])Set_LED13;
        		if(a == pwm[14])Set_LED14;
        		if(a == pwm[15])Set_LED15;
        		if(a == pwm[16])Set_LED16;
        		if(a == pwm[17])Set_LED17;
        		if(a == pwm[18])Set_LED18;
        		if(a == pwm[19])Set_LED19;
        		if(a == pwm[20])Set_LED20;
        		if(a == pwm[21])Set_LED21;
        		if(a == pwm[22])Set_LED22;
        		if(a == pwm[23])Set_LED23;
        		if(a == pwm[24])Set_LED24;
        		if(a == pwm[25])Set_LED25;
        		if(a == pwm[26])Set_LED26;
        		if(a == pwm[27])Set_LED27;
        		if(a == pwm[28])Set_LED28;
        		if(a == pwm[29])Set_LED29;
        		if(a == pwm[30])Set_LED30;
        		if(a == pwm[31])Set_LED31;
        		if(a == pwm[32])Set_LED32;
        		if(a == pwm[33])Set_LED33;
        		if(a == pwm[34])Set_LED34;
        		if(a == pwm[35])Set_LED35;
        		if(a == pwm[36])Set_LED36;
        		if(a == pwm[37])Set_LED37;
        		if(a == pwm[38])Set_LED38;
        		if(a == pwm[39])Set_LED39;
        		if(a == pwm[40])Set_LED40;
        		if(a == pwm[41])Set_LED41;
        		if(a == pwm[42])Set_LED42;
        		if(a == pwm[43])Set_LED43;
        		if(a == pwm[44])Set_LED44;
        		if(a == pwm[45])Set_LED45;
        		if(a == pwm[46])Set_LED46;
        		if(a == pwm[47])Set_LED47;
        		if(a == pwm[48])Set_LED48;
        		if(a == pwm[49])Set_LED49;
        		if(a == pwm[50])Set_LED50;
        		if(a == pwm[51])Set_LED51;
        		if(a == pwm[52])Set_LED52;
        		if(a == pwm[53])Set_LED53;
        	}
        	a-=1;
        	if(a == 255)
        	//
        	{  a = max_var_PWM;
        		PORTA=0;
        		PORTB=0;
        		PORTC=0;
        		PORTD=0;
        		PORTE=0;
        		PORTF=0;
        		PORTG=0;
        	}
        }
        
        int main(void)
        {
        	uint8_t		x1,x2,x3;
        	//Config all
        	//Config timers
        	//Config PORTS
        	{
        		DDRA=255;
        		DDRB=255;
        		DDRC=255;
        		DDRD=255;
        		DDRE=255;
        		DDRF=255;
        		DDRG=31;
        		// Timer/Counter 0 initialization
        		// Clock source: System Clock
        		// Clock value: 1000.000 kHz
        		// Mode: CTC top=OCR0
        		// OC0 output: Disconnected
        		TCCR0=0x0A;
        		OCR0=150;
        		// Timer(s)/Counter(s) Interrupt(s) initialization
        		TIMSK=0x02;
        		// Global enable interrupts
        		sei();
        	}
        	//End Config ......
        	while(1)
        	//
        	{
        		/////////////////////////////////////////
        		for(x1=0;x1<25;x1++)
        		{  pwm[1]=rain1[x1];
        			for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
        			_delay_ms(40);
        		}
        		for(x1=0;x1<35;x1++)
        		{  pwm[1]=rain2[x1];
        			for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
        			_delay_ms(40);
        		}
        		_delay_ms(500);
        		for(x1=0;x1<25;x1++)
        		{  pwm[1]=rain3[x1];
        			for(x2=17;x2>0;x2--)pwm[x2+1]=pwm[x2];
        			_delay_ms(40);
        		}
        		/////////////////////////////////////////
        		for(x1=0;x1<25;x1++)
        		{  pwm[17]=rain1[x1];
        			for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			_delay_ms(40);
        		}
        		for(x1=0;x1<35;x1++)
        		{  pwm[17]=rain2[x1];
        			for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			_delay_ms(40);
        		}
        		for(x1=0;x1<25;x1++)
        		{  pwm[17]=rain3[x1];
        			for(x2=0;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			_delay_ms(40);
        		}
        		//////////////////////////////////////////
        		for(x3=0;x3<3;x3++)
        		for(x1=0;x1<14;x1++)
        		{  for(x2=0;x2<8;x2++)pwm[x2]=pwm[x2+1];
        			for(x2=17;x2>9;x2--)pwm[x2]=pwm[x2-1];
        			pwm[8]=rain1[x1];
        			pwm[9]=rain1[x1];
        			_delay_ms(40);
        		}
        		for(x3=0;x3<3;x3++)
        		for(x1=0;x1<14;x1++)
        		{  for(x2=8;x2>00;x2--)pwm[x2]=pwm[x2-1];
        			for(x2=9;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			pwm[0]=rain1[x1];
        			pwm[17]=rain1[x1];
        			_delay_ms(40);
        		}
        		//////////////////////////////////////////
        		for(x3=0;x3<4;x3++)
        		for(x1=0;x1<19;x1++)
        		{  for(x2=0;x2<8;x2++)pwm[x2]=pwm[x2+1];
        			for(x2=17;x2>9;x2--)pwm[x2]=pwm[x2-1];
        			pwm[8]=rain4[x1];
        			pwm[9]=rain4[x1];
        			_delay_ms(40);
        		}
        		for(x3=0;x3<4;x3++)
        		for(x1=0;x1<19;x1++)
        		{  for(x2=8;x2>00;x2--)pwm[x2]=pwm[x2-1];
        			for(x2=9;x2<17;x2++)pwm[x2]=pwm[x2+1];
        			pwm[0]=rain4[x1];
        			pwm[17]=rain4[x1];
        			_delay_ms(40);
        		}
        		//////////////////////////////////////////
        	}
        }
        راستی بچه ها
        برای راحتی کار یک کتابخونه نوشتم که کار ورودی و خروجی کردن و ست و ریست و تاگل و نات و ... رو خیلی راحت میکنه
        کتابخانه رو براتون میگذارم تا بهتون خوش بگذره :nice:

        کتابخانه iobits.h برای کامپایلر Atmel Studio 6.1
        http://s5.picofile.com/file/8119225042/iobits4ATmel_Studio.h.html

        امیدوارم خوشتون بیاد
        موفق باشید
        [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
        معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
        معرفی نرم افزار Codewizard PWM
        با من بیشتر آشنا شوید

        دیدگاه


          #5
          پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آمو&

          سلام دوست عزیز
          از زحماتتون واقعا متشکرم
          سورسی که خودتون نوشتید به خوبی کار میکنه .
          من خواستم یک ابشاری خیلی ساده برای 32 LED با AT32 بنویسم و این حلقه رو تعریف کردم
          کد:
              for(x1=0;x1<25;x1++)
              {  pwm[1]=rain1[x1];
                for(x2=31;x2>0;x2--)
                {
                 pwm[x2+1]=pwm[x2];
                }
                delay_ms(40);
              }
          ولی جواب خوبی نمیگیرم
          تا LED 24 به خوبی کار میکنه ولی از 24 به بعد یک پرش ایجاد میشه و انگار LEDهای 24 به بعد با LEDهای 1تا8 سنکرون میشن و عین هم کار میکنند .
          لطفا توی تصحیح سورس کمکم کنید
          ممنونم .

          دیدگاه


            #6
            پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آمو&

            نوشته اصلی توسط Mohammad_2007
            سلام دوست عزیز
            از زحماتتون واقعا متشکرم
            سورسی که خودتون نوشتید به خوبی کار میکنه .
            من خواستم یک ابشاری خیلی ساده برای 32 LED با AT32 بنویسم و این حلقه رو تعریف کردم
            کد:
                for(x1=0;x1<25;x1++)
                {  pwm[1]=rain1[x1];
                  for(x2=31;x2>0;x2--)
                  {
                   pwm[x2+1]=pwm[x2];
                  }
                  delay_ms(40);
                }
            ولی جواب خوبی نمیگیرم
            تا LED 24 به خوبی کار میکنه ولی از 24 به بعد یک پرش ایجاد میشه و انگار LEDهای 24 به بعد با LEDهای 1تا8 سنکرون میشن و عین هم کار میکنند .
            لطفا توس تصحیح سورس کمکم کنید
            ممنونم .
            سلام دوست عزیز
            خوب معلومه
            کد:
            flash byte rain1[25]={99,70,40,20,10,5,4,3,2,1,0};
            آرایه رو نگاه کن ...
            تا 25 تا بیشتر نگذاشتم
            پس شما باید اندیس این آرایه رو بزرگتر بگیرید ...
            کد:
            flash byte rain1[40]={99,70,40,20,10,5,4,3,2,1,0};
            این رو بگذارید جواب میده :agree: :nice:
            این رو تست کنید جوابش رو بهم بگید
            موفق باشید
            [hr]
            در ضمن
            چرا شما با مگا 32 کار میکنید ؟؟؟
            چرا با مگا 16 کار نمیکنید ....
            پایه های مگا 16 و 32 یکی هست ...
            ارزونتر هم هست ...


            [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
            معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
            معرفی نرم افزار Codewizard PWM
            با من بیشتر آشنا شوید

            دیدگاه


              #7
              پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آموزشی]

              اینهارو قبلا هم تست کردم
              با افزایشش مسکل سنکرون بود حل میشه ولی هنوز پرش وجود داره ، هر چیم کد رو بررسی میکنم دلیل خاصی نمیبینم ولی... !!!
              الان باز دوباره تست کردم و جواب نداد :sad:

              راستی تو بیشتر مواقع میکرو هنگ میکنه
              درضمن از کلاک داخلی استفاده کردم

              دیدگاه


                #8
                پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آموزشی]

                نوشته اصلی توسط Mohammad_2007
                اینهارو قبلا هم تست کردم
                الان باز دوباره تست کردم و جواب نداد :sad:
                آها
                مشکلتون اینجا هم هست
                کد:
                    for(x1=0;x1<40;x1++)
                    {  pwm[1]=rain1[x1];
                      for(x2=31;x2>0;x2--)
                      {
                       pwm[x2+1]=pwm[x2];
                      }
                      delay_ms(40);
                    }
                25 رو بکنید 40
                [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
                معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
                معرفی نرم افزار Codewizard PWM
                با من بیشتر آشنا شوید

                دیدگاه


                  #9
                  پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آموزشی]

                  این سورس رو تست کردم
                  کد:
                      for(x1=0;x1<40;x1++)
                      {  pwm[1]=rain1[x1];
                        for(x2=31;x2>0;x2--)
                        {
                         pwm[x2+1]=pwm[x2];
                        }
                        delay_ms(40);
                      }
                  هنوز پرش وجود داره
                  بیشتر مواقع میکرو هنگ میکنه

                  دیدگاه


                    #10
                    پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آموزشی]

                    نوشته اصلی توسط Mohammad_2007
                    این سورس رو تست کردم
                    کد:
                        for(x1=0;x1<40;x1++)
                        {  pwm[1]=rain1[x1];
                          for(x2=31;x2>0;x2--)
                          {
                           pwm[x2+1]=pwm[x2];
                          }
                          delay_ms(40);
                        }
                    هنوز پرش وجود داره
                    بیشتر مواقع میکرو هنگ میکنه
                    میشه فیلم بگیرید و بگذارید تا ببینم
                    من همین فیلمی که گذاشتم رو 3 شبانه روز گذاشتم هنگ هم نکرد ...
                    فرکانسش 8مگ داخلی گذاشتم
                    راستی
                    JTAG رو غیر فعال کنید
                    [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
                    معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
                    معرفی نرم افزار Codewizard PWM
                    با من بیشتر آشنا شوید

                    دیدگاه


                      #11
                      پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آموزشی]

                      کد رو به این شکل نوشتم مشکل تا حدودی حل شد
                      کد:
                          for(x1=0;x1<40;x1++)
                          {  pwm[1]=rain1[x1];
                            for(x2=32;x2!=0;x2--)
                            {
                             pwm[x2+1]=pwm[x2];
                            }
                            delay_ms(40);
                          }
                      ایشالا رو برد 1000 سوراخ میزنم چون به برد برد نمیشه زیاد اعتماد کرد
                      راستی اگه بخوام طول قطره رو بیشتر کنم باید اعداد تابع rain1 رو بیشتر کنم ، درسته ؟
                      ایشالا فردا تست رو ادامه میدم
                      ممنونم و شب بخیر

                      دیدگاه


                        #12
                        پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آمو&

                        نوشته اصلی توسط SAMAN.ASADI
                        در ضمن
                        چرا شما با مگا 32 کار میکنید ؟؟؟
                        چرا با مگا 16 کار نمیکنید ....
                        پایه های مگا 16 و 32 یکی هست ...
                        ارزونتر هم هست ...
                        اخه الان 16 موجود ندارم :biggrin:
                        ایشالا ردیف که شد از 16 استفاده میکنم.

                        راستی jtag رو چجوری باید غیر فعال کنم ؟

                        دیدگاه


                          #13
                          پاسخ : پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟&#1

                          نوشته اصلی توسط Mohammad_2007
                          کد رو به این شکل نوشتم مشکل تا حدودی حل شد
                          کد:
                              for(x1=0;x1<40;x1++)
                              {  pwm[1]=rain1[x1];
                                for(x2=32;x2!=0;x2--)
                                {
                                 pwm[x2+1]=pwm[x2];
                                }
                                delay_ms(40);
                              }
                          ایشالا رو برد 1000 سوراخ میزنم چون به برد برد نمیشه زیاد اعتماد کرد
                          راستی اگه بخوام طول قطره رو بیشتر کنم باید اعداد تابع rain1 رو بیشتر کنم ، درسته ؟
                          ایشالا فردا تست رو ادامه میدم
                          ممنونم و شب بخیر
                          بله
                          باید اعداد رو تغییر بدید ...
                          البته باید آرایه رو 2 برابر بگیرید
                          65 بگیرید خوبه
                          حافظه به اندازه کافی زیاد هست :biggrin:
                          نگران حافظه میکرو نباشید
                          [hr]

                          نوشته اصلی توسط Mohammad_2007
                          اخه الان 16 موجود ندارم :biggrin:
                          ایشالا ردیف که شد از 16 استفاده میکنم.

                          راستی jtag رو چجوری باید غیر فعال کنم ؟
                          فیوزبیت JTAGEN که به صورت پیشفرض صفر هست رو باید بکنیدش یک تا غیر فعال بشه
                          آن وقت میتوانید با پایه های C.2 , C.3 , C.4 , C.5 کار کنید
                          ----------------------------------------------------------------------------------------------------------------
                          این هم کدی که میخواستید
                          کد:
                            while(1)
                            {
                              for(x1=0;x1<32;x1++)
                              {
                                pwm[1]=rain1[x1];
                                for(x2=31;x2>0;x2--)pwm[x2+1]=pwm[x2];
                                delay_ms(40);
                              }
                              for(x1=0;x1<32;x1++)
                              {
                                for(x2=31;x2>0;x2--)pwm[x2+1]=pwm[x2];
                                delay_ms(40);
                              }
                            }
                          باید 32 تا متغیر را وارد کنید سپس خارجش کنید
                          حلقه For دومی این مشکلتون رو حل میکنه
                          همین الان تستش کردم ... :biggrin:
                          --------------------------------------------------------------------------------------------------------------------
                          این هم همین الان تستش کردم
                          کد:
                          /*****************************************************
                          This program was produced by the
                          CodeWizardAVR V2.05.3 Standard
                          Automatic Program Generator
                          © Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
                          http://www.hpinfotech.com
                          Project : 32-channel PWM (Rain LED)
                          Version : 2.1
                          Date  : 2/27/2014
                          Author : Saman.Asadi
                          www.ECA.ir
                          Chip type        : ATmega16
                          Program type      : Application
                          AVR Core Clock frequency: 8.000000 MHz
                          Memory model      : Small
                          External RAM size    : 0
                          Data Stack size     : 256
                          *****************************************************/
                          #include <mega16a.h>
                          #include <delay.h>
                          
                          #define led1    PORTA.0
                          #define led2    PORTA.1
                          #define led3    PORTA.2
                          #define led4    PORTA.3
                          #define led5    PORTA.4
                          #define led6    PORTA.5
                          #define led7    PORTA.6
                          #define led8    PORTA.7
                          #define led9    PORTC.7
                          #define led10    PORTC.6
                          #define led11    PORTC.5
                          #define led12    PORTC.4
                          #define led13    PORTC.3
                          #define led14    PORTC.2
                          #define led15    PORTC.1
                          #define led16    PORTC.0
                          #define led17    PORTD.7
                          #define led18    PORTD.6
                          #define led19    PORTD.5
                          #define led20    PORTD.4
                          #define led21    PORTD.3
                          #define led22    PORTD.2
                          #define led23    PORTD.1
                          #define led24    PORTD.0
                          #define led25    PORTB.7
                          #define led26    PORTB.6
                          #define led27    PORTB.5
                          #define led28    PORTB.4
                          #define led29    PORTB.3
                          #define led30    PORTB.2
                          #define led31    PORTB.1
                          #define led32    PORTB.0
                          
                          #define byte    unsigned char
                          #define max_var_PWM 200
                          #define factor
                          byte    a = max_var_PWM;
                          byte    pwm[35];
                          flash byte rain1[35]=
                          {200,170,150,130,110,90,70,50,30,28,26,24,22,20,18,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
                          
                          // Timer 0 output compare interrupt service routine
                          interrupt [TIM0_COMP] void timer0_comp_isr(void)
                          {  if(a)
                            {  if(a == pwm[1] )led1=1;
                              if(a == pwm[2] )led2=1;
                              if(a == pwm[3] )led3=1;
                              if(a == pwm[4] )led4=1;
                              if(a == pwm[5] )led5=1;
                              if(a == pwm[6] )led6=1;
                              if(a == pwm[7] )led7=1;
                              if(a == pwm[8] )led8=1;
                              if(a == pwm[9] )led9=1;
                              if(a == pwm[10])led10=1;
                              if(a == pwm[11])led11=1;
                              if(a == pwm[12])led12=1;
                              if(a == pwm[13])led13=1;
                              if(a == pwm[14])led14=1;
                              if(a == pwm[15])led15=1;
                              if(a == pwm[16])led16=1;
                              if(a == pwm[17])led17=1;
                              if(a == pwm[18])led18=1;
                              if(a == pwm[19])led19=1;
                              if(a == pwm[20])led20=1;
                              if(a == pwm[21])led21=1;
                              if(a == pwm[22])led22=1;
                              if(a == pwm[23])led23=1;
                              if(a == pwm[24])led24=1;
                              if(a == pwm[25])led25=1;
                              if(a == pwm[26])led26=1;
                              if(a == pwm[27])led27=1;
                              if(a == pwm[28])led28=1;
                              if(a == pwm[29])led29=1;
                              if(a == pwm[30])led30=1;
                              if(a == pwm[31])led31=1;
                              if(a == pwm[32])led32=1;
                            }
                            if(--a == 255)
                            {  a = max_var_PWM;
                              PORTA=0;
                              PORTB=0;
                              PORTC=0;
                              PORTD=0;
                            }
                          }
                          
                          void main(void)
                          {
                            byte x1,x2;
                            //Config all
                            //Config timers
                            //Config PORTS
                            {
                              DDRA=255;
                              DDRB=255;
                              DDRC=255;
                              DDRD=255;
                              // Timer/Counter 0 initialization
                              // Clock source: System Clock
                              // Clock value: 1000.000 kHz
                              // Mode: CTC top=OCR0
                              // OC0 output: Disconnected
                              TCCR0=0x0A;
                              OCR0=80;
                              // Timer(s)/Counter(s) Interrupt(s) initialization
                              TIMSK=0x02;
                              // Global enable interrupts
                              #asm("sei")
                            }
                            //End Config ......
                            while(1)
                            {
                              for(x1=0;x1<32;x1++)
                              {
                                pwm[1]=rain1[x1];
                                for(x2=31;x2>0;x2--)pwm[x2+1]=pwm[x2];
                                delay_ms(15);
                              }
                              for(x1=0;x1<32;x1++)
                              {
                                for(x2=31;x2>0;x2--)pwm[x2+1]=pwm[x2];
                                delay_ms(15);
                              }
                            }
                          }
                          توی این برنامه تنظیمات رو تغییر دادم بنابراین کل برنامه را کپی برداری کنید
                          مقادیر PWM هم همون طور که میبینی از 0 تا 200 هست

                          موفق باشید


                          [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
                          معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
                          معرفی نرم افزار Codewizard PWM
                          با من بیشتر آشنا شوید

                          دیدگاه


                            #14
                            زحمت...

                            سامان جان خیلی ممنون که کمک میکنی
                            میگم حالا شما که زحمت کشیدی و تا اینجا کمک کردی...
                            یک زحمت دیگه بکش و واسه مگا 8 یک تنظیماتی انجام بده و یک آبشاری خوشگل واسش بنویس
                            واقعا ممنونت میشم :rolleyes:
                            خیلی لطف میکنی دوست عزیز

                            دیدگاه


                              #15
                              پاسخ : رحمت ...

                              نوشته اصلی توسط Mohammad_2007
                              سامان جان خیلی ممنون که کمک میکنی
                              میگم حالا شما که زحمت کشیدی و تا اینجا کمک کردی...
                              یک زحمت دیگه بکش و واسه مگا 8 یک تنظیماتی انجام بده و یک آبشاری خوشگل واسش بنویس
                              واقعا ممنونت میشم :rolleyes:
                              خیلی لطف میکنی دوست عزیز
                              سلام محمد جان
                              برای کدویژن ؟؟؟
                              کاری که نداره ... نمونه برنامه رو برای کامپایلر اتمل استودیو نوشتم
                              اون قسمت رو کپی پست کنید توی کدویژن
                              اینطوری!!!
                              کد:
                              /*****************************************************
                              This program was produced by the
                              CodeWizardAVR V2.05.3 Standard
                              Automatic Program Generator
                              © Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
                              http://www.hpinfotech.com
                              Project : 22-channel PWM (Rain LED)
                              Version : 2.1
                              Date  : 4/8/2014
                              Author : Saman.Asadi
                              www.ECA.ir
                              Chip type        : ATmega8
                              Program type      : Application
                              AVR Core Clock frequency: 8.000000 MHz
                              Memory model      : Small
                              External RAM size    : 0
                              Data Stack size     : 256
                              *****************************************************/
                              #include <mega8.h>
                              #include <delay.h>
                              #define Set_LED1    PORTD.0 = 1
                              #define Set_LED2    PORTD.1 = 1
                              #define Set_LED3    PORTD.2 = 1
                              #define Set_LED4    PORTD.3 = 1
                              #define Set_LED5    PORTD.4 = 1
                              #define Set_LED6    PORTB.6 = 1
                              #define Set_LED7    PORTB.7 = 1
                              #define Set_LED8    PORTD.5 = 1
                              #define Set_LED9    PORTD.6 = 1
                              #define Set_LED10    PORTD.7 = 1
                              #define Set_LED11    PORTB.0 = 1
                              #define Set_LED12    PORTB.1 = 1
                              #define Set_LED13    PORTB.2 = 1
                              #define Set_LED14    PORTB.3 = 1
                              #define Set_LED15    PORTB.4 = 1
                              #define Set_LED16    PORTB.5 = 1
                              #define Set_LED17    PORTC.0 = 1
                              #define Set_LED18    PORTC.1 = 1
                              #define Set_LED19    PORTC.2 = 1
                              #define Set_LED20    PORTC.3 = 1
                              #define Set_LED21    PORTC.4 = 1
                              #define Set_LED22    PORTC.5 = 1
                              #define byte      unsigned char
                              #define max_var_PWM   200
                              byte  a = max_var_PWM , pwm[25];
                              flash byte rain1[25]=
                              {200,180,160,140,120,100,80,60,40,20,15,10,9,8,7,6,5,4,3,2,1,0};
                              
                              interrupt [TIM0_OVF] void timer0_comp_isr(void)
                              {
                                TCNT0 = 105;
                                if(a)
                                {
                                  if(a == pwm[1] )Set_LED1;
                                  if(a == pwm[2] )Set_LED2;
                                  if(a == pwm[3] )Set_LED3;
                                  if(a == pwm[4] )Set_LED4;
                                  if(a == pwm[5] )Set_LED5;
                                  if(a == pwm[6] )Set_LED6;
                                  if(a == pwm[7] )Set_LED7;
                                  if(a == pwm[8] )Set_LED8;
                                  if(a == pwm[9] )Set_LED9;
                                  if(a == pwm[10])Set_LED10;
                                  if(a == pwm[11])Set_LED11;
                                  if(a == pwm[12])Set_LED12;
                                  if(a == pwm[13])Set_LED13;
                                  if(a == pwm[14])Set_LED14;
                                  if(a == pwm[15])Set_LED15;
                                  if(a == pwm[16])Set_LED16;
                                  if(a == pwm[17])Set_LED17;
                                  if(a == pwm[18])Set_LED18;
                                  if(a == pwm[19])Set_LED19;
                              		if(a == pwm[20])Set_LED20;
                              		if(a == pwm[21])Set_LED21;
                              		if(a == pwm[22])Set_LED22;
                              	}
                              	if(--a == 255)
                              	{  a = max_var_PWM;
                              		PORTB=0;
                              		PORTC=0;
                              		PORTD=0;
                              	}
                              }
                              
                              void main(void)
                              {
                                byte x1,x2;
                                //Config all
                                //Config timers
                                //Config PORTS
                                {
                                  DDRB=255;
                                  DDRC=0x3F;
                                  DDRD=255;
                              		// Timer/Counter 0 initialization
                              		// Clock source: System Clock
                              		// Clock value: 1000.000 kHz
                              		TCNT0=105;
                              		TCCR0=2;
                              		// Timer(s)/Counter(s) Interrupt(s) initialization
                              		TIMSK=1;
                                  // Global enable interrupts
                                  #asm("sei")
                                }
                                //End Config ......
                                while(1)
                                {
                                  for(x1=0;x1<22;x1++)
                                  {
                                    pwm[1]=rain1[x1];
                                    for(x2=21;x2>0;x2--)pwm[x2+1]=pwm[x2];
                                    delay_ms(15);
                                  }
                                  for(x1=0;x1<32;x1++)
                                  {
                                    for(x2=31;x2>0;x2--)pwm[x2+1]=pwm[x2];
                                    delay_ms(15);
                                  }
                                }
                              }
                              کار نکرد خبرم کن
                              مگا 8 خونه ندارم تست کنم
                              موفق باشید
                              [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
                              معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
                              معرفی نرم افزار Codewizard PWM
                              با من بیشتر آشنا شوید

                              دیدگاه

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