From cec47de6ea481731f35c3431727730e7dabfb3bf Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Sun, 21 Apr 2019 20:08:36 +0000 Subject: [PATCH] Add LPT to serial converter --- lpt2ser.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lpt2ser.c diff --git a/lpt2ser.c b/lpt2ser.c new file mode 100644 index 0000000..b87b4e5 --- /dev/null +++ b/lpt2ser.c @@ -0,0 +1,55 @@ +#include "drivers/uart_tx.h" +#include +#include + +void wait_strobe_on() { // active low + while((PIND >> PD2) & 1) {}; +} + +void wait_strobe_off() { + while(~(PIND >> PD2) & 1) {}; +} + +void ack_on() { // active low + PORTD &= ~(1 << PD3); +} + +void ack_off() { + PORTD |= (1 << PD3); +} + +void busy_on() { // active high + PORTB |= (1 << PB4); +} + +void busy_off() { + PORTB &= ~(1 << PB4); +} + +int main(void) { + // STROBE input is on PD2 + // PB0-PB3 and PD4-PD7 are data inputs + DDRD = (1 << PD3); // ACK output + DDRB = (1 << PB4); // BUSY output + + // pull-up per default + PORTD |= (1 << PD2) | (1 << PD3); + + uint8_t i, data; + + for(;;) { + wait_strobe_on(); + data = (PIND & 0xF0) | (PINB & 0x0F); + busy_on(); + ack_on(); + _delay_us(10); // 5 us minimum + ack_off(); + + // this blocks until written + uart_putc(data); + + busy_off(); + // make sure we are not reading the same char again + wait_strobe_off(); + } +}