//Схема и задача прежняя
#include <avr/io.h>
#include <avr/interrupt.h>
unsigned char rab;
ISR(TIMER1_COMPA_vect)
{
if (PIND&(1<<PIND0))
{
rab>>=1;
if(rab==0)
rab=0x80;
}
else
{
rab<<=1;
if(rab==0)
rab=1;
}
PORTB=rab^0xff;
}
int main(void)
{
DDRD&=(~(1<<DDD0));
DDRB=0xff;
PORTB=0xff;
PORTD=0xff;
ACSR=0x80;
TIMSK=0x40;
TCCR1B=0b00001101;
OCR1AH=0x03;
OCR1AL=0x0c;
rab=0b00010000;
asm("sei");
while(1)
{
}
}
//Добавим Таймер0 на порт А
#include <avr/io.h>
#include "avr/interrupt.h"
unsigned char rab;
ISR(TIMER1_COMPA_vect)
{
if (PIND&(1<<PIND0))
{
rab<<=1;
if(rab==0)rab=1;
}
else
{
rab>>=1;
if(rab==0)rab=0x80;
}
PORTB=rab^0xff;
}
ISR(TIMER0_COMPA_vect)
{
PORTA^=(1<<PA0);
}
int main(void)
{
DDRA|=(1<<DDD0);
DDRB=0xff;
DDRD&=(~(1<<DDD0));
PORTA|=(1<<PA0);
PORTB=0xff;
PORTD|=(1<<PD0);
TCCR0A=0b00000010;
TCCR0B=0b00000101;
OCR0A=255;
TIMSK=0b01000001;
TCCR1B=0b00001101;
OCR1A=50;
rab=0b00010000;
asm("sei");
while(1)
{
}
}
НАЗАД Assembler AVR Assembler PIC ДАЛЕЕ