Programming attiny2313 in C
I wrote the code in C++ for mk attiny2313 I would like to know how this code should actually look, because I believe this crutch is still
The essence of the code: when you click on the button attached to port A 0b00000001, a logical 1 is applied sequentially to ports B 0b00000001 - 0b00000100 when the counter reaches the limit, in this case 3, then everything is reset and starts again.
#include <avr/io.h>
int main(void)
{
DDRB = 0xff;
int count = 0;
while (1)
{
if (PINA == 0b001)
{
while(1)
{
if (PINA == 0b000)
{
break;
}
}
if (count <= 0)
{
count++;
PORTB |= 1<<1;
}
else
{
count = 0;
PORTB = 0b00000000;
}
}
}
}
1
Author: Alexey Esaulenko, 2017-01-05
1 answers
Everything is simple.
int main(void)
{
DDRB = 0xff;
char count; // 8-битной переменной тут более чем достаточно
while(1)
{
// ждём нажатия кнопки
while (PINA != 0b001)
;
// ждём отпускания кнопки
while (PINA == 0b001)
;
for (count = 0; count < 3; count++)
{
PORTB |= 1 << count;
// тут нужна задержка.
// изучить содержимое delay.h предлагаю самостоятельно
}
PORTB = 0;
}
}
0
Author: Alexey Esaulenko, 2017-01-10 11:26:15