Изучение лабораторного стенда STК500 и написание двух программ на языках программирования ассемблер и С, задействующие все возможности стенда, страница 4

                        and                  r7,r16  ;убрать лишнее 1-й линии

                        and                  r8,r16  ;убрать лишнее 2-й линии

st6:      nop                                         ;кнопки обработанны

st9:      nop

                        jmp                 st0

mas1:

.db                   0x81,0x42,0x24,0x18,0x24,0x42,0x81

mas2:

.db                   0x81,0xC3,0xE7,0xFF,0xE7,0xC3,0x81

Ниже приведен код программы на С с комментариями.

#define F_CPU 8000000UL

#define __AVR_ATmega16__

#include <avr/io.h>

#include <avr/interrupt.h>

#include <stdio.h>

void initLedsAndButtons() //инициализация портов

{

            //init leds ports on output

            PORTB=0xFF;

            DDRB=0xFF;

            //init buttons ports on input

            PORTD=0xFF;

            DDRD=0x00;

}

void initTimer0()//инициализация таймера

{

            TCNT0 = 0x0; //start from

            OCR0 = 0xFF; //end of cycle

            TCCR0 = 0b00000101;

}

void resetTimer0()//Сброс

{

            TIFR = TIFR - 0b00000010; //drop OCF0 to 0

            TCNT0 = 0x0; //from start

}

int main()

{

            char addToTimer0 = 0;

            char maxAddToTimer = 10;

            initLedsAndButtons();

            initTimer0();

            PORTB=0;//зажигание лампочек

            char val=255; //начальное значение на порту вывода

            char key=0; //номер кнопки

            char bufkey;

            int keynum=0; //номер для паузы

            int speed=0; //задержка

            int maxspeed=0; //начальное значение задержки

            int value=255;

            int value1=0;

            while (1)

            {

                        if(TIFR & OCF0)

                        {

                                    if(PIND==255||PIND==127) // обработка кнопок

                                    {

                                               if(key==1)

                                               {

                                                           speed=speed-1;

                                                           if(speed==0)

                                                           {

                                                                       speed=maxspeed;

                                                                       if(value==0)

                                                                       {          PORTB=127; value=127;}

                                                                       else

                                                                                   PORTB=value;

                                                                       value=value>>1;

                                                                       speed=maxspeed;

                                                           }

                                               }

                                               if(key==2)

                                               {

                                                           speed=speed-1;

                                                           if(speed==0)

                                                           {

                                                                       speed=maxspeed;

                                                                       if(value==0)

                                                                       {          PORTB=127; value=127;}

                                                                       else

                                                                                   PORTB=value;

                                                                       value=value>>1;

                                                                       speed=maxspeed;

                                                           }

                                               }