پاسخ : چگونه تمام پایه های ATmega16-32-64-128 را PWM کنیم ؟؟!!! [آموزشی]
سامان جان سلام
کدش رو با کمی تغییر تو تاخیر و... ویرایش کردم
مدارش رو بستم ولی انگار پورت c.0 تا c.3 یک مقداری نا هماهنگن و زودتر از c.4 و c.5 خاموش میشه !
البته وقتی با Power LED روشنش کردم انگار مشکلش حل شد .
فیلم هر دوتاشو پلود کردم.
http://m2007.persiangig.com/video/LED.flv
http://m2007.persiangig.com/video/POWER.flv
سامان جان سلام
کدش رو با کمی تغییر تو تاخیر و... ویرایش کردم
کد:
#include <mega8.h>
#include <delay.h>
#define Set_LED1 PORTC.5 = 1
#define Set_LED2 PORTC.4 = 1
#define Set_LED3 PORTC.3 = 1
#define Set_LED4 PORTC.2 = 1
#define Set_LED5 PORTC.1 = 1
#define Set_LED6 PORTC.0 = 1
#define Set_LED7 PORTB.5 = 1
#define Set_LED8 PORTB.4 = 1
#define Set_LED9 PORTB.3 = 1
#define Set_LED10 PORTB.2 = 1
#define Set_LED11 PORTB.1 = 1
#define Set_LED12 PORTB.0 = 1
#define Set_LED13 PORTD.7 = 1
#define Set_LED14 PORTD.6 = 1
#define byte unsigned char
#define max_var_PWM 80
byte a = max_var_PWM , pwm[25];
flash byte rain1[25]=
{200,150,100,80,60,40,20,15,9,7,5,3,1};
interrupt [TIM0_OVF] void timer0_comp_isr(void)
{
TCNT0 = 105;
if(a)
{
if(a == pwm[1] )Set_LED14;
if(a == pwm[2] )Set_LED13;
if(a == pwm[3] )Set_LED12;
if(a == pwm[4] )Set_LED11;
if(a == pwm[5] )Set_LED10;
if(a == pwm[6] )Set_LED9;
if(a == pwm[7] )Set_LED8;
if(a == pwm[8] )Set_LED7;
if(a == pwm[9] )Set_LED6;
if(a == pwm[10])Set_LED5;
if(a == pwm[11])Set_LED4;
if(a == pwm[12])Set_LED3;
if(a == pwm[13])Set_LED2;
if(a == pwm[14])Set_LED1;
}
if(--a == 255)
{ a = max_var_PWM;
PORTB=0;
PORTC=0;
PORTD=0;
}
}
void main(void)
{
byte x1,x2;
//Config all
//Config timers
//Config PORTS
{
DDRB=255;
DDRC=255;
DDRD=255;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 1000.000 kHz
TCNT0=105;
TCCR0=2;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=1;
// Global enable interrupts
#asm("sei")
}
//End Config ......
while(1)
{
for(x1=0;x1<22;x1++)
{
pwm[1]=rain1[x1];
for(x2=21;x2>0;x2--)pwm[x2+1]=pwm[x2];
delay_ms(48);
}
for(x1=0;x1<32;x1++)
{
for(x2=31;x2>0;x2--)pwm[x2+1]=pwm[x2];
delay_ms(10);
}
}
}
البته وقتی با Power LED روشنش کردم انگار مشکلش حل شد .
فیلم هر دوتاشو پلود کردم.
http://m2007.persiangig.com/video/LED.flv
http://m2007.persiangig.com/video/POWER.flv









دیدگاه