1 | /* |
---|
2 | * BULL_Druckermapping.c |
---|
3 | * |
---|
4 | * Created: 26.01.2013 17:38:39 |
---|
5 | * Author: Sven |
---|
6 | */ |
---|
7 | |
---|
8 | #include "wiring.h" |
---|
9 | #include "util/delay.h" |
---|
10 | #include <avr/io.h> |
---|
11 | |
---|
12 | #include "mapping-table.h" |
---|
13 | #include "util/parity.h" // parity_even_bit(val) |
---|
14 | |
---|
15 | void Initialize() { |
---|
16 | // Ports einrichten |
---|
17 | // PORTxn setzten damit DDRxn Pull-Up-Widerstaende setzt |
---|
18 | PORTA = 0x00; |
---|
19 | PORTB = 0x01; // LED Pull up |
---|
20 | PORTC = 0xFF; // 8bit data output als offene kollektoren |
---|
21 | PORTD = 0x00; |
---|
22 | |
---|
23 | DDRA = 0x00; // 8bit data input |
---|
24 | DDRB = 0x00 | (1 << DDB0); // LED Output |
---|
25 | DDRC = 0xFF; // 8bit data output |
---|
26 | DDRD = 0x00; // ungenutzt |
---|
27 | } |
---|
28 | |
---|
29 | uint8_t get_translated_data(uint8_t input) { |
---|
30 | // input auf 6bit beschraenken |
---|
31 | static uint8_t mask = 63; // 0x0011.1111 = 6 bit an |
---|
32 | input &= mask; // obere Bits rausschneiden, sicherheitshalber |
---|
33 | uint8_t output_data = (input <= LAST_DEFINED_CHARACTER) ? translation_table[input] : UNDEFINED_CHARACTER; |
---|
34 | // Printer I 50B Paritybit = 1 for even number of 1 |
---|
35 | if(parity_even_bit(output_data) == 0) { |
---|
36 | // I have an even number of bits |
---|
37 | // output_data sind 6bit Daten, sodass die Paritaet im 7. Bit steht. |
---|
38 | output_data |= 0x01 << 6; |
---|
39 | } |
---|
40 | // Das 8. Bit ist dann Null. |
---|
41 | return output_data; |
---|
42 | } |
---|
43 | |
---|
44 | int main(void) { |
---|
45 | Initialize(); |
---|
46 | start_led(); |
---|
47 | |
---|
48 | for(int i=0;;i++) { |
---|
49 | if(i == 20*000*000) { |
---|
50 | toggle_led(); |
---|
51 | i = 0; |
---|
52 | } |
---|
53 | |
---|
54 | // invertieren aller bits: |
---|
55 | // ~datum |
---|
56 | // PORT_DATA_OUT = ~PIN_DATA_IN; |
---|
57 | |
---|
58 | PORT_DATA_OUT = get_translated_data(PIN_DATA_IN); |
---|
59 | |
---|
60 | |
---|
61 | //_delay_ms(300); |
---|
62 | //stop_led(); |
---|
63 | //_delay_ms(300); |
---|
64 | |
---|
65 | } |
---|
66 | } |
---|