// RGB LEDni boshqarish. PWM uchun dasturiy ta'minot
#include
#include
volatile char pwm_counter,pwm_r,pwm_g,pwm_b;
// T0 to‘lib ketganda uzilish
ISR (TIMER0_OVF_vect)
{
if (pwm_counter++ > 163)
{
PORTB = 0x00;
pwm_counter = 0;
}
if (pwm_counter > pwm_r) PORTB |= (1 << PB1);
if (pwm_counter > pwm_g) PORTB |= (1 << PB2);
if (pwm_counter > pwm_b) PORTB |= (1 << PB3);
}
// Protsedurani mikrosaniyalarda kechiktirish
void delay_us(unsigned char time_us)
{ register unsigned char i;
for(i = 0; i < time_us; i++) // 4 tsikl
{ asm (" PUSH R0 "); // 2 tsikl
asm (" POP R0 "); // 2 tsikl
}
}
// Millisekundlarda protsedura kechikishi
void delay_ms(unsigned int time_ms)
{ register unsigned int i;
for(i = 0; i < time_ms; i++)
{ delay_us(250);
delay_us(250);
delay_us(250);
delay_us(250);
}
}
// qizil rang
void red (unsigned int time)
{
for (char a = 0; a < 165; a++)
{
pwm_r = 164 - a; //oshirish
pwm_g = 164;
pwm_b = 164;
delay_ms(time);
}
for (char a = 0; a < 165; a++)
{
pwm_r = a; //kamayish
pwm_g = 164;
pwm_b = 164;
delay_ms(time);
}
}
// Yashil rang
void green (unsigned int time)
{
for (char a = 0; a < 165; a++)
{
pwm_r = 164;
pwm_g = 164 - a;
pwm_b = 164;
delay_ms(time);
}
for (char a = 0; a < 165; a++)
{
pwm_r = 164;
pwm_g = a;
pwm_b = 164;
delay_ms(time);
}
}
// Ko‘k rang
void blue (unsigned int time)
{
for (char a = 0; a < 165; a++)
{
pwm_r = 164;
pwm_g = 164;
pwm_b = 164 - a;
delay_ms(time);