Well here's the first problem.
Code:
foo.c: In function ‘main’:
foo.c:11:13: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘uint8_t *’ {aka ‘unsigned char *’} [-Wformat=]
11 | scanf("%d", &LSB_BIT );
| ~^ ~~~~~~~~
| | |
| | uint8_t * {aka unsigned char *}
| int *
| %hhd
foo.c:20:13: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘uint8_t *’ {aka ‘unsigned char *’} [-Wformat=]
20 | scanf("%d", &LSB_BIT );
| ~^ ~~~~~~~~
| | |
| | uint8_t * {aka unsigned char *}
| int *
| %hhd
Your scanf with %d is going to trash memory outside of the intended variable.
Using the correct scanf format of %hhd, I get
Code:
$ gcc foo.c
$ ./a.out
Set/Reset LSB Enter 1 /0 : 1
1
Byte = 2
Set/Reset LSB Enter 1 /0 : 1
3
Byte = 6
Enable as many warnings as you can on your compiler, and use a compiler with lots of diagnostics.