اطلاعیه

Collapse
No announcement yet.

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

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

    پاسخ : چگونه همه پایه های128و64و32و16وATmega8 را PWM کنیم؟؟ پروژه LED RGB اضاف شد!

    سلام دوستان
    چگونه می توانم یک ولوم را به صورت بی سیم فرمان بدم و سرعت موتور را کم و زیاد کنم ؟
    این پروژه را به صورت 16 کانال میخواهم

    دیدگاه


      پاسخ : چگونه همه پایه های128و64و32و16وATmega8 را PWM کنیم؟؟ پروژه LED RGB اضاف شد!

      نوشته اصلی توسط IRANIANMADAR
      سلام دوستان
      چگونه می توانم یک ولوم را به صورت بی سیم فرمان بدم و سرعت موتور را کم و زیاد کنم ؟
      این پروژه را به صورت 16 کانال میخواهم
      سلام دوست عزیز
      کل پروژه تقریبا زیاد سخت نیست ...
      اگر ارتباط بی سیم مطمئنی داشته باشید بقیه مراحل زیاد سخت نیست ...
      یک مشکلی هم که این پروژه داره اینه که کمتر میکرویی پیدا میشه که 16 تا ADC داشته باشه که میکرویی به ذهنم نمیرسه که 16 تا ADC داشته باشه ...
      البته میشه دوتا مالتی پلکسر آنالوگ 8 به 1 استفاده کنیم ...
      باید روی این پروژه کار بشه ... روی روشهای مختلف فکر میکنم نتیجه رو بهتون خبر میدهم ...

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

      دیدگاه


        پاسخ : برنامه پیشنهادی برای LED) LED RGB تمام رنگی)

        نوشته اصلی توسط سامان اسدی
        سلام

        سوال خیلی خوبی پرسیدید ... و میتونه یک پروژه خوبی باشه ...
        البته من میخواستم که برنامه رو بگذارم که دیگه وقت نکردم برم دنبالش ...

        خوب یریم سر اصل مطلب
        ببین دوست عزیز
        شما میخواین که 256 تا رنگ با 3 LED سبز و آبی و قرمز درست کنید ...
        اگر هر LED براش چندتا طیف رنگ تعریف کنید کافیه و میتونید تولید چند صد رنگ مختلف را ایجاد کنید ...
        به عنوان مثال
        اگر هر LED هشت طیف رنگی براش تعریف کنید میشه 512=8X8X8
        اگر هر LED هفت طیف رنگی براش تعریف کنید میشه 343=7X7X7
        اگر هر LED شش طیف رنگی براش تعریف کنید میشه 216=6X6X6
        خوب
        الان ما میخوایم که با اولین حالت کار کنیم (512 رنگی)
        طبق گفته های پست قبلی من باید 8 طیف رو (که میشه 0 تا 7 ) ضرب در فرکانس PWM (اینجا میگیریم 100 هرتز )کنیم میشه 800 ...
        زمانی که نیاز داریم تا برنامه پرش کنه به روتین تایمر 1/800 ثانیه است که برابر است با 1.25 میلی ثانیه ...
        پس باید برنامه رو طوری بنویسیم که هر 1.25 میلی ثانیه به روتین تایمر رود ...
        با فرض اینکه فرکانس کاری ما 8مگا هرتز باشه و تقسیم کننده فرکانس تایمر صفر روی 64 تنظیم کنیم ، زمان هر بار که به مقدار تایمر کانتر صفر اضاف میشه 8 میکرو ثانیه ... که اگر بخوایم مقدار تایمر رو بدست بیاریم میشه 156=1.25mS/8us و چون شمارش دیجیتال از صفر تا n هست باید از صفر تا 155 در نظر بگیریم ...
        خوب
        چند تا زیر برنامه هم میخواد که تبدیل بشوند به RGB که لقمه آماده رو براتون گرفتم و فقط کافیه نوش جان کنید !
        به زبان بیسیک هم وقت نداشتم بشینم بیش از حد فکر کنم ... به زبان سی (کدویژن) نوشتم ... ببخشید دیگه ...
        این هم کدش

        کد:
        /*****************************************************
        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 : RGB(By PWM)
        Version :
        Date  : 19/07/2014
        Author : Saman.Asadi
        Company :
        Comments:
        
        
        Chip type        : ATmega64
        Program type      : Application
        AVR Core Clock frequency: 8.000000 MHz
        Memory model      : Small
        External RAM size    : 0
        Data Stack size     : 1024
        *****************************************************/
        #include <mega64a.h>
        #include <delay.h>
        #include <iobits.h>
        
        #define setled1   SETBIT(PORTF,0)
        #define setled2   SETBIT(PORTF,1)
        #define setled3   SETBIT(PORTF,2)
        #define setled4   SETBIT(PORTF,3)
        #define setled5   SETBIT(PORTF,4)
        #define setled6   SETBIT(PORTF,5)
        #define setled7   SETBIT(PORTF,6)
        #define setled8   SETBIT(PORTF,7)
        #define setled9   SETBIT(PORTA,0)
        #define setled10  SETBIT(PORTA,1)
        #define setled11  SETBIT(PORTA,2)
        #define setled12  SETBIT(PORTA,3)
        #define setled13  SETBIT(PORTA,4)
        #define setled14  SETBIT(PORTA,5)
        #define setled15  SETBIT(PORTA,6)
        #define setled16  SETBIT(PORTA,7)
        #define setled17  SETBIT(PORTG,2)
        #define setled18  SETBIT(PORTC,7)
        #define setled19  SETBIT(PORTC,6)
        #define setled20  SETBIT(PORTC,5)
        #define setled21  SETBIT(PORTC,4)
        #define setled22  SETBIT(PORTC,3)
        #define setled23  SETBIT(PORTC,2)
        #define setled24  SETBIT(PORTC,1)
        #define setled25  SETBIT(PORTC,0)
        #define setled26  SETBIT(PORTG,1)
        #define setled27  SETBIT(PORTG,0)
        #define setled28  SETBIT(PORTD,7)
        #define setled29  SETBIT(PORTD,6)
        #define setled30  SETBIT(PORTD,5)
        #define setled31  SETBIT(PORTD,4)
        #define setled32  SETBIT(PORTD,3)
        #define setled33  SETBIT(PORTD,2)
        #define setled34  SETBIT(PORTD,1)
        #define setled35  SETBIT(PORTD,0)
        #define setled36  SETBIT(PORTG,4)
        #define setled37  SETBIT(PORTG,3)
        #define setled38  SETBIT(PORTB,7)
        #define setled39  SETBIT(PORTB,6)
        #define setled40  SETBIT(PORTB,5)
        #define setled41  SETBIT(PORTB,4)
        #define setled42  SETBIT(PORTB,3)
        #define setled43  SETBIT(PORTB,2)
        #define setled44  SETBIT(PORTB,1)
        #define setled45  SETBIT(PORTB,0)
        #define setled46  SETBIT(PORTE,7)
        #define setled47  SETBIT(PORTE,6)
        #define setled48  SETBIT(PORTE,5)
        #define setled49  SETBIT(PORTE,4)
        #define setled50  SETBIT(PORTE,3)
        #define setled51  SETBIT(PORTE,2)
        #define setled52  SETBIT(PORTE,1)
        #define setled53  SETBIT(PORTE,0)
        #define byte    unsigned char
        #define max_var_PWM 7
        //////////////////////////////////////////////////
        byte    a = max_var_PWM;
        byte    pwm[60];
        //////////////////////////////////////////////////
        
        void RGB1(unsigned int color_code_0_To_511)
        {
          pwm[1] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[2] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[3] = color_code_0_To_511 & 0x07;
        }
        void RGB2(unsigned int color_code_0_To_511)
        {
          pwm[4] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[5] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[6] = color_code_0_To_511 & 0x07;
        }
        void RGB3(unsigned int color_code_0_To_511)
        {
          pwm[7] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[8] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[9] = color_code_0_To_511 & 0x07;
        }
        void RGB4(unsigned int color_code_0_To_511)
        {
          pwm[10] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[11] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[12] = color_code_0_To_511 & 0x07;
        }
        void RGB5(unsigned int color_code_0_To_511)
        {
          pwm[13] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[14] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[15] = color_code_0_To_511 & 0x07;
        }
        void RGB6(unsigned int color_code_0_To_511)
        {
          pwm[16] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[17] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[18] = color_code_0_To_511 & 0x07;
        }
        void RGB7(unsigned int color_code_0_To_511)
        {
          pwm[19] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[20] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[21] = color_code_0_To_511 & 0x07;
        }
        void RGB8(unsigned int color_code_0_To_511)
        {
          pwm[22] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[23] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[24] = color_code_0_To_511 & 0x07;
        }
        void RGB9(unsigned int color_code_0_To_511)
        {
          pwm[25] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[26] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[27] = color_code_0_To_511 & 0x07;
        }
        void RGB10(unsigned int color_code_0_To_511)
        {
          pwm[28] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[29] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[30] = color_code_0_To_511 & 0x07;
        }
        void RGB11(unsigned int color_code_0_To_511)
        {
          pwm[31] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[32] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[33] = color_code_0_To_511 & 0x07;
        }
        void RGB12(unsigned int color_code_0_To_511)
        {
          pwm[34] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[35] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[36] = color_code_0_To_511 & 0x07;
        }
        void RGB13(unsigned int color_code_0_To_511)
        {
          pwm[37] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[07] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[39] = color_code_0_To_511 & 0x07;
        }
        void RGB14(unsigned int color_code_0_To_511)
        {
          pwm[40] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[41] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[42] = color_code_0_To_511 & 0x07;
        }
        void RGB15(unsigned int color_code_0_To_511)
        {
          pwm[43] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[44] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[45] = color_code_0_To_511 & 0x07;
        }
        void RGB16(unsigned int color_code_0_To_511)
        {
          pwm[46] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[47] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[48] = color_code_0_To_511 & 0x07;
        }
        void RGB17(unsigned int color_code_0_To_511)
        {
          pwm[49] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[50] = color_code_0_To_511 & 0x07;
          color_code_0_To_511 = color_code_0_To_511 >> 3;
          pwm[51] = color_code_0_To_511 & 0x07;
        }
        
        // 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-- ;
          if(a == 255)
          {
            a = max_var_PWM;
            PORTA=0;
            PORTB=0;
            PORTC=0;
            PORTD=0;
            PORTE=0;
            PORTF=0;
            PORTG=0;
          }
        }
        
        void main(void)
        {
          //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: 125.000 kHz
            // Mode: CTC top=OCR0
            // OC0 output: Disconnected
            ASSR=0x00;
            TCCR0=0x0C;
            TCNT0=0x00;
            OCR0=0x9B;
            // Timer(s)/Counter(s) Interrupt(s) initialization
            TIMSK=0x02;
            // Global enable interrupts
            #asm("sei")
          }
          //End Config ......
          RGB1(0);
          RGB2(30);
          RGB3(60);
          RGB4(90);
          RGB5(120);
          RGB6(150);
          RGB7(180);
          RGB8(210);
          RGB9(240);
          RGB10(270);
          RGB11(300);
          RGB12(330);
          RGB13(360);
          RGB14(390);
          RGB15(420);
          RGB16(450);
          RGB17(480);
        
          while(1)
          {
        
          }
        }
        حافظه زیاد اشغال کردن خیلی مهم نیست ...
        مهم اینه که تلفات پردازشی زیاده و ممکنه که پردازش کم بیاره ....
        نظر من رو میخواین من میگم برید سراغ زبان سی ...
        از همین الان ...

        سوالی بود درخدمتم ...
        موفق باشید
        [hr]
        ============================[tt]اضاف شده[/tt]
        ببخشید دوستان
        به دلیل اشکالات در برنامه نویسی برنامه اصلاح شد
        سلام مهندس

        احوالت ؟؟

        لطف کن و برنامهRGB رو برای میکرو مگا 8 و زبان بیسیک هم بنویس تا ما هم استفاده کنیم ...

        کمک بزرگی میکنی ...

        ممنون
        الـــهی , گـــاهـــی , نــگـــــاهی

        دیدگاه


          پاسخ : چگونه تمام پایه های 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

          امیدوارم خوشتون بیاد
          موفق باشید
          سلام رفیق خسته نباشی اقا میشه همین کد رو برای میکرو های arm بنویسی ؟
          میکرو arm من at91sam7x256 هست میخام تموم پایه هاش بشه pwm امکان داره کمکم کنی؟ با keil میخام دستت درست اگه کمکم کنی

          دیدگاه


            پاسخ : برنامه پیشنهادی برای LED) LED RGB تمام رنگی)

            نوشته اصلی توسط ilion
            سلام مهندس

            احوالت ؟؟

            لطف کن و برنامهRGB رو برای میکرو مگا 8 و زبان بیسیک هم بنویس تا ما هم استفاده کنیم ...

            کمک بزرگی میکنی ...

            ممنون
            به به .... سلام آقا مهدی ...
            خیلی ممنون ... خوبم ...
            شما حالتون چطوره ... عالی هستید ؟؟ :smile:
            به روی چشم ...
            سر فرصت حتما میگذارم ... الان سرم حسابی شلوغه ...
            تا اوایل هفته جدید به یاری خداوند می گذارم ...
            موفق باشید
            ==============================================
            نوشته اصلی توسط anti.dark
            سلام رفیق خسته نباشی اقا میشه همین کد رو برای میکرو های arm بنویسی ؟
            میکرو arm من at91sam7x256 هست میخام تموم پایه هاش بشه pwm امکان داره کمکم کنی؟ با keil میخام دستت درست اگه کمکم کنی
            سلام عزیز
            ممنون ... همچنین ...
            برای میکروهای ARM هم ... باشه به روی چشم ... ولی الان نمیتونم سریع برنامه رو براتون بگذارم ...
            زمان بدید به روی چشم
            با میکروهای ARM که دیگه عالی میشه چون فرکانس بالاست و از طرفی پردازنده 32 بیتی هست ... دیگه خلاصه هلو ....
            دقت PWMها به احتمال زیاد به 8 بیت هم میرسه ... شاید هم بیشتر ... البته بستگی به کابرد داره ...
            موفق باشید
            [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
            معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
            معرفی نرم افزار Codewizard PWM
            با من بیشتر آشنا شوید

            دیدگاه


              پاسخ : برنامه پیشنهادی برای LED) LED RGB تمام رنگی)

              نوشته اصلی توسط سامان اسدی
              به به .... سلام آقا مهدی ...
              خیلی ممنون ... خوبم ...
              شما حالتون چطوره ... عالی هستید ؟؟ :smile:
              به روی چشم ...
              سر فرصت حتما میگذارم ... الان سرم حسابی شلوغه ...
              تا اوایل هفته جدید به یاری خداوند می گذارم ...
              موفق باشید
              ==============================================سلام عزیز
              ممنون ... همچنین ...
              برای میکروهای ARM هم ... باشه به روی چشم ... ولی الان نمیتونم سریع برنامه رو براتون بگذارم ...
              زمان بدید به روی چشم
              با میکروهای ARM که دیگه عالی میشه چون فرکانس بالاست و از طرفی پردازنده 32 بیتی هست ... دیگه خلاصه هلو ....
              دقت PWMها به احتمال زیاد به 8 بیت هم میرسه ... شاید هم بیشتر ... البته بستگی به کابرد داره ...
              موفق باشید
              سلام اگه بتونی تا فردا یه کاریش کنی خیلییی عالی میشه بد جور لنگم اگه این لطف و بکنی خیلی ممنونت میشم رفیق

              دیدگاه


                پاسخ : برنامه پیشنهادی برای LED) LED RGB تمام رنگی)


                به به .... سلام آقا مهدی ...
                خیلی ممنون ... خوبم ...
                شما حالتون چطوره ... عالی هستید ؟؟ :smile:
                به روی چشم ...
                سر فرصت حتما میگذارم ... الان سرم حسابی شلوغه ...
                تا اوایل هفته جدید به یاری خداوند می گذارم ...
                موفق باشید

                [/quote]

                سلام ... سامان خــــان عزیز

                لطف میکنی ... دمت گــــــــــــــــــــــــــــــــرم سالار :applause:

                آقایی



                اضافه شده در تاریخ :
                سلام سامان

                من شاید نزدیک هفت شب بیشتره دائما دارم سر میزنم و خبری ازت نیست ... :cry:

                کجایی برادر ....

                نگرانت شدم

                یاعلی
                الـــهی , گـــاهـــی , نــگـــــاهی

                دیدگاه


                  ساخت 7 RGB و 22 PWM با Mega8 و ساخت 10 RGB و 32 PWM با Mega16,32 (با بسکام)

                  سلام دوستان
                  از این که خیلی دیر به دیر میام سر میزنم عذرخواهی میکنم
                  به درخواست دوست عزیزم آقا مهدی برنامه RGB برای برنامه بسکام هم نوشتم و امیدوارم دوستان از این برنامه لذت ببرند ...

                  برنامه RGB در بسکام (میکروی ATmega8) :
                  [code=qbasic]

                  'Designed by : Saman.Asadi
                  'Date : 1393.08.10 ; 2014.11.01
                  'Made in Iran-Shiraz
                  '============================================ ===========================|
                  'Project1 : 7RGB by (ATmega8) |
                  'Frequency crystal : 2~16MHz |
                  'Frequency PWM : 250Hz |
                  'Number of colors : 512 Colors (0 to 511) |
                  '============================================ ===========================|
                  'Project2 : 22PWM by (ATmega8) |
                  'Frequency crystal : 2~16MHz |
                  'Frequency PWM : 250Hz |
                  'Accuracy PWM : 3bit (0 to 7) |
                  '============================================ ===========================|
                  'if F-CPU= 1MHz And F-PWM=250Hz then Max Processing 43.2 % bad |
                  'if F-CPU= 2MHz And F-PWM=250Hz then Max Processing 21.6 % Medium |
                  'if F-CPU= 4MHz And F-PWM=250Hz then Max Processing 10.8 % good |Data sheet
                  'if F-CPU= 8MHz And F-PWM=250Hz then Max Processing 5.4 % Very good |
                  'if F-CPU=16MHz And F-PWM=250Hz then Max Processing 2.7 % Excellent |
                  '============================================ ===========================|


                  $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 7

                  Dim Pwm(25) As Byte , A As Byte
                  A = Max_var_pwm
                  'Config All =============================================
                  'Config Timers
                  Config Timer2 = Timer , Prescale = 32
                  Enable Compare2
                  On Compare2 T2
                  'Timer / Counter 2 Initialization
                  'Clock source: System Clock
                  'Clock value: 250 kHz
                  'Mode: CTC top=OCR2
                  'OC2 output: Disconnected
                  Tccr2 = 11
                  Ocr2 = 124
                  'for 16MHz OCR0A = 249
                  'for 8 MHz OCR0A = 124
                  'for 4 MHz OCR0A = 61
                  'for 2 MHz OCR0A = 31
                  'for 1 MHz OCR0A = 15
                  'Config Ports
                  Ddrb = 255
                  Ddrc = 63
                  Ddrd = 255
                  ' Global enable interrupts
                  Enable Interrupts
                  'End Config ============================================

                  Declare Sub Rgb1(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb2(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb3(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb4(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb5(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb6(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb7(byval Rgb_0_to_511 As Word)


                  Call Rgb1(70)
                  Call Rgb2(140)
                  Call Rgb3(210)
                  Call Rgb4(280)
                  Call Rgb5(350)
                  Call Rgb6(430)
                  Call Rgb7(510)

                  Do




                  Loop
                  End

                  T2:
                  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

                  Sub Rgb1(byval Rgb_0_to_511 As Word)
                  Pwm(1) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(2) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(3) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb2(byval Rgb_0_to_511 As Word)
                  Pwm(4) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(5) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(6) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb3(byval Rgb_0_to_511 As Word)
                  Pwm(7) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(8) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(9) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb4(byval Rgb_0_to_511 As Word)
                  Pwm(10) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(11) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(12) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb5(byval Rgb_0_to_511 As Word)
                  Pwm(13) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(14) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(15) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb6(byval Rgb_0_to_511 As Word)
                  Pwm(16) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(17) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(18) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb7(byval Rgb_0_to_511 As Word)
                  Pwm(19) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(20) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(21) = Rgb_0_to_511 And 7
                  End Sub
                  [/code]

                  برنامه RGB در بسکام (میکرهای ATmega16,32) :
                  [code=qbasic]

                  'Designed by : Saman.Asadi
                  'Date : 1393.08.10 ; 2014.11.01
                  'Made in Iran-Shiraz
                  '============================================ ===========================|
                  'Project1 : 17RGB by (ATmega16 or ATmega32) |
                  'Frequency crystal : 2~16MHz |
                  'Frequency PWM : 250Hz |
                  'Number of colors : 512 Colors (0 to 511) |
                  '============================================ ===========================|
                  'Project2 : 53PWM by (ATmega16 or ATmega32) |
                  'Frequency crystal : 2~16MHz |
                  'Frequency PWM : 250Hz |
                  'Accuracy PWM : 3bit (0 to 7) |
                  '============================================ ===========================|
                  'if F-CPU= 1MHz And F-PWM=250Hz then Max Processing 60% Bad |
                  'if F-CPU= 2MHz And F-PWM=250Hz then Max Processing 30% Medium |
                  'if F-CPU= 4MHz And F-PWM=250Hz then Max Processing 15% Good | Data sheet
                  'if F-CPU= 8MHz And F-PWM=250Hz then Max Processing 7.5% Very good |
                  'if F-CPU=16MHz And F-PWM=250Hz then Max Processing 3.75% Excellent |
                  '============================================ ===========================|

                  $regfile = "m16def.dat"
                  '$regfile = "m16def.dat" for ATmega16
                  '$regfile = "m32def.dat" for ATmega32
                  $crystal = 8000000

                  Led1 Alias Portb.0
                  Led2 Alias Portb.1
                  Led3 Alias Portb.2
                  Led4 Alias Portb.3
                  Led5 Alias Portb.4
                  Led6 Alias Portb.5
                  Led7 Alias Portb.6
                  Led8 Alias Portb.7
                  Led9 Alias Portd.0
                  Led10 Alias Portd.1
                  Led11 Alias Portd.2
                  Led12 Alias Portd.3
                  Led13 Alias Portd.4
                  Led14 Alias Portd.5
                  Led15 Alias Portd.6
                  Led16 Alias Portd.7
                  Led17 Alias Portc.0
                  Led18 Alias Portc.1
                  Led19 Alias Portc.2
                  Led20 Alias Portc.3
                  Led21 Alias Portc.4
                  Led22 Alias Portc.5
                  Led23 Alias Portc.6
                  Led24 Alias Portc.7
                  Led25 Alias Porta.7
                  Led26 Alias Porta.6
                  Led27 Alias Porta.5
                  Led28 Alias Porta.4
                  Led29 Alias Porta.3
                  Led30 Alias Porta.2
                  Led31 Alias Porta.1
                  Led32 Alias Porta.0
                  Max_var_pwm Alias 7

                  Dim Pwm(35) As Byte , A As Byte
                  A = Max_var_pwm
                  'Config All =============================================
                  'Config Timers
                  Config Timer2 = Timer , Prescale = 32
                  Enable Compare2
                  On Compare2 T2
                  'Timer / Counter 2 Initialization
                  'Clock source: System Clock
                  'Clock value: 250 kHz
                  'Mode: CTC top=OCR2
                  'OC2 output: Disconnected
                  Tccr2 = 11
                  Ocr2 = 124
                  'for 16MHz OCR0A = 249
                  'for 8 MHz OCR0A = 124
                  'for 4 MHz OCR0A = 61
                  'for 2 MHz OCR0A = 31
                  'for 1 MHz OCR0A = 15
                  'Config Ports
                  Ddra = 255
                  Ddrb = 255
                  Ddrc = 255
                  Ddrd = 255
                  ' Global enable interrupts
                  Enable Interrupts
                  'End Config ============================================

                  Declare Sub Rgb1(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb2(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb3(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb4(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb5(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb6(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb7(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb8(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb9(byval Rgb_0_to_511 As Word)
                  Declare Sub Rgb10(byval Rgb_0_to_511 As Word)


                  Call Rgb1(18)
                  Call Rgb2(36)
                  Call Rgb3(54)
                  Call Rgb4(72)
                  Call Rgb5(90)
                  Call Rgb6(108)
                  Call Rgb7(126)
                  Call Rgb8(144)
                  Call Rgb9(162)
                  Call Rgb10(180)


                  Do




                  Loop
                  End

                  T2:
                  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 = 1
                  Portb = 0
                  Portc = 0
                  Portd = 0
                  End If
                  Return

                  Sub Rgb1(byval Rgb_0_to_511 As Word)
                  Pwm(1) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(2) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(3) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb2(byval Rgb_0_to_511 As Word)
                  Pwm(4) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(5) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(6) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb3(byval Rgb_0_to_511 As Word)
                  Pwm(7) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(8) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(9) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb4(byval Rgb_0_to_511 As Word)
                  Pwm(10) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(11) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(12) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb5(byval Rgb_0_to_511 As Word)
                  Pwm(13) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(14) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(15) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb6(byval Rgb_0_to_511 As Word)
                  Pwm(16) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(17) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(18) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb7(byval Rgb_0_to_511 As Word)
                  Pwm(19) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(20) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(21) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb8(byval Rgb_0_to_511 As Word)
                  Pwm(22) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(23) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(24) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb9(byval Rgb_0_to_511 As Word)
                  Pwm(25) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(26) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(27) = Rgb_0_to_511 And 7
                  End Sub

                  Sub Rgb10(byval Rgb_0_to_511 As Word)
                  Pwm(28) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(29) = Rgb_0_to_511 And 7
                  Rgb_0_to_511 = Rgb_0_to_511 / 8
                  Pwm(30) = Rgb_0_to_511 And 7
                  End Sub
                  [/code]
                  [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
                  معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
                  معرفی نرم افزار Codewizard PWM
                  با من بیشتر آشنا شوید

                  دیدگاه


                    ساخت 17 RGB و 53 PWM با میکروهای ATmega64,128 (با کامپایلر بسکام)

                    برنامه RGB در بسکام (میکروهای ATmega 64,128) :
                    [code=qbasic]
                    'Designed by : Saman.Asadi
                    'Date : 1393.08.10 ; 2014.11.01
                    'Made in Iran-Shiraz
                    '============================================ =======================|
                    'Project1 : 17RGB by (ATmega64 or ATmega128) |
                    'Frequency crystal : 16MHz |
                    'Frequency PWM : 250Hz |
                    'Number of colors : 512 Colors (0 to 511) |
                    '============================================ =======================|
                    'Project2 : 53PWM by (ATmega64 or ATmega128) |
                    'Frequency crystal : 16MHz |
                    'Frequency PWM : 250Hz |
                    'Accuracy PWM : 3bit (0 to 7) |
                    '============================================ =======================|
                    'if F-CPU= 2MHz And F-PWM=250Hz then Max Processing 56% bad |
                    'if F-CPU= 4MHz And F-PWM=250Hz then Max Processing 28% medium |
                    'if F-CPU= 8MHz And F-PWM=250Hz then Max Processing 14% good | Data sheet
                    'if F-CPU=16MHz And F-PWM=250Hz then Max Processing 7% very good |
                    '============================================ =======================|

                    $regfile = "m64def.dat"
                    '$regfile = "m64def.dat" for ATmega64
                    '$regfile = "m128def.dat" for ATmega128
                    $crystal = 8000000

                    Led1 Alias Porte.0
                    Led2 Alias Porte.1
                    Led3 Alias Porte.2
                    Led4 Alias Porte.3
                    Led5 Alias Porte.4
                    Led6 Alias Porte.5
                    Led7 Alias Porte.6
                    Led8 Alias Porte.7
                    Led9 Alias Portb.0
                    Led10 Alias Portb.1
                    Led11 Alias Portb.2
                    Led12 Alias Portb.3
                    Led13 Alias Portb.4
                    Led14 Alias Portb.5
                    Led15 Alias Portb.6
                    Led16 Alias Portb.7
                    Led17 Alias Portg.3
                    Led18 Alias Portg.4
                    Led19 Alias Portd.0
                    Led20 Alias Portd.1
                    Led21 Alias Portd.2
                    Led22 Alias Portd.3
                    Led23 Alias Portd.4
                    Led24 Alias Portd.5
                    Led25 Alias Portd.6
                    Led26 Alias Portd.7
                    Led27 Alias Portg.0
                    Led28 Alias Portg.1
                    Led29 Alias Portc.0
                    Led30 Alias Portc.1
                    Led31 Alias Portc.2
                    Led32 Alias Portc.3
                    Led33 Alias Portc.4
                    Led34 Alias Portc.5
                    Led35 Alias Portc.6
                    Led36 Alias Portc.7
                    Led37 Alias Portg.2
                    Led38 Alias Porta.7
                    Led39 Alias Porta.6
                    Led40 Alias Porta.5
                    Led41 Alias Porta.4
                    Led42 Alias Porta.3
                    Led43 Alias Porta.2
                    Led44 Alias Porta.1
                    Led45 Alias Porta.0
                    Led46 Alias Portf.7
                    Led47 Alias Portf.6
                    Led48 Alias Portf.5
                    Led49 Alias Portf.4
                    Led50 Alias Portf.3
                    Led51 Alias Portf.2
                    Led52 Alias Portf.1
                    Led53 Alias Portf.0
                    Max_var_pwm Alias 7

                    Dim Pwm(55) As Byte , A As Byte
                    A = Max_var_pwm
                    'Config All =============================================
                    'Config Timers
                    'Config Ports
                    Config Timer0 = Timer , Prescale = 32
                    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: 125kHz
                    ' Mode: CTC top=OCR0
                    Tccr0 = 11
                    Ocr0 = 124
                    'for 16MHz OCR0A = 124
                    'for 8 MHz OCR0A = 61
                    ' Global enable interrupts
                    Enable Interrupts
                    'End Config ============================================

                    Declare Sub Rgb1(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb2(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb3(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb4(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb5(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb6(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb7(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb8(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb9(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb10(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb11(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb12(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb13(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb14(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb15(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb16(byval Rgb_0_to_511 As Word)
                    Declare Sub Rgb17(byval Rgb_0_to_511 As Word)

                    Call Rgb1(30)
                    Call Rgb2(60)
                    Call Rgb3(90)
                    Call Rgb4(120)
                    Call Rgb5(150)
                    Call Rgb6(180)
                    Call Rgb7(210)
                    Call Rgb8(240)
                    Call Rgb9(270)
                    Call Rgb10(300)
                    Call Rgb11(330)
                    Call Rgb12(360)
                    Call Rgb13(390)
                    Call Rgb14(420)
                    Call Rgb15(450)
                    Call Rgb16(480)
                    Call Rgb17(510)


                    Do

                    Loop
                    End

                    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

                    Sub Rgb1(byval Rgb_0_to_511 As Word)
                    Pwm(1) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(2) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(3) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb2(byval Rgb_0_to_511 As Word)
                    Pwm(4) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(5) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(6) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb3(byval Rgb_0_to_511 As Word)
                    Pwm(7) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(8) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(9) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb4(byval Rgb_0_to_511 As Word)
                    Pwm(10) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(11) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(12) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb5(byval Rgb_0_to_511 As Word)
                    Pwm(13) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(14) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(15) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb6(byval Rgb_0_to_511 As Word)
                    Pwm(16) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(17) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(18) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb7(byval Rgb_0_to_511 As Word)
                    Pwm(19) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(20) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(21) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb8(byval Rgb_0_to_511 As Word)
                    Pwm(22) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(23) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(24) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb9(byval Rgb_0_to_511 As Word)
                    Pwm(25) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(26) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(27) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb10(byval Rgb_0_to_511 As Word)
                    Pwm(28) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(29) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(30) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb11(byval Rgb_0_to_511 As Word)
                    Pwm(31) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(32) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(33) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb12(byval Rgb_0_to_511 As Word)
                    Pwm(34) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(35) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(36) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb13(byval Rgb_0_to_511 As Word)
                    Pwm(37) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(38) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(39) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb14(byval Rgb_0_to_511 As Word)
                    Pwm(40) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(41) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(42) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb15(byval Rgb_0_to_511 As Word)
                    Pwm(43) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(44) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(45) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb16(byval Rgb_0_to_511 As Word)
                    Pwm(46) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(47) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(48) = Rgb_0_to_511 And 7
                    End Sub

                    Sub Rgb17(byval Rgb_0_to_511 As Word)
                    Pwm(49) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(50) = Rgb_0_to_511 And 7
                    Rgb_0_to_511 = Rgb_0_to_511 / 8
                    Pwm(51) = Rgb_0_to_511 And 7
                    End Sub
                    [/code]
                    [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
                    معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
                    معرفی نرم افزار Codewizard PWM
                    با من بیشتر آشنا شوید

                    دیدگاه


                      ساخت 28 RGB و 86 PWM با میکروهای ATmega640,1280,2560 (با بسکام)

                      برنامه RGB در بسکام (میکروهای ATmega 640,1280,2560) :
                      [code=qbasic]

                      'Designed by : Saman.Asadi
                      'Date : 1393.08.10 ; 2014.11.01
                      'Made in Iran-Shiraz
                      '============================================ ===========================|
                      'Project1 : 28RGB by (ATmega640 or ATmega1280 or ATmega2560) |
                      'Frequency crystal : 8~16MHz |
                      'Frequency PWM : 250Hz |
                      'Number of colors : 512 Colors (0 to 511) |
                      '============================================ ===========================|
                      'Project2 : 86PWM by (ATmega640 or ATmega1280 or ATmega2560) |
                      'Frequency crystal : 8~16MHz |
                      'Frequency PWM : 250Hz |
                      'Accuracy PWM : 3bit (0 to 7) |
                      '============================================ ===========================|
                      'if F-CPU= 2MHz And F-PWM=250Hz then Max Processing 88% Very bad |
                      'if F-CPU= 4MHz And F-PWM=250Hz then Max Processing 44% Bad |
                      'if F-CPU= 8MHz And F-PWM=250Hz then Max Processing 22% Medium | Data sheet
                      'if F-CPU=16MHz And F-PWM=250Hz then Max Processing 11% good |
                      '============================================ ===========================|


                      $regfile = "m640def.dat"
                      '$regfile = "m640def.dat" for ATmega640
                      '$regfile = "m1280def.dat" for ATmega1280
                      '$regfile = "m2560def.dat" for ATmega2560
                      $crystal = 16000000

                      Led1 Alias Portg.5
                      Led2 Alias Porte.0
                      Led3 Alias Porte.1
                      Led4 Alias Porte.2
                      Led5 Alias Porte.3
                      Led6 Alias Porte.4
                      Led7 Alias Porte.5
                      Led8 Alias Porte.6
                      Led9 Alias Porte.7
                      Led10 Alias Porth.0
                      Led11 Alias Porth.1
                      Led12 Alias Porth.2
                      Led13 Alias Porth.3
                      Led14 Alias Porth.4
                      Led15 Alias Porth.5
                      Led16 Alias Porth.6
                      Led17 Alias Portb.0
                      Led18 Alias Portb.1
                      Led19 Alias Portb.2
                      Led20 Alias Portb.3
                      Led21 Alias Portb.4
                      Led22 Alias Portb.5
                      Led23 Alias Portb.6
                      Led24 Alias Portb.7
                      Led25 Alias Porth.7
                      Led26 Alias Portg.3
                      Led27 Alias Portg.4
                      Led28 Alias Portl.0
                      Led29 Alias Portl.1
                      Led30 Alias Portl.2
                      Led31 Alias Portl.3
                      Led32 Alias Portl.4
                      Led33 Alias Portl.5
                      Led34 Alias Portl.6
                      Led35 Alias Portl.7
                      Led36 Alias Portd.0
                      Led37 Alias Portd.1
                      Led38 Alias Portd.2
                      Led39 Alias Portd.3
                      Led40 Alias Portd.4
                      Led41 Alias Portd.5
                      Led42 Alias Portd.6
                      Led43 Alias Portd.7
                      Led44 Alias Portg.0
                      Led45 Alias Portg.1
                      Led46 Alias Portc.0
                      Led47 Alias Portc.1
                      Led48 Alias Portc.2
                      Led49 Alias Portc.3
                      Led50 Alias Portc.4
                      Led51 Alias Portc.5
                      Led52 Alias Portc.6
                      Led53 Alias Portc.7
                      Led54 Alias Portj.0
                      Led55 Alias Portj.1
                      Led56 Alias Portj.2
                      Led57 Alias Portj.3
                      Led58 Alias Portj.4
                      Led59 Alias Portj.5
                      Led60 Alias Portj.6
                      Led61 Alias Portg.2
                      Led62 Alias Porta.7
                      Led63 Alias Porta.6
                      Led64 Alias Porta.5
                      Led65 Alias Porta.4
                      Led66 Alias Porta.3
                      Led67 Alias Porta.2
                      Led68 Alias Porta.1
                      Led69 Alias Porta.0
                      Led70 Alias Portj.7
                      Led71 Alias Portk.7
                      Led72 Alias Portk.6
                      Led73 Alias Portk.5
                      Led74 Alias Portk.4
                      Led75 Alias Portk.3
                      Led76 Alias Portk.2
                      Led77 Alias Portk.1
                      Led78 Alias Portk.0
                      Led79 Alias Portf.7
                      Led80 Alias Portf.6
                      Led81 Alias Portf.5
                      Led82 Alias Portf.4
                      Led83 Alias Portf.3
                      Led84 Alias Portf.2
                      Led85 Alias Portf.1
                      Led86 Alias Portf.0
                      Max_var_pwm Alias 7

                      Dim Pwm(90) As Byte , A As Byte
                      A = Max_var_pwm
                      'Config All =============================================
                      'Crystal Oscillator division factor: 1
                      Clkpr = 128
                      Clkpr = 0
                      'Config Timers
                      Config Timer0 = Timer , Prescale = 64
                      Enable Compare0a
                      On Compare0a T0
                      ' Timer/Counter 0 initialization
                      ' Clock source: System Clock
                      ' Clock value: 250 kHz
                      ' Mode: CTC top=OCR0A
                      ' OC0A output: Disconnected
                      ' OC0B output: Disconnected
                      Tccr0a = 2
                      Tccr0b = 3
                      Ocr0a = 124
                      'for 16MHz OCR0A = 124
                      'for 8 MHz OCR0A = 61
                      'Config Ports
                      Ddra = 255
                      Ddrb = 255
                      Ddrc = 255
                      Ddrd = 255
                      Ddre = 255
                      Ddrf = 255
                      Ddrg = 63
                      Ddrh = 255
                      Ddrj = 255
                      Ddrk = 255
                      Ddrl = 255
                      ' Global enable interrupts
                      Enable Interrupts
                      'End Config ============================================

                      Declare Sub Rgb1(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb2(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb3(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb4(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb5(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb6(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb7(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb8(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb9(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb10(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb11(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb12(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb13(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb14(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb15(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb16(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb17(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb18(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb19(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb20(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb21(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb22(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb23(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb24(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb25(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb26(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb27(byval Rgb_0_to_511 As Word)
                      Declare Sub Rgb28(byval Rgb_0_to_511 As Word)

                      Call Rgb1(18)
                      Call Rgb2(36)
                      Call Rgb3(54)
                      Call Rgb4(72)
                      Call Rgb5(90)
                      Call Rgb6(108)
                      Call Rgb7(126)
                      Call Rgb8(144)
                      Call Rgb9(162)
                      Call Rgb10(180)
                      Call Rgb11(198)
                      Call Rgb12(216)
                      Call Rgb13(234)
                      Call Rgb14(252)
                      Call Rgb15(280)
                      Call Rgb16(288)
                      Call Rgb17(306)
                      Call Rgb18(324)
                      Call Rgb19(342)
                      Call Rgb20(360)
                      Call Rgb21(378)
                      Call Rgb22(396)
                      Call Rgb23(414)
                      Call Rgb24(432)
                      Call Rgb25(450)
                      Call Rgb26(468)
                      Call Rgb27(486)
                      Call Rgb28(504)


                      Do




                      Loop
                      End

                      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
                      If A = Pwm(54) Then Led54 = 1
                      If A = Pwm(55) Then Led55 = 1
                      If A = Pwm(56) Then Led56 = 1
                      If A = Pwm(57) Then Led57 = 1
                      If A = Pwm(58) Then Led58 = 1
                      If A = Pwm(59) Then Led59 = 1
                      If A = Pwm(60) Then Led60 = 1
                      If A = Pwm(61) Then Led61 = 1
                      If A = Pwm(62) Then Led62 = 1
                      If A = Pwm(63) Then Led63 = 1
                      If A = Pwm(64) Then Led64 = 1
                      If A = Pwm(65) Then Led65 = 1
                      If A = Pwm(66) Then Led66 = 1
                      If A = Pwm(67) Then Led67 = 1
                      If A = Pwm(68) Then Led68 = 1
                      If A = Pwm(69) Then Led69 = 1
                      If A = Pwm(70) Then Led70 = 1
                      If A = Pwm(71) Then Led71 = 1
                      If A = Pwm(72) Then Led72 = 1
                      If A = Pwm(73) Then Led73 = 1
                      If A = Pwm(74) Then Led74 = 1
                      If A = Pwm(75) Then Led75 = 1
                      If A = Pwm(76) Then Led76 = 1
                      If A = Pwm(77) Then Led77 = 1
                      If A = Pwm(78) Then Led78 = 1
                      If A = Pwm(79) Then Led79 = 1
                      If A = Pwm(80) Then Led80 = 1
                      If A = Pwm(81) Then Led81 = 1
                      If A = Pwm(82) Then Led82 = 1
                      If A = Pwm(83) Then Led83 = 1
                      If A = Pwm(84) Then Led84 = 1
                      If A = Pwm(85) Then Led85 = 1
                      If A = Pwm(86) Then Led86 = 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
                      Porth = 0
                      Portj = 0
                      Portk = 0
                      Portl = 0
                      End If
                      Return

                      Sub Rgb1(byval Rgb_0_to_511 As Word)
                      Pwm(1) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(2) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(3) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb2(byval Rgb_0_to_511 As Word)
                      Pwm(4) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(5) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(6) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb3(byval Rgb_0_to_511 As Word)
                      Pwm(7) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(8) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(9) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb4(byval Rgb_0_to_511 As Word)
                      Pwm(10) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(11) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(12) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb5(byval Rgb_0_to_511 As Word)
                      Pwm(13) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(14) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(15) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb6(byval Rgb_0_to_511 As Word)
                      Pwm(16) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(17) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(18) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb7(byval Rgb_0_to_511 As Word)
                      Pwm(19) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(20) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(21) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb8(byval Rgb_0_to_511 As Word)
                      Pwm(22) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(23) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(24) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb9(byval Rgb_0_to_511 As Word)
                      Pwm(25) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(26) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(27) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb10(byval Rgb_0_to_511 As Word)
                      Pwm(28) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(29) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(30) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb11(byval Rgb_0_to_511 As Word)
                      Pwm(31) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(32) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(33) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb12(byval Rgb_0_to_511 As Word)
                      Pwm(34) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(35) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(36) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb13(byval Rgb_0_to_511 As Word)
                      Pwm(37) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(38) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(39) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb14(byval Rgb_0_to_511 As Word)
                      Pwm(40) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(41) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(42) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb15(byval Rgb_0_to_511 As Word)
                      Pwm(43) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(44) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(45) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb16(byval Rgb_0_to_511 As Word)
                      Pwm(46) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(47) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(48) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb17(byval Rgb_0_to_511 As Word)
                      Pwm(49) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(50) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(51) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb18(byval Rgb_0_to_511 As Word)
                      Pwm(52) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(53) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(54) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb19(byval Rgb_0_to_511 As Word)
                      Pwm(55) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(56) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(57) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb20(byval Rgb_0_to_511 As Word)
                      Pwm(58) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(59) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(60) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb21(byval Rgb_0_to_511 As Word)
                      Pwm(61) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(62) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(63) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb22(byval Rgb_0_to_511 As Word)
                      Pwm(64) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(65) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(66) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb23(byval Rgb_0_to_511 As Word)
                      Pwm(67) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(68) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(69) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb24(byval Rgb_0_to_511 As Word)
                      Pwm(70) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(71) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(72) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb25(byval Rgb_0_to_511 As Word)
                      Pwm(73) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(74) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(75) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb26(byval Rgb_0_to_511 As Word)
                      Pwm(76) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(77) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(78) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb27(byval Rgb_0_to_511 As Word)
                      Pwm(79) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(80) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(81) = Rgb_0_to_511 And 7
                      End Sub

                      Sub Rgb28(byval Rgb_0_to_511 As Word)
                      Pwm(82) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(83) = Rgb_0_to_511 And 7
                      Rgb_0_to_511 = Rgb_0_to_511 / 8
                      Pwm(84) = Rgb_0_to_511 And 7
                      End Sub

                      [/code]

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

                      دیدگاه


                        ساخت 7 RGB و 22 PWM با Mega8 و ساخت 10 RGB و 32 PWM با Mega16,32 (با کدویژن)

                        برنامه RGB در کدویژن (میکروی ATmega8)
                        [code=c]
                        //Designed by : Saman.Asadi
                        //Date : 1393.08.10 ; 2014.11.01
                        //Made in Iran-Shiraz
                        //================================================== ====================|
                        //Project1 : 7RGB by (ATmega8) |
                        //Frequency crystal : 2~16MHz |
                        //Frequency PWM : 250Hz |
                        //Number of colors : 512 Colors (0 to 511) |
                        //================================================== ====================|
                        //Project2 : 22PWM by (ATmega8) |
                        //Frequency crystal : 2~16MHz |
                        //Frequency PWM : 250Hz |
                        //Accuracy PWM : 3bit (0 to 7) |
                        //================================================== ====================|
                        //if F-CPU= 1MHz And F-PWM=250Hz then Max Processing 25.6 % Medium |
                        //if F-CPU= 2MHz And F-PWM=250Hz then Max Processing 12.8 % Good |
                        //if F-CPU= 4MHz And F-PWM=250Hz then Max Processing 6.4 % Very Good | Data sheet
                        //if F-CPU= 8MHz And F-PWM=250Hz then Max Processing 3.2 % Excellent |
                        //if F-CPU=16MHz And F-PWM=250Hz then Max Processing 1.6 % Excellent |
                        //================================================== ====================|

                        #include <mega8.h> //for ATmega8
                        #include <iobits.h>
                        #include <delay.h>

                        #define Set_LED1 SETBIT(PORTD,0)
                        #define Set_LED2 SETBIT(PORTD,1)
                        #define Set_LED3 SETBIT(PORTD,2)
                        #define Set_LED4 SETBIT(PORTD,3)
                        #define Set_LED5 SETBIT(PORTD,4)
                        #define Set_LED6 SETBIT(PORTB,6)
                        #define Set_LED7 SETBIT(PORTB,7)
                        #define Set_LED8 SETBIT(PORTD,5)
                        #define Set_LED9 SETBIT(PORTD,6)
                        #define Set_LED10 SETBIT(PORTD,7)
                        #define Set_LED11 SETBIT(PORTB,0)
                        #define Set_LED12 SETBIT(PORTB,1)
                        #define Set_LED13 SETBIT(PORTB,2)
                        #define Set_LED14 SETBIT(PORTB,3)
                        #define Set_LED15 SETBIT(PORTB,4)
                        #define Set_LED16 SETBIT(PORTB,5)
                        #define Set_LED17 SETBIT(PORTC,0)
                        #define Set_LED18 SETBIT(PORTC,1)
                        #define Set_LED19 SETBIT(PORTC,2)
                        #define Set_LED20 SETBIT(PORTC,3)
                        #define Set_LED21 SETBIT(PORTC,4)
                        #define Set_LED22 SETBIT(PORTC,5)
                        //===============================
                        #define Max_var_PWM 7
                        //===============================
                        unsigned char PWM[25] , A= Max_var_PWM;
                        //===============================
                        void RGB1(unsigned int RGB_0_to_511)
                        {
                        PWM[1] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[2] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[3] = RGB_0_to_511 & 7;
                        }
                        void RGB2(unsigned int RGB_0_to_511)
                        {
                        PWM[4] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[5] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[6] = RGB_0_to_511 & 7;
                        }
                        void RGB3(unsigned int RGB_0_to_511)
                        {
                        PWM[7] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[8] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[9] = RGB_0_to_511 & 7;
                        }
                        void RGB4(unsigned int RGB_0_to_511)
                        {
                        PWM[10] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[11] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[12] = RGB_0_to_511 & 7;
                        }
                        void RGB5(unsigned int RGB_0_to_511)
                        {
                        PWM[13] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[14] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[15] = RGB_0_to_511 & 7;
                        }
                        void RGB6(unsigned int RGB_0_to_511)
                        {
                        PWM[16] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[17] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[18] = RGB_0_to_511 & 7;
                        }
                        void RGB7(unsigned int RGB_0_to_511)
                        {
                        PWM[19] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[20] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[21] = RGB_0_to_511 & 7;
                        }

                        // Timer 2 output compare interrupt service routine
                        interrupt [TIM2_COMP] void timer2_comp_isr(void)
                        {
                        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)
                        {
                        //Config PORTS
                        DDRB = 255;
                        DDRC = 63;
                        DDRD = 255;
                        // Timer/Counter 2 initialization
                        // Clock source: System Clock
                        // Clock value: 250.000 kHz
                        // Mode: CTC top=OCR2
                        // OC2 output: Disconnected
                        TCCR2=0x0B;
                        OCR2=124;
                        //for 16MHz OCR0A=249;
                        //for 8 MHz OCR0A=124;
                        //for 4 MHz OCR0A=62;
                        //for 2 MHz OCR0A=31;
                        // Timer(s)/Counter(s) Interrupt(s) initialization
                        TIMSK=0x80;
                        // Global enable interrupts
                        #asm("sei&quot
                        //==================Start Program
                        RGB1(18);
                        RGB2(36);
                        RGB3(54);
                        RGB4(72);
                        RGB5(90);
                        RGB6(108);
                        RGB7(126);
                        while (1)
                        {


                        }
                        }
                        [/code]

                        برنامه RGB در کدویژن (میکروهای ATmega16,32)
                        [code=c]
                        //Designed by : Saman.Asadi
                        //Date : 1393.08.10 ; 2014.11.01
                        //Made in Iran-Shiraz
                        //================================================== ====================|
                        //Project1 : 10RGB by (ATmega16 or ATmega32) |
                        //Frequency crystal : 2~16MHz |
                        //Frequency PWM : 250Hz |
                        //Number of colors : 512 Colors (0 to 511) |
                        //================================================== ====================|
                        //Project2 : 32PWM by (ATmega16 or ATmega32) |
                        //Frequency crystal : 2~16MHz |
                        //Frequency PWM : 250Hz |
                        //Accuracy PWM : 3bit (0 to 7) |
                        //================================================== ====================|
                        //if F-CPU= 1MHz And F-PWM=250Hz then Max Processing 40.8 % Bad |
                        //if F-CPU= 2MHz And F-PWM=250Hz then Max Processing 20.4 % Medium |
                        //if F-CPU= 4MHz And F-PWM=250Hz then Max Processing 10.2 % Good | Data sheet
                        //if F-CPU= 8MHz And F-PWM=250Hz then Max Processing 5.1 % Very Good |
                        //if F-CPU=16MHz And F-PWM=250Hz then Max Processing 2.55 % Excellent |
                        //================================================== ====================|

                        #include <mega16.h> //for ATmega16
                        //#include <mega32.h> //for ATmega32
                        #include <iobits.h>
                        #include <delay.h>

                        #define Set_LED1 SETBIT(PORTB,0)
                        #define Set_LED2 SETBIT(PORTB,1)
                        #define Set_LED3 SETBIT(PORTB,2)
                        #define Set_LED4 SETBIT(PORTB,3)
                        #define Set_LED5 SETBIT(PORTB,4)
                        #define Set_LED6 SETBIT(PORTB,5)
                        #define Set_LED7 SETBIT(PORTB,6)
                        #define Set_LED8 SETBIT(PORTB,7)
                        #define Set_LED9 SETBIT(PORTD,0)
                        #define Set_LED10 SETBIT(PORTD,1)
                        #define Set_LED11 SETBIT(PORTD,2)
                        #define Set_LED12 SETBIT(PORTD,3)
                        #define Set_LED13 SETBIT(PORTD,4)
                        #define Set_LED14 SETBIT(PORTD,5)
                        #define Set_LED15 SETBIT(PORTD,6)
                        #define Set_LED16 SETBIT(PORTD,7)
                        #define Set_LED17 SETBIT(PORTC,0)
                        #define Set_LED18 SETBIT(PORTC,1)
                        #define Set_LED19 SETBIT(PORTC,2)
                        #define Set_LED20 SETBIT(PORTC,3)
                        #define Set_LED21 SETBIT(PORTC,4)
                        #define Set_LED22 SETBIT(PORTC,5)
                        #define Set_LED23 SETBIT(PORTC,6)
                        #define Set_LED24 SETBIT(PORTC,7)
                        #define Set_LED25 SETBIT(PORTA,7)
                        #define Set_LED26 SETBIT(PORTA,6)
                        #define Set_LED27 SETBIT(PORTA,5)
                        #define Set_LED28 SETBIT(PORTA,4)
                        #define Set_LED29 SETBIT(PORTA,3)
                        #define Set_LED30 SETBIT(PORTA,2)
                        #define Set_LED31 SETBIT(PORTA,1)
                        #define Set_LED32 SETBIT(PORTA,0)
                        //===============================
                        #define Max_var_PWM 7
                        //===============================
                        unsigned char PWM[35] , A= Max_var_PWM;
                        //===============================
                        void RGB1(unsigned int RGB_0_to_511)
                        {
                        PWM[1] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[2] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[3] = RGB_0_to_511 & 7;
                        }
                        void RGB2(unsigned int RGB_0_to_511)
                        {
                        PWM[4] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[5] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[6] = RGB_0_to_511 & 7;
                        }
                        void RGB3(unsigned int RGB_0_to_511)
                        {
                        PWM[7] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[8] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[9] = RGB_0_to_511 & 7;
                        }
                        void RGB4(unsigned int RGB_0_to_511)
                        {
                        PWM[10] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[11] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[12] = RGB_0_to_511 & 7;
                        }
                        void RGB5(unsigned int RGB_0_to_511)
                        {
                        PWM[13] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[14] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[15] = RGB_0_to_511 & 7;
                        }
                        void RGB6(unsigned int RGB_0_to_511)
                        {
                        PWM[16] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[17] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[18] = RGB_0_to_511 & 7;
                        }
                        void RGB7(unsigned int RGB_0_to_511)
                        {
                        PWM[19] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[20] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[21] = RGB_0_to_511 & 7;
                        }
                        void RGB8(unsigned int RGB_0_to_511)
                        {
                        PWM[22] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[23] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[24] = RGB_0_to_511 & 7;
                        }
                        void RGB9(unsigned int RGB_0_to_511)
                        {
                        PWM[25] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[26] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[27] = RGB_0_to_511 & 7;
                        }
                        void RGB10(unsigned int RGB_0_to_511)
                        {
                        PWM[28] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[29] = RGB_0_to_511 & 7;
                        RGB_0_to_511 /= 8;
                        PWM[30] = RGB_0_to_511 & 7;
                        }

                        // Timer 2 output compare interrupt service routine
                        interrupt [TIM2_COMP] void timer2_comp_isr(void)
                        {
                        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 == 255)
                        {
                        A = Max_var_PWM;
                        PORTA = 0;
                        PORTB = 0;
                        PORTC = 0;
                        PORTD = 0;
                        }
                        }

                        void main(void)
                        {
                        //Config PORTS
                        DDRA = 255;
                        DDRB = 255;
                        DDRC = 255;
                        DDRD = 255;
                        // Timer/Counter 2 initialization
                        // Clock source: System Clock
                        // Clock value: 250.000 kHz
                        // Mode: CTC top=OCR2
                        // OC2 output: Disconnected
                        TCCR2=0x0B;
                        OCR2=124;
                        //for 16MHz OCR0A=249;
                        //for 8 MHz OCR0A=124;
                        //for 4 MHz OCR0A=62;
                        //for 2 MHz OCR0A=31;
                        // Timer(s)/Counter(s) Interrupt(s) initialization
                        TIMSK=0x80;
                        // Global enable interrupts
                        #asm("sei&quot
                        //==================Start Program
                        RGB1(18);
                        RGB2(36);
                        RGB3(54);
                        RGB4(72);
                        RGB5(90);
                        RGB6(108);
                        RGB7(126);
                        RGB8(144);
                        RGB9(162);
                        RGB10(180);

                        while (1)
                        {


                        }
                        }

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

                        دیدگاه


                          ساخت 17 RGB و 53 PWM با Mega64,128 (با کامپایلر کدویژن)

                          برنامه RGB در کدویژن (میکروهای ATmega64,128)
                          [code=c]
                          //Designed by : Saman.Asadi
                          //Date : 1393.08.10 ; 2014.11.01
                          //Made in Iran-Shiraz
                          //================================================== ====================|
                          //Project1 : 17RGB by (ATmega64 or ATmega128) |
                          //Frequency crystal : 4~16MHz |
                          //Frequency PWM : 250Hz |
                          //Number of colors : 512 Colors (0 to 511) |
                          //================================================== ====================|
                          //Project2 : 53PWM by (ATmega64 or ATmega128) |
                          //Frequency crystal : 4~16MHz |
                          //Frequency PWM : 250Hz |
                          //Accuracy PWM : 3bit (0 to 7) |
                          //================================================== ====================|
                          //if F-CPU= 1MHz And F-PWM=250Hz then Max Processing 73.6 % Very Bad |
                          //if F-CPU= 2MHz And F-PWM=250Hz then Max Processing 36.8 % Bad |
                          //if F-CPU= 4MHz And F-PWM=250Hz then Max Processing 18.4 % Medium | Data sheet
                          //if F-CPU= 8MHz And F-PWM=250Hz then Max Processing 9.2 % Good |
                          //if F-CPU=16MHz And F-PWM=250Hz then Max Processing 4.6 % Very Good |
                          //================================================== ====================|

                          #include <mega64.h> //for ATmega64
                          //#include <mega128.h> //for ATmega128
                          #include <iobits.h>
                          #include <delay.h>

                          #define Set_LED1 SETBIT(PORTE,0)
                          #define Set_LED2 SETBIT(PORTE,1)
                          #define Set_LED3 SETBIT(PORTE,2)
                          #define Set_LED4 SETBIT(PORTE,3)
                          #define Set_LED5 SETBIT(PORTE,4)
                          #define Set_LED6 SETBIT(PORTE,5)
                          #define Set_LED7 SETBIT(PORTE,6)
                          #define Set_LED8 SETBIT(PORTE,7)
                          #define Set_LED9 SETBIT(PORTB,0)
                          #define Set_LED10 SETBIT(PORTB,1)
                          #define Set_LED11 SETBIT(PORTB,2)
                          #define Set_LED12 SETBIT(PORTB,3)
                          #define Set_LED13 SETBIT(PORTB,4)
                          #define Set_LED14 SETBIT(PORTB,5)
                          #define Set_LED15 SETBIT(PORTB,6)
                          #define Set_LED16 SETBIT(PORTB,7)
                          #define Set_LED17 SETBIT(PORTG,3)
                          #define Set_LED18 SETBIT(PORTG,4)
                          #define Set_LED19 SETBIT(PORTD,0)
                          #define Set_LED20 SETBIT(PORTD,1)
                          #define Set_LED21 SETBIT(PORTD,2)
                          #define Set_LED22 SETBIT(PORTD,3)
                          #define Set_LED23 SETBIT(PORTD,4)
                          #define Set_LED24 SETBIT(PORTD,5)
                          #define Set_LED25 SETBIT(PORTD,6)
                          #define Set_LED26 SETBIT(PORTD,7)
                          #define Set_LED27 SETBIT(PORTG,0)
                          #define Set_LED28 SETBIT(PORTG,1)
                          #define Set_LED29 SETBIT(PORTC,0)
                          #define Set_LED30 SETBIT(PORTC,1)
                          #define Set_LED31 SETBIT(PORTC,2)
                          #define Set_LED32 SETBIT(PORTC,3)
                          #define Set_LED33 SETBIT(PORTC,4)
                          #define Set_LED34 SETBIT(PORTC,5)
                          #define Set_LED35 SETBIT(PORTC,6)
                          #define Set_LED36 SETBIT(PORTC,7)
                          #define Set_LED37 SETBIT(PORTG,2)
                          #define Set_LED38 SETBIT(PORTA,7)
                          #define Set_LED39 SETBIT(PORTA,6)
                          #define Set_LED40 SETBIT(PORTA,5)
                          #define Set_LED41 SETBIT(PORTA,4)
                          #define Set_LED42 SETBIT(PORTA,3)
                          #define Set_LED43 SETBIT(PORTA,2)
                          #define Set_LED44 SETBIT(PORTA,1)
                          #define Set_LED45 SETBIT(PORTA,0)
                          #define Set_LED46 SETBIT(PORTF,7)
                          #define Set_LED47 SETBIT(PORTF,6)
                          #define Set_LED48 SETBIT(PORTF,5)
                          #define Set_LED49 SETBIT(PORTF,4)
                          #define Set_LED50 SETBIT(PORTF,3)
                          #define Set_LED51 SETBIT(PORTF,2)
                          #define Set_LED52 SETBIT(PORTF,1)
                          #define Set_LED53 SETBIT(PORTF,0)
                          //===============================
                          #define Max_var_PWM 7
                          //===============================
                          unsigned char PWM[60] , A= Max_var_PWM;
                          //===============================
                          void RGB1(unsigned int RGB_0_to_511)
                          {
                          PWM[1] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[2] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[3] = RGB_0_to_511 & 7;
                          }
                          void RGB2(unsigned int RGB_0_to_511)
                          {
                          PWM[4] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[5] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[6] = RGB_0_to_511 & 7;
                          }
                          void RGB3(unsigned int RGB_0_to_511)
                          {
                          PWM[7] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[8] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[9] = RGB_0_to_511 & 7;
                          }
                          void RGB4(unsigned int RGB_0_to_511)
                          {
                          PWM[10] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[11] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[12] = RGB_0_to_511 & 7;
                          }
                          void RGB5(unsigned int RGB_0_to_511)
                          {
                          PWM[13] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[14] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[15] = RGB_0_to_511 & 7;
                          }
                          void RGB6(unsigned int RGB_0_to_511)
                          {
                          PWM[16] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[17] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[18] = RGB_0_to_511 & 7;
                          }
                          void RGB7(unsigned int RGB_0_to_511)
                          {
                          PWM[19] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[20] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[21] = RGB_0_to_511 & 7;
                          }
                          void RGB8(unsigned int RGB_0_to_511)
                          {
                          PWM[22] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[23] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[24] = RGB_0_to_511 & 7;
                          }
                          void RGB9(unsigned int RGB_0_to_511)
                          {
                          PWM[25] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[26] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[27] = RGB_0_to_511 & 7;
                          }
                          void RGB10(unsigned int RGB_0_to_511)
                          {
                          PWM[28] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[29] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[30] = RGB_0_to_511 & 7;
                          }
                          void RGB11(unsigned int RGB_0_to_511)
                          {
                          PWM[31] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[32] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[33] = RGB_0_to_511 & 7;
                          }
                          void RGB12(unsigned int RGB_0_to_511)
                          {
                          PWM[34] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[35] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[36] = RGB_0_to_511 & 7;
                          }
                          void RGB13(unsigned int RGB_0_to_511)
                          {
                          PWM[37] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[38] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[39] = RGB_0_to_511 & 7;
                          }
                          void RGB14(unsigned int RGB_0_to_511)
                          {
                          PWM[40] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[41] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[42] = RGB_0_to_511 & 7;
                          }
                          void RGB15(unsigned int RGB_0_to_511)
                          {
                          PWM[43] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[44] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[45] = RGB_0_to_511 & 7;
                          }
                          void RGB16(unsigned int RGB_0_to_511)
                          {
                          PWM[46] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[47] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[48] = RGB_0_to_511 & 7;
                          }
                          void RGB17(unsigned int RGB_0_to_511)
                          {
                          PWM[49] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[50] = RGB_0_to_511 & 7;
                          RGB_0_to_511 /= 8;
                          PWM[51] = RGB_0_to_511 & 7;
                          }

                          // Timer 0 output compare interrupt service routine
                          interrupt [TIM0_COMP] void timer0_comp_isr(void)
                          {
                          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 ;
                          }
                          if(--A == 255)
                          {
                          A = Max_var_PWM;
                          PORTA = 0;
                          PORTB = 0;
                          PORTC = 0;
                          PORTD = 0;
                          PORTE = 0;
                          PORTF = 0;
                          PORTG = 0;
                          }
                          }

                          void main(void)
                          {
                          //Config PORTS
                          DDRA = 255;
                          DDRB = 255;
                          DDRC = 255;
                          DDRD = 255;
                          DDRE = 255;
                          DDRF = 255;
                          DDRG = 63 ;
                          // Timer/Counter 0 initialization
                          // Clock source: System Clock
                          // Clock value: 250.000 kHz
                          // Mode: CTC top=OCR0
                          // OC0 output: Disconnected
                          TCCR0=0x0B;
                          OCR0=124;
                          //for 16MHz OCR0A=249;
                          //for 8 MHz OCR0A=124;
                          //for 4 MHz OCR0A=62;
                          //for 2 MHz OCR0A=31;
                          // Timer(s)/Counter(s) Interrupt(s) initialization
                          TIMSK=2;
                          // Global enable interrupts
                          #asm("sei&quot
                          //==================Start Program
                          RGB1(30);
                          RGB2(60);
                          RGB3(90);
                          RGB4(120);
                          RGB5(150);
                          RGB6(180);
                          RGB7(210);
                          RGB8(240);
                          RGB9(270);
                          RGB10(300);
                          RGB11(330);
                          RGB12(360);
                          RGB13(390);
                          RGB14(420);
                          RGB15(450);
                          RGB16(480);
                          RGB17(510);

                          while (1)
                          {


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

                          دیدگاه


                            ساخت 28 RGB و 86 PWM با Mega640,1280,2560 (با کامپایلر کدویژن)

                            برنامه RGB در کدویژن (میکروهای ATmega640,1280,2560)
                            [code=c]
                            //Designed by : Saman.Asadi
                            //Date : 1393.08.10 ; 2014.11.01
                            //Made in Iran-Shiraz
                            //================================================== ====================|
                            //Project1 : 28RGB by (ATmega640 or ATmega1280 or ATmega2560) |
                            //Frequency crystal : 8~16MHz |
                            //Frequency PWM : 250Hz |
                            //Number of colors : 512 Colors (0 to 511) |
                            //================================================== ====================|
                            //Project2 : 86PWM by (ATmega640 or ATmega1280 or ATmega2560) |
                            //Frequency crystal : 8~16MHz |
                            //Frequency PWM : 250Hz |
                            //Accuracy PWM : 3bit (0 to 7) |
                            //================================================== ====================|
                            //if F-CPU= 2MHz And F-PWM=250Hz then Max Processing 62.8 % Very bad |
                            //if F-CPU= 4MHz And F-PWM=250Hz then Max Processing 31.4 % Medium |
                            //if F-CPU= 8MHz And F-PWM=250Hz then Max Processing 15.7 % good | Data sheet
                            //if F-CPU=16MHz And F-PWM=250Hz then Max Processing 7.85 % very good |
                            //================================================== ====================|

                            #include <mega640.h> //for ATmega640
                            //#include <mega1280.h> //for ATmega1280
                            //#include <mega2560.h> //for ATmega2560
                            #include <iobits.h>
                            #include <delay.h>

                            #define Set_LED1 SETBIT(PORTG,5)
                            #define Set_LED2 SETBIT(PORTE,0)
                            #define Set_LED3 SETBIT(PORTE,1)
                            #define Set_LED4 SETBIT(PORTE,2)
                            #define Set_LED5 SETBIT(PORTE,3)
                            #define Set_LED6 SETBIT(PORTE,4)
                            #define Set_LED7 SETBIT(PORTE,5)
                            #define Set_LED8 SETBIT(PORTE,6)
                            #define Set_LED9 SETBIT(PORTE,7)
                            #define Set_LED10 SETBIT(PORTH,0)
                            #define Set_LED11 SETBIT(PORTH,1)
                            #define Set_LED12 SETBIT(PORTH,2)
                            #define Set_LED13 SETBIT(PORTH,3)
                            #define Set_LED14 SETBIT(PORTH,4)
                            #define Set_LED15 SETBIT(PORTH,5)
                            #define Set_LED16 SETBIT(PORTH,6)
                            #define Set_LED17 SETBIT(PORTB,0)
                            #define Set_LED18 SETBIT(PORTB,1)
                            #define Set_LED19 SETBIT(PORTB,2)
                            #define Set_LED20 SETBIT(PORTB,3)
                            #define Set_LED21 SETBIT(PORTB,4)
                            #define Set_LED22 SETBIT(PORTB,5)
                            #define Set_LED23 SETBIT(PORTB,6)
                            #define Set_LED24 SETBIT(PORTB,7)
                            #define Set_LED25 SETBIT(PORTH,7)
                            #define Set_LED26 SETBIT(PORTG,3)
                            #define Set_LED27 SETBIT(PORTG,4)
                            #define Set_LED28 SETBIT(PORTL,0)
                            #define Set_LED29 SETBIT(PORTL,1)
                            #define Set_LED30 SETBIT(PORTL,2)
                            #define Set_LED31 SETBIT(PORTL,3)
                            #define Set_LED32 SETBIT(PORTL,4)
                            #define Set_LED33 SETBIT(PORTL,5)
                            #define Set_LED34 SETBIT(PORTL,6)
                            #define Set_LED35 SETBIT(PORTL,7)
                            #define Set_LED36 SETBIT(PORTD,0)
                            #define Set_LED37 SETBIT(PORTD,1)
                            #define Set_LED38 SETBIT(PORTD,2)
                            #define Set_LED39 SETBIT(PORTD,3)
                            #define Set_LED40 SETBIT(PORTD,4)
                            #define Set_LED41 SETBIT(PORTD,5)
                            #define Set_LED42 SETBIT(PORTD,6)
                            #define Set_LED43 SETBIT(PORTD,7)
                            #define Set_LED44 SETBIT(PORTG,0)
                            #define Set_LED45 SETBIT(PORTG,1)
                            #define Set_LED46 SETBIT(PORTC,0)
                            #define Set_LED47 SETBIT(PORTC,1)
                            #define Set_LED48 SETBIT(PORTC,2)
                            #define Set_LED49 SETBIT(PORTC,3)
                            #define Set_LED50 SETBIT(PORTC,4)
                            #define Set_LED51 SETBIT(PORTC,5)
                            #define Set_LED52 SETBIT(PORTC,6)
                            #define Set_LED53 SETBIT(PORTC,7)
                            #define Set_LED54 SETBIT(PORTJ,0)
                            #define Set_LED55 SETBIT(PORTJ,1)
                            #define Set_LED56 SETBIT(PORTJ,2)
                            #define Set_LED57 SETBIT(PORTJ,3)
                            #define Set_LED58 SETBIT(PORTJ,4)
                            #define Set_LED59 SETBIT(PORTJ,5)
                            #define Set_LED60 SETBIT(PORTJ,6)
                            #define Set_LED61 SETBIT(PORTG,2)
                            #define Set_LED62 SETBIT(PORTA,7)
                            #define Set_LED63 SETBIT(PORTA,6)
                            #define Set_LED64 SETBIT(PORTA,5)
                            #define Set_LED65 SETBIT(PORTA,4)
                            #define Set_LED66 SETBIT(PORTA,3)
                            #define Set_LED67 SETBIT(PORTA,2)
                            #define Set_LED68 SETBIT(PORTA,1)
                            #define Set_LED69 SETBIT(PORTA,0)
                            #define Set_LED70 SETBIT(PORTJ,7)
                            #define Set_LED71 SETBIT(PORTK,7)
                            #define Set_LED72 SETBIT(PORTK,6)
                            #define Set_LED73 SETBIT(PORTK,5)
                            #define Set_LED74 SETBIT(PORTK,4)
                            #define Set_LED75 SETBIT(PORTK,3)
                            #define Set_LED76 SETBIT(PORTK,2)
                            #define Set_LED77 SETBIT(PORTK,1)
                            #define Set_LED78 SETBIT(PORTK,0)
                            #define Set_LED79 SETBIT(PORTF,7)
                            #define Set_LED80 SETBIT(PORTF,6)
                            #define Set_LED81 SETBIT(PORTF,5)
                            #define Set_LED82 SETBIT(PORTF,4)
                            #define Set_LED83 SETBIT(PORTF,3)
                            #define Set_LED84 SETBIT(PORTF,2)
                            #define Set_LED85 SETBIT(PORTF,1)
                            #define Set_LED86 SETBIT(PORTF,0)
                            //===============================
                            #define Max_var_PWM 7
                            //===============================
                            unsigned char PWM[90] , A= Max_var_PWM;
                            //===============================
                            void RGB1(unsigned int RGB_0_to_511)
                            {
                            PWM[1] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[2] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[3] = RGB_0_to_511 & 7;
                            }
                            void RGB2(unsigned int RGB_0_to_511)
                            {
                            PWM[4] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[5] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[6] = RGB_0_to_511 & 7;
                            }
                            void RGB3(unsigned int RGB_0_to_511)
                            {
                            PWM[7] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[8] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[9] = RGB_0_to_511 & 7;
                            }
                            void RGB4(unsigned int RGB_0_to_511)
                            {
                            PWM[10] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[11] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[12] = RGB_0_to_511 & 7;
                            }
                            void RGB5(unsigned int RGB_0_to_511)
                            {
                            PWM[13] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[14] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[15] = RGB_0_to_511 & 7;
                            }
                            void RGB6(unsigned int RGB_0_to_511)
                            {
                            PWM[16] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[17] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[18] = RGB_0_to_511 & 7;
                            }
                            void RGB7(unsigned int RGB_0_to_511)
                            {
                            PWM[19] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[20] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[21] = RGB_0_to_511 & 7;
                            }
                            void RGB8(unsigned int RGB_0_to_511)
                            {
                            PWM[22] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[23] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[24] = RGB_0_to_511 & 7;
                            }
                            void RGB9(unsigned int RGB_0_to_511)
                            {
                            PWM[25] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[26] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[27] = RGB_0_to_511 & 7;
                            }
                            void RGB10(unsigned int RGB_0_to_511)
                            {
                            PWM[28] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[29] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[30] = RGB_0_to_511 & 7;
                            }
                            void RGB11(unsigned int RGB_0_to_511)
                            {
                            PWM[31] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[32] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[33] = RGB_0_to_511 & 7;
                            }
                            void RGB12(unsigned int RGB_0_to_511)
                            {
                            PWM[34] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[35] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[36] = RGB_0_to_511 & 7;
                            }
                            void RGB13(unsigned int RGB_0_to_511)
                            {
                            PWM[37] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[38] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[39] = RGB_0_to_511 & 7;
                            }
                            void RGB14(unsigned int RGB_0_to_511)
                            {
                            PWM[40] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[41] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[42] = RGB_0_to_511 & 7;
                            }
                            void RGB15(unsigned int RGB_0_to_511)
                            {
                            PWM[43] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[44] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[45] = RGB_0_to_511 & 7;
                            }
                            void RGB16(unsigned int RGB_0_to_511)
                            {
                            PWM[46] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[47] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[48] = RGB_0_to_511 & 7;
                            }
                            void RGB17(unsigned int RGB_0_to_511)
                            {
                            PWM[49] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[50] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[51] = RGB_0_to_511 & 7;
                            }
                            void RGB18(unsigned int RGB_0_to_511)
                            {
                            PWM[52] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[53] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[54] = RGB_0_to_511 & 7;
                            }
                            void RGB19(unsigned int RGB_0_to_511)
                            {
                            PWM[55] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[56] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[57] = RGB_0_to_511 & 7;
                            }
                            void RGB20(unsigned int RGB_0_to_511)
                            {
                            PWM[58] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[59] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[60] = RGB_0_to_511 & 7;
                            }
                            void RGB21(unsigned int RGB_0_to_511)
                            {
                            PWM[61] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[62] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[63] = RGB_0_to_511 & 7;
                            }
                            void RGB22(unsigned int RGB_0_to_511)
                            {
                            PWM[64] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[65] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[66] = RGB_0_to_511 & 7;
                            }
                            void RGB23(unsigned int RGB_0_to_511)
                            {
                            PWM[67] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[68] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[69] = RGB_0_to_511 & 7;
                            }
                            void RGB24(unsigned int RGB_0_to_511)
                            {
                            PWM[70] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[71] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[72] = RGB_0_to_511 & 7;
                            }
                            void RGB25(unsigned int RGB_0_to_511)
                            {
                            PWM[73] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[74] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[75] = RGB_0_to_511 & 7;
                            }
                            void RGB26(unsigned int RGB_0_to_511)
                            {
                            PWM[76] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[77] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[78] = RGB_0_to_511 & 7;
                            }
                            void RGB27(unsigned int RGB_0_to_511)
                            {
                            PWM[79] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[80] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[81] = RGB_0_to_511 & 7;
                            }
                            void RGB28(unsigned int RGB_0_to_511)
                            {
                            PWM[82] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[83] = RGB_0_to_511 & 7;
                            RGB_0_to_511 /= 8;
                            PWM[84] = RGB_0_to_511 & 7;
                            }
                            // Timer 0 output compare A interrupt service routine
                            interrupt [TIM0_COMPA] void timer0_compa_isr(void)
                            {
                            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 ;
                            if(A==PWM[54]) Set_LED54 ;
                            if(A==PWM[55]) Set_LED55 ;
                            if(A==PWM[56]) Set_LED56 ;
                            if(A==PWM[57]) Set_LED57 ;
                            if(A==PWM[58]) Set_LED58 ;
                            if(A==PWM[59]) Set_LED59 ;
                            if(A==PWM[60]) Set_LED60 ;
                            if(A==PWM[61]) Set_LED61 ;
                            if(A==PWM[62]) Set_LED62 ;
                            if(A==PWM[63]) Set_LED63 ;
                            if(A==PWM[64]) Set_LED64 ;
                            if(A==PWM[65]) Set_LED65 ;
                            if(A==PWM[66]) Set_LED66 ;
                            if(A==PWM[67]) Set_LED67 ;
                            if(A==PWM[68]) Set_LED68 ;
                            if(A==PWM[69]) Set_LED69 ;
                            if(A==PWM[70]) Set_LED70 ;
                            if(A==PWM[71]) Set_LED71 ;
                            if(A==PWM[72]) Set_LED72 ;
                            if(A==PWM[73]) Set_LED73 ;
                            if(A==PWM[74]) Set_LED74 ;
                            if(A==PWM[75]) Set_LED75 ;
                            if(A==PWM[76]) Set_LED76 ;
                            if(A==PWM[77]) Set_LED77 ;
                            if(A==PWM[78]) Set_LED78 ;
                            if(A==PWM[79]) Set_LED79 ;
                            if(A==PWM[80]) Set_LED80 ;
                            if(A==PWM[81]) Set_LED81 ;
                            if(A==PWM[82]) Set_LED82 ;
                            if(A==PWM[83]) Set_LED83 ;
                            if(A==PWM[84]) Set_LED84 ;
                            if(A==PWM[85]) Set_LED85 ;
                            if(A==PWM[86]) Set_LED86 ;
                            }
                            if(--A == 255)
                            {
                            A = Max_var_PWM;
                            PORTA = 0;
                            PORTB = 0;
                            PORTC = 0;
                            PORTD = 0;
                            PORTE = 0;
                            PORTF = 0;
                            PORTG = 0;
                            PORTH = 0;
                            PORTJ = 0;
                            PORTK = 0;
                            PORTL = 0;
                            }
                            }

                            void main(void)
                            {
                            // Crystal Oscillator division factor: 1
                            #pragma optsize-
                            CLKPR=0x80;
                            CLKPR=0x00;
                            #ifdef _OPTIMIZE_SIZE_
                            #pragma optsize+
                            #endif
                            //Config PORTS
                            DDRA = 255;
                            DDRB = 255;
                            DDRC = 255;
                            DDRD = 255;
                            DDRE = 255;
                            DDRF = 255;
                            DDRG = 63 ;
                            DDRH = 255;
                            DDRJ = 255;
                            DDRK = 255;
                            DDRL = 255;
                            // Timer/Counter 0 initialization
                            // Clock source: System Clock
                            // Clock value: 125.000 kHz
                            // Mode: CTC top=OCR0A
                            // OC0A output: Disconnected
                            // OC0B output: Disconnected
                            TCCR0A=0x02;
                            TCCR0B=0x03;
                            OCR0A=62;
                            //for 16MHz OCR0A=124;
                            //for 8 MHz OCR0A=62;
                            //for 4 MHz OCR0A=31;
                            // Timer/Counter 0 Interrupt(s) initialization
                            TIMSK0=0x02;
                            // Global enable interrupts
                            #asm("sei&quot
                            //==================Start Program
                            RGB1(18);
                            RGB2(36);
                            RGB3(54);
                            RGB4(72);
                            RGB5(90);
                            RGB6(108);
                            RGB7(126);
                            RGB8(144);
                            RGB9(162);
                            RGB10(180);
                            RGB11(198);
                            RGB12(216);
                            RGB13(234);
                            RGB14(252);
                            RGB15(280);
                            RGB16(288);
                            RGB17(306);
                            RGB18(324);
                            RGB19(342);
                            RGB20(360);
                            RGB21(378);
                            RGB22(396);
                            RGB23(414);
                            RGB24(432);
                            RGB25(450);
                            RGB26(468);
                            RGB27(486);
                            RGB28(504);

                            while (1)
                            {


                            }
                            }
                            [/code]

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

                            دیدگاه


                              پاسخ : چگونه همه پایه های128و64و32و16وATmega8 را PWM کنیم؟؟ پروژه LED RGB اضاف شد!

                              سلام سامان جان

                              احوالت ؟ ایام سوگواری امام حسین رو به شما و همه دوستان تسلیت عرض میکنم

                              ببخش اینقدر مزاحم شما میشم

                              راستش من برنامه RGB به زبان بیسیک برای مگا8 رو داخل بسکام کامپایلش کردم

                              ولی سخت افزاریشو یه کم گیج شدم که چطور تست کنم

                              لطف میکنی یک توضیح بدی که چطوری باید عمل کرد ؟

                              لطف میکنی

                              ممنونم از محبتد @};-

                              الـــهی , گـــاهـــی , نــگـــــاهی

                              دیدگاه


                                چگونگی راه اندازی RGB

                                نوشته اصلی توسط ilion
                                سلام سامان جان
                                احوالت ؟ ایام سوگواری امام حسین رو به شما و همه دوستان تسلیت عرض میکنم
                                ببخش اینقدر مزاحم شما میشم
                                راستش من برنامه RGB به زبان بیسیک برای مگا8 رو داخل بسکام کامپایلش کردم
                                ولی سخت افزاریشو یه کم گیج شدم که چطور تست کنم
                                لطف میکنی یک توضیح بدی که چطوری باید عمل کرد ؟
                                لطف میکنی
                                ممنونم از محبتد @};-
                                سلام
                                خیلی ممنونم ... خیلــــــــــی خـــــــــــوبــــــم ...
                                من هم به نوبت خودم این روز بزرگ را به همه دوستان تسلیت میگم ... و امیدوارم که همه ما راهشان را ادامه دهیم ... :redface:

                                آخ آخ آخ ....
                                این همه برنامه گذاشتم ولی یه توضیح مختصر ندادم ...
                                ببینید دوستان
                                این برنامه هایی که گذاشتم کار کردن با اون خیلی آسونه
                                بسته به کارتون برنامه و سخت افزار متنوعی میشه طراحی کرد ولی این توضیحی که الان میدم متوجه برنامه میشوید
                                اگر میخواهید از RGB استفاده کنید باید زیر برنامه RGB را صدا کنید و ورودی آن را با توجه به طیف رنگی که میخواهیم آن را تعیین میکنیم ... این را باید حتما در عمل دید که چه رنگی به دست می آید .
                                اول اینکه این رو بگم که RGB از سه رنگ تشکیل شده ( آبی و قرمز و سبز) و اگر هر کدوم از این سه تا نور ، کم یا زیاد شوند رنگهای مختلفی ایجاد می کند . پس باید 3تا PWM ای که برای RGB استفاده میشود حتما در زیر برنامه تعیین شود ...
                                به عنوان مثال ()RGB1 که تشکیل شده از [1]PWM و [2]PWM و [3]PWM است .
                                و اگر دقت کرده باشید در برنامه میکروی ATmega8 پایه دو [1]PWM و پایه سه [2]PWM و پایه چهارم [3]PWM را تولید میکند که باید سه تا پایه آند RGB LED را به این پایه های 2و3و4 میکرو وصل گردد و پایه یا پایه های کاتد را به زمین متصل کرد .
                                با تغییر ورودی در زیر برنامه RGB1 رنگ آن مشخص میشود ...
                                توجه داشته باشید که اگر از RGB استفاده میکنید نباید PWM هایی که در زیر برنامه هستند تغییر داد زیرا رنگ به هم میخورد ...
                                امیدوارم که خوب توضیح داده باشم ...
                                [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
                                معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
                                معرفی نرم افزار Codewizard PWM
                                با من بیشتر آشنا شوید

                                دیدگاه

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