1 | uchar gpib_write_data(uchar c)
|
2 | {
|
3 | uchar ucHandshakeValue;
|
4 |
|
5 | Variabel = c;
|
6 | //PORT3 - Datenleitungen - Alle INPUT
|
7 | G_DIO1 = INPUT_NO_PULL;
|
8 | G_DIO2 = INPUT_NO_PULL;
|
9 | G_DIO3 = INPUT_NO_PULL;
|
10 | G_DIO4 = INPUT_NO_PULL;
|
11 | G_DIO5 = INPUT_NO_PULL;
|
12 | G_DIO6 = INPUT_NO_PULL;
|
13 | G_DIO7 = INPUT_NO_PULL;
|
14 | G_DIO8 = INPUT_NO_PULL;
|
15 |
|
16 | if ((c&0x01))
|
17 | {
|
18 | G_DIO1 = OUTPUT_PUSHPULL; // Bit runterziehen
|
19 | P_DATA_OUT &=~ DIO1;
|
20 | } else
|
21 | {
|
22 | G_DIO1 = INPUT_NO_PULL; // Bit loslassen
|
23 | }
|
24 |
|
25 | if ((c&0x02))
|
26 | {
|
27 | G_DIO2 = OUTPUT_PUSHPULL;// Bit runterziehen
|
28 | P_DATA_OUT &=~ DIO2;
|
29 | }
|
30 | else
|
31 | {
|
32 | G_DIO2 = INPUT_NO_PULL; // Bit loslassen
|
33 | }
|
34 |
|
35 | if ((c&0x04))
|
36 | {
|
37 | G_DIO3 = OUTPUT_PUSHPULL; // Bit runterziehen
|
38 | P_DATA_OUT &=~ DIO3;
|
39 | } else
|
40 | {
|
41 | G_DIO3 = INPUT_NO_PULL; // Bit loslassen
|
42 | }
|
43 |
|
44 | if ((c&0x08))
|
45 | {
|
46 | G_DIO4 = OUTPUT_PUSHPULL; // Bit runterziehen
|
47 | P_DATA_OUT &=~ DIO4;
|
48 | } else
|
49 | {
|
50 | G_DIO4 = INPUT_NO_PULL; // Bit loslassen
|
51 | }
|
52 |
|
53 | if ((c&0x10))
|
54 | {
|
55 | G_DIO5 = OUTPUT_PUSHPULL; // Bit runterziehen
|
56 | P_DATA_OUT &=~ DIO5;
|
57 | } else
|
58 | {
|
59 | G_DIO5 = INPUT_NO_PULL; // Bit loslassen
|
60 | }
|
61 |
|
62 | if ((c&0x20))
|
63 | {
|
64 | G_DIO6 = OUTPUT_PUSHPULL; // Bit runterziehen
|
65 | P_DATA_OUT &=~ DIO6;
|
66 | } else
|
67 | {
|
68 | G_DIO6 = INPUT_NO_PULL; // Bit loslassen
|
69 | }
|
70 |
|
71 | if ((c&0x40))
|
72 | {
|
73 | G_DIO7 = OUTPUT_PUSHPULL; // Bit runterziehen
|
74 | P_DATA_OUT &=~ DIO7;
|
75 | }
|
76 | else
|
77 | {
|
78 | G_DIO7 = INPUT_NO_PULL; // Bit loslassen
|
79 | }
|
80 |
|
81 | if ((c&0x80))
|
82 | {
|
83 | G_DIO8 = OUTPUT_PUSHPULL; // Bit runterziehen
|
84 | P_DATA_OUT &=~ DIO8;
|
85 | }
|
86 | else
|
87 | {
|
88 | G_DIO8 = INPUT_NO_PULL; // Bit loslassen
|
89 | }
|
90 |
|
91 | G_NRFD = INPUT_NO_PULL; // Bit loslassen
|
92 |
|
93 | G_NDAC = INPUT_NO_PULL; // Bit loslassen
|
94 |
|
95 | //Datenauf Buschreiben
|
96 | Datenrichtung |= Write_data; // Datenrichtung = Daten schreiben
|
97 |
|
98 | ucHandshakeValue = 0;
|
99 | uiErrorCounter = 0;
|
100 | ui10msCounter = guiTimer_10ms + 1;
|
101 | // Warten bis Gerät bereit ist für neue Daten - NRFD = 1
|
102 | while ((ucHandshakeValue == 0) && (uiErrorCounter <= 100))
|
103 | {
|
104 | // Wenn NRFD laenger als 1 Sekunde nicht = 0, dann Error
|
105 | ucHandshakeValue = ((P_SIGNAL >> 0x02) & 0x01);
|
106 | if (guiTimer_10ms >= ui10msCounter)
|
107 | {
|
108 | uiErrorCounter ++;
|
109 | ui10msCounter = guiTimer_10ms + 1;
|
110 | if (uiErrorCounter >= 100 )
|
111 | {
|
112 | return ERROR;
|
113 | }
|
114 | }
|
115 | }
|
116 | //DAV = 1
|
117 | G_DAV = OUTPUT_PUSHPULL; // Bit runterziehen
|
118 | P_SIGNAL_OUT &=~ DAV;
|
119 |
|
120 |
|
121 | G_NDAC = INPUT_NO_PULL; // Bit loslassen
|
122 |
|
123 | ucHandshakeValue = 0;
|
124 | uiErrorCounter = 0;
|
125 | ui10msCounter = guiTimer_10ms + 1;
|
126 | //Warten bis Daten in Buffer gespeichert NDAC = 0
|
127 | while ((ucHandshakeValue == 0) && (uiErrorCounter <= 100))
|
128 | {
|
129 | // Wenn NDAC laenger als 1 Sekunde nicht = 0, dann Error
|
130 | ucHandshakeValue = ((P_SIGNAL >> 0x03) & 0x01);// NDAC einlesen
|
131 | if (guiTimer_10ms >= ui10msCounter)
|
132 | {
|
133 | uiErrorCounter ++; // uiErrorCounter alle 10ms hochzählen
|
134 | ui10msCounter = guiTimer_10ms + 1;
|
135 | if (uiErrorCounter >= 100 )
|
136 | {
|
137 | return ERROR; //Nach 1 Sekunde Error zurückgeben
|
138 | }
|
139 | }
|
140 |
|
141 | }
|
142 | // Release DAV = 0, Daten sind nun nicht mehr gültig
|
143 | G_DAV = INPUT_NO_PULL; // Bit loslassen
|
144 |
|
145 | //Warten bis Daten akzeptiert NDAC = 0
|
146 | ucHandshakeValue = 1;
|
147 | uiErrorCounter = 0;
|
148 | ui10msCounter = guiTimer_10ms + 1;
|
149 | while ((ucHandshakeValue == 1) && (uiErrorCounter <= 100))
|
150 | {
|
151 | ucHandshakeValue = ((P_SIGNAL >> 0x03) & 0x01);
|
152 | if (guiTimer_10ms >= ui10msCounter)
|
153 | {
|
154 | uiErrorCounter ++;
|
155 | ui10msCounter = guiTimer_10ms + 1;
|
156 | if (uiErrorCounter >= 100 )
|
157 | {
|
158 | gucError = 1;
|
159 | return ERROR;
|
160 | }
|
161 | }
|
162 | }
|
163 | Datenrichtung = Datenrichtung & ~Read_data; // Datenrichtung = Daten lesen
|
164 | //PORT3 - Datenleitungen alle Input setzen
|
165 | G_DIO1 = INPUT_NO_PULL;
|
166 | G_DIO2 = INPUT_NO_PULL;
|
167 | G_DIO3 = INPUT_NO_PULL;
|
168 | G_DIO4 = INPUT_NO_PULL;
|
169 | G_DIO5 = INPUT_NO_PULL;
|
170 | G_DIO6 = INPUT_NO_PULL;
|
171 | G_DIO7 = INPUT_NO_PULL;
|
172 | return 1 ;
|
173 | }
|