1 | /* |
---|
2 | * ANELEX Interface Microcontroller |
---|
3 | * Test program level |
---|
4 | * Started: 28. August 2010, im Museum |
---|
5 | * Codebase: Gamma10 test program level |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #include "wiring.h" |
---|
10 | #include "anelex.h" |
---|
11 | #include "toolchain.h" |
---|
12 | #include "frontend.h" |
---|
13 | |
---|
14 | static FILE output = FDEV_SETUP_STREAM(stdout_transmit, NULL, _FDEV_SETUP_WRITE); |
---|
15 | |
---|
16 | void Initialize() |
---|
17 | { |
---|
18 | // negierte Ausgaenge schalten |
---|
19 | PORTA = 0x00; |
---|
20 | PORTB = 0x00; // LED (auslassen, an=0x01) |
---|
21 | PORTC = 0x00; |
---|
22 | PORTD = 0x00; |
---|
23 | |
---|
24 | // DDRA: DATA-Anschluss von 0..5 |
---|
25 | DDRA = (1 << DDA0) | (1 << DDA1) | (1 << DDA2) | (1 << DDA3) | (1 << DDA4) | (1 << DDA5); |
---|
26 | // DDRB: LED als output, CA ist input, IB2 ist input |
---|
27 | DDRB = (1 << DDB0); |
---|
28 | // DDRC: STROBE, CP, PRINTCM, RESET sind output, ERRORS input |
---|
29 | DDRC = (1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3); |
---|
30 | // DDRD: AI und KI sind Output, IB1, IB2 input, RTS input, CTS output |
---|
31 | DDRD = (1 << DDD6) | (1 << DDD5) | (1 << DDD7); |
---|
32 | |
---|
33 | // jetzt erst default values setzen |
---|
34 | PORTC = (1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3); |
---|
35 | |
---|
36 | // Pin Change Intterupts aufsetzen |
---|
37 | // PCMSK*: Pin Change Masks (welche Pins tragen zum Intterupt bei) |
---|
38 | // PORT C: |
---|
39 | //PCMSK2 = (1 << PCINT16) | (1 << PCINT17) | (1 << PCINT18) | (1 << PCINT19); |
---|
40 | // Pin Change Interrupt Control Register: PC Interrupt Enable for Port C |
---|
41 | //PCICR = (1 << PCIE2); |
---|
42 | |
---|
43 | // INTTERUPTS AUFSETZEN |
---|
44 | EICRA = (1 << ISC20) | (1 << ISC21) // rising FLANKE von INT2 (CA = Load Cycle) erzeugt intterrupt |
---|
45 | | (1 << ISC11) | (1 << ISC10); // rising edge von INT1 (LINE READY) erzeugt intteruupt |
---|
46 | |
---|
47 | EIMSK = (1 << INT2) | (1 << INT1); // interrupt fuer INT1,2 anschalten |
---|
48 | |
---|
49 | |
---|
50 | // Interrupt enable |
---|
51 | sei(); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | int main() { |
---|
58 | start_led(); |
---|
59 | |
---|
60 | Initialize(); |
---|
61 | uart_init(38400); |
---|
62 | stdout = &output; |
---|
63 | |
---|
64 | // startwerte fuer strukturen: |
---|
65 | line_state = LINE_FINISHED; // Startwert |
---|
66 | input_line_end = CR; |
---|
67 | |
---|
68 | _delay_ms(2000); |
---|
69 | |
---|
70 | puts("ANELEX Interface Microcontroller (c) 2010 Sven Koeppel"); |
---|
71 | puts("This program is part of the Bull Anelex Project at technikum29"); |
---|
72 | puts("Options: 1. Enter text to print. 2. Type ?help for available commands."); |
---|
73 | puts("3. Press Button to print default text. 4. Obey RS232 hardware flow control."); |
---|
74 | stop_led(); |
---|
75 | |
---|
76 | |
---|
77 | for(;;) { |
---|
78 | start_led(); |
---|
79 | readline(); |
---|
80 | stop_led(); |
---|
81 | |
---|
82 | // process user input |
---|
83 | if(current_line[0] == '?') { |
---|
84 | exec_command(); |
---|
85 | continue; |
---|
86 | } |
---|
87 | |
---|
88 | // if readline() went to fast: |
---|
89 | while(line_state != LINE_FINISHED) { |
---|
90 | puts("Wait for printer finished..."); |
---|
91 | _delay_ms(2000); |
---|
92 | } |
---|
93 | |
---|
94 | print_line(); // returns immediately |
---|
95 | |
---|
96 | while(line_state == LINE_TRANSMITTING); |
---|
97 | puts("printing - accepting new line"); |
---|
98 | } |
---|
99 | |
---|
100 | return 0; // ende. |
---|
101 | } |
---|
102 | |
---|
103 | /* |
---|
104 | byte_t y; |
---|
105 | for(y=0;;y++) { |
---|
106 | // warten, bis BUTTON gedrueckt ist |
---|
107 | if(PINB & (1 << PORTB4)) { |
---|
108 | start_led(); |
---|
109 | for(;;) { |
---|
110 | if((PINB & (1 << PORTB4)) == 0) |
---|
111 | break; |
---|
112 | } |
---|
113 | printf("%d: Button gedrueckt\n", counter++); |
---|
114 | |
---|
115 | for(int zzz=0; zzz < 1; zzz++) { |
---|
116 | |
---|
117 | // hier koennen wir jetzt mal arbeiten |
---|
118 | // alle strings durchdrucken |
---|
119 | for(int s=0; tests[s][0]; s++) { |
---|
120 | current_string = tests[s]; |
---|
121 | printf("%d. Drucke %s\n", s, current_string); |
---|
122 | |
---|
123 | print_line_feed(); |
---|
124 | current_counter = 0; |
---|
125 | |
---|
126 | for(;;) { |
---|
127 | if(current_counter == LINE_PRINTED) { |
---|
128 | printf("Zeile fertig! :-)\n"); |
---|
129 | break; |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | stop_led(); |
---|
134 | |
---|
135 | } // for tests |
---|
136 | |
---|
137 | } // mehrfachtests |
---|
138 | } // for buton |
---|
139 | //printf("%d: Sleeping...\n", counter); |
---|
140 | //counter++; |
---|
141 | //_delay_ms(10); |
---|
142 | // endlosschleife |
---|
143 | } |
---|
144 | |
---|
145 | return 0; |
---|
146 | } |
---|
147 | */ |
---|