From 12688a2578ace9776eadfaae0806eaf4ebec48e6 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Thu, 5 Dec 2013 04:06:23 +0100 Subject: Initial commit --- ferment.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 ferment.c (limited to 'ferment.c') diff --git a/ferment.c b/ferment.c new file mode 100644 index 0000000..aba1916 --- /dev/null +++ b/ferment.c @@ -0,0 +1,69 @@ +#define F_CPU 1000000UL +#include +#include +#include +#include +#include +#include +#include +#include + +/* port D + * + * 4 1- (NMOS, inverted) + * 5 1+ (PMOS) + * 6 2- (NMOS, inverted) + * 7 2+ (PMOS) + * + */ + +#define D_1_MINUS (1 << 4) +#define D_1_PLUS (1 << 5) +#define D_2_MINUS (1 << 6) +#define D_2_PLUS (1 << 7) + +/* Turns the H-bridge off, putting the output + * into high impedance mode. */ +static void bridge_off(void) +{ + PORTD |= D_1_MINUS | D_2_MINUS; + PORTD &= ~(D_1_PLUS | D_2_PLUS); +} + +/* Turns the H-bridge on, setting 1+ 2- */ +static void bridge_on_a(void) +{ + bridge_off(); + _delay_ms(100); + PORTD |= D_1_PLUS; + PORTD &= ~D_2_MINUS; +} + +/* Turns the H-bridge on, setting 1- 2+ */ +static void bridge_on_b(void) +{ + bridge_off(); + _delay_ms(100); + PORTD |= D_2_PLUS; + PORTD &= ~D_1_MINUS; +} + +/* Initializes the output port needed for the H-bridge */ +static void bridge_init(void) +{ + bridge_off(); + DDRD |= D_1_PLUS | D_1_MINUS | D_2_PLUS | D_2_MINUS; +} + +int main() +{ + bridge_init(); + /* simple demo, just flips polarity every now and then */ + while (1) { + bridge_on_a(); + _delay_ms(200); + bridge_on_b(); + _delay_ms(200); + } +} + -- cgit v1.2.1