I wrote code in C ++ for mic attiny2313 I would like to know how this code should actually look like, because I suppose this crutch is still

The essence of the code: when you click on a button attached to port A 0b00000001, logical 1 is sequentially sent to ports B 0b00000001 - 0b00000100 when the counter reaches the limit, in this case 3, everything is reset and starts anew.

#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; } } } } 
  • There is not a crutch, there is a code that does not do what you describe. - Vladimir Gamalyan
  • @VladimirGamalian is worse than I thought .. Will you help me with a crutch? Which mistakes? Or is there nothing to fix and burn better? - Vladimir Alexandrov

1 answer 1

Everything is just the same.

 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; } }