Код: Выделить всё
#include <tiny13a.h>
#include <delay.h>
#include <stdlib.h>
#define RED 1
#define GREEN 0
#define BLUE 2
unsigned char wave_counter=0;
unsigned char red_bs=0;
unsigned char green_bs=0;
unsigned char blue_bs=0;
unsigned char rg = 1;
unsigned char gb = 0;
unsigned char br = 0;
interrupt [TIM0_COMPA] void timer0_compa_isr(void)
{
PORTB.RED=(wave_counter<red_bs);
PORTB.GREEN=(wave_counter<green_bs);
PORTB.BLUE=(wave_counter<blue_bs);
wave_counter++;
}
void common_init()
{
CLKPR=0x80;
CLKPR=0x00;
TIMSK0=0b100;
DDRB=0xff;
TCCR0A|=0b10;
TCCR0B=4;
red_bs = 255;
}
void main(void)
{
common_init();
#asm("sei")
while (1){
if(rg)
{
red_bs--;
green_bs++;
if(red_bs == -1)
{
red_bs = 0;
rg = 0;
gb = 1;
}
}
if(gb)
{
green_bs--;
blue_bs++;
if(green_bs == -1)
{
gb = 0;
br = 1;
}
}
if(br)
{
blue_bs--;
red_bs++;
if(blue_bs == -1)
{
br = 0;
rg = 1;
}
}
delay_ms(100);
}
}




