-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbitio.c
More file actions
36 lines (33 loc) · 697 Bytes
/
bitio.c
File metadata and controls
36 lines (33 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* bitio.c
* Bit I/O
*
* @author Nathan Campos <nathanpc@dreamintech.net>
*/
#include <stdint.h>
#include "boolean.h"
/**
* Get a single bit from a byte.
*
* @param b A byte.
* @param pos The bit position to be extracted.
* @return A bit.
*/
unsigned int get_byte(char b, unsigned int pos) {
return (b & (1 << pos));
}
/**
* Puts the desired bit into a pin. It's used to get the bits in a char
* to send to the LCD.
*
* @param c The character.
* @param pos Bit position.
* @param pin The pin to be set.
*/
void bit_to_pin(char c, unsigned int pos, volatile unsigned char *port, unsigned int pin) {
if (get_byte(c, pos)) {
*port |= pin;
} else {
*port &= ~pin;
}
}