From ebe951a445b5d774542731d6165a9c5cd56beb2b Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 9 Feb 2014 02:42:17 +0900 Subject: Add Initial files of 4704_usb --- protocol/ibm4704.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 protocol/ibm4704.c (limited to 'protocol/ibm4704.c') diff --git a/protocol/ibm4704.c b/protocol/ibm4704.c new file mode 100644 index 000000000..26441ed52 --- /dev/null +++ b/protocol/ibm4704.c @@ -0,0 +1,150 @@ +/* +Copyright 2010,2011,2012,2013 Jun WAKO +*/ +#include +#include +#include "debug.h" +#include "ibm4704.h" + + +#define WAIT(stat, us, err) do { \ + if (!wait_##stat(us)) { \ + ibm4704_error = err; \ + goto ERROR; \ + } \ +} while (0) + + +uint8_t ibm4704_error = 0; + + +void ibm4704_init(void) +{ + // POR + //_delay_ms(2500); + //while ( 0xA3 != ibm4704_recv() ) ; + + inhibit(); + DDRD |= 1<<3; + PORTD &= ~(1<<3); +} + +uint8_t ibm4704_send(uint8_t data) +{ + bool parity = true; // odd parity + ibm4704_error = 0; + + /* Request to send */ + idle(); + clock_lo(); +PIND |= 1<<3; + + /* wait for Start bit(Clock:lo/Data:hi) */ + WAIT(data_hi, 300, 0x30); + + /* Data bit */ + for (uint8_t i = 0; i < 8; i++) { + WAIT(clock_hi, 100, 0x31); + //_delay_us(5); +PIND |= 1<<3; + if (data&(1< 2) { + xprintf("x%02X ", ibm4704_error); + } + inhibit(); + _delay_us(200); // wait to recover clock to hi + return -1; +} -- cgit v1.2.3-70-g09d2