avr-firmwares/lpt2ser.c

56 lines
925 B
C

#include "drivers/uart_tx.h"
#include <avr/io.h>
#include <util/delay.h>
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();
}
}