Na gut ihr bekommt code, hab gedacht ich versuchs erstmal so weil ich
auf dem PC wo AVR Studio ist kein Internet habe.
Hier ist mein main.c file:
1 | #include <avr/io.h>
|
2 | #include <avr/interrupt.h>
|
3 | #include <util/delay.h>
|
4 | #include "Defines.h"
|
5 | #include "Timer0_Function_Prototypes.h"
|
6 | #include "Port_Initialization_Function_Prototypes.h"
|
7 | #include "InputProc_Function_Prototypes.h"
|
8 | #include "Output_Function_Prototype.h"
|
9 | #include "Key_Enum.h"
|
10 |
|
11 | #define MAX_STRING_SIZE 20
|
12 |
|
13 | int main(void)
|
14 | {
|
15 | InitPorts();
|
16 | InitTimer();
|
17 | sei();
|
18 |
|
19 | // No key is pressed at the beginning.
|
20 | KeyPressed keyPressed = None;
|
21 | unsigned char debouncedStateE = 0xFF;
|
22 | unsigned char debouncedStateF = 0xFF;
|
23 |
|
24 | // Mode variables.
|
25 | bool inputMode = true;
|
26 | bool outputMode = false;
|
27 |
|
28 | // String to store characters.
|
29 | unsigned char inputString[MAX_STRING_SIZE];
|
30 | unsigned char stringSz = 0;
|
31 |
|
32 | while (inputMode)
|
33 | {
|
34 | debouncedStateE = GetDebouncedStateE();
|
35 | debouncedStateF = GetDebouncedStateF();
|
36 |
|
37 | if (GetInputE(&keyPressed, debouncedStateE))
|
38 | InputProc(keyPressed, inputString, &stringSz);
|
39 | else if (GetInputF(&keyPressed, debouncedStateF))
|
40 | InputProc(keyPressed, inputString, &stringSz);
|
41 |
|
42 | // If the max string size has been reached, switch to output mode.
|
43 | if (stringSz > MAX_STRING_SIZE - 2)
|
44 | {
|
45 | inputMode = false;
|
46 | outputMode = true;
|
47 | }
|
48 | }
|
49 |
|
50 | // Append terminating null character to string.
|
51 | inputString[MAX_STRING_SIZE - 1] = '\0';
|
52 |
|
53 | while (outputMode)
|
54 | {
|
55 | PORTB = 0xFF;
|
56 | }
|
57 |
|
58 | return 0;
|
59 | }
|
In dem letzten while loop wird die String dann mit Hilfe einer Funktion
wieder ausgegeben. Komischerweise funktioniert obiges Beispiel, jedoch
mit folgender Änderung nicht:
1 | while (outputMode)
|
2 | {
|
3 | PrintString(inputString);
|
4 | }
|
Wobei PrintString in diesem Falle das gleiche machen soll wie oben:
1 | void PrintString(char* pInputString)
|
2 | {
|
3 | PORTB = 0xFF;
|
4 | }
|
Dann tritt das Problem auf was ich im ersten Post beschrieben habe und
das Programm fängt wieder beim Eingabe mode an.