Last active
April 6, 2020 17:34
-
-
Save fpawel/c2209dd13160cb93ae0fb3d3122c2188 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* программа для компа, которая выводит | |
00000001 | |
00000011 | |
00000111 | |
00001111 | |
00011111 | |
00111111 | |
01111111 | |
11111111 | |
00000000 | |
00000001 | |
00000011 | |
00000111 | |
00001111 | |
00011111 | |
00111111 | |
01111111 | |
11111111 | |
00000000 | |
00000001 | |
00000011 | |
*/ | |
#include "stdio.h" | |
//printBits в данном случае чисто для того, чтобы распечатаь число в двоичной чичтеме счисления, не обращай внимания | |
void printBits(size_t const size, void const* const ptr) | |
{ | |
unsigned char* b = (unsigned char*)ptr; | |
unsigned char byte; | |
int i, j; | |
for (i = size - 1; i >= 0; i--) | |
{ | |
for (j = 7; j >= 0; j--) | |
{ | |
byte = (b[i] >> j) & 1; | |
printf("%u", byte); | |
} | |
} | |
puts(""); | |
} | |
// pause - предположим это твоя пауза | |
void pause(int) | |
{ | |
} | |
// waitSignal - предположим это остановка до следующего сигнала | |
void waitSignal() | |
{ | |
} | |
int main() | |
{ | |
// предположим x - это состояние порта вывода твоего контроллера | |
unsigned char x = 0; | |
// иммитация цикла | |
for (int i = 0; i < 20; ++i) | |
{ | |
// на каждой итерации если порт 11111111, то обнуление и остановка до следующего сигнала | |
if (x == 0xFF) | |
{ | |
x = 0; | |
waitSignal(); | |
} | |
else | |
{ | |
// иначе двоичный сдвиг влево и прибавить 1 | |
x = (x << 1) + 1; | |
// твоя пауза | |
pause(0); | |
} | |
// printBits просто печатает x в консоль, тебе не нужно | |
printBits(sizeof(x), &x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment