Forum: Compiler & IDEs IOs umbenennen


von Mathiable (Gast)


Lesenswert?

Guten Tag

Ich arbeite momentan mit WinAVR und einem ATXMEGA128A1, der ja 
bekanntlich 78 IOs hat. Das Programm wird aber auch von Personen 
bearbeitet, die zwar C programmieren können aber noch nie mit Atmel MyCs 
gearbeitet haben, so dass ich mich wegen der Übersichtlichkeit frage ob 
es eine Möglichkeit gibt Outputs quasi wie eine Variable anzusteuern, so 
dass bsp. PINA1 mit "LED=1" angesteuert werden könnte. Die Input abfrage 
lässt sich ja mit Define so abändern.

1
#define BIT_VALUE( PORT, BIT )    (( (PORT) & (1<<(BIT))) != 0 ) //macht aus dem Byte einzelne Bit
2
3
#define Taste (BIT_VALUE( PINA, PINA0 ))
4
5
void main(void)
6
{
7
    if(Taste==1){
8
     
9
    ...
10
11
    }
12
}


Hoffe ihr könnt mir helfen

Freundliche Grüsse

Mathiable

von Karl H. (kbuchegg)


Lesenswert?

Mathiable schrieb:
> Guten Tag
>
> Ich arbeite momentan mit WinAVR und einem ATXMEGA128A1, der ja
> bekanntlich 78 IOs hat. Das Programm wird aber auch von Personen
> bearbeitet, die zwar C programmieren können aber noch nie mit Atmel MyCs
> gearbeitet haben, so dass ich mich wegen der Übersichtlichkeit frage ob
> es eine Möglichkeit gibt Outputs quasi wie eine Variable anzusteuern, so
> dass bsp. PINA1 mit "LED=1" angesteuert werden könnte.

Die Möglichkeit gibt es schon. Man kann sich natürlich eine struct 
machen, in der mittels Bitfelder ein uint8_t auf 8 Bits aufgedröselt 
wird und dann dem Compiler die ganze Maskierung überlassen.

Aber wenn deine Programmierer sowieso nicht so fit sind, ist es 
fraglich, ob du dadurch nicht mehr Konfusion erzeugst als es gut ist.

Ich würde die PortPins, ähnlich wie du es bei der Abfrage gemacht hast, 
in ein paar Makros verpacken, jeweils mit einem Set und Clear Makro.

von Peter D. (peda)


Lesenswert?

Ja das geht sogar sehr gut.

Man braucht dazu ein Macro. Dann kann man die Portpins wie Bitvariablen 
ansprechen, also auf 0 oder 1 testen oder setzen.
Hier eine Beispiel:

http://www.mikrocontroller.net/attachment/30300/lcd_drv.zip


Peter

von Peter (Gast)


Lesenswert?

Eine elegante Möglichkeit: Nicht super effizient, aber auch nicht so 
schlimm wie es zunächst aussieht...
1
//==============================================================
2
// Definition for I/O-Pin control
3
//--------------------------------------------------------------
4
#define PIN_0       0x01  // IO-Pin(0)
5
#define PIN_1       0x02  // IO-Pin(1)
6
#define PIN_2       0x04  // IO-Pin(2)
7
#define PIN_3       0x08  // IO-Pin(3)
8
#define PIN_4       0x10  // IO-Pin(4)
9
#define PIN_5       0x20  // IO-Pin(5)
10
#define PIN_6       0x40  // IO-Pin(6)
11
#define PIN_7       0x80  // IO-Pin(7)
12
13
#define PORT_A      &PORTA, &DDRA, &PINA
14
#define PORT_B      &PORTB, &DDRB, &PINB
15
#define PORT_C      &PORTC, &DDRC, &PINC
16
#define PORT_D      &PORTD, &DDRD, &PIND
17
18
#define L           0    // Output Low-Level
19
#define H           1    // Output High-Level
20
#define T           2    // Output Toggle-Level
21
#define Z           3    // Input with High-Impedance
22
#define P           4    // Input with Pullup
23
24
//---------------------------------------
25
// Beispiel Definitionen für alle IOs
26
//---------------------------------------
27
#define IOUT_1        PORT_A, PIN_0
28
#define UOUT_1        PORT_A, PIN_1
29
#define SD_1A         PORT_A, PIN_2
30
#define SD_2A         PORT_A, PIN_3
31
#define IOUT_2        PORT_A, PIN_4
32
#define UOUT_2        PORT_A, PIN_5
33
#define SD_1B         PORT_A, PIN_6
34
#define SD_2B         PORT_A, PIN_7
35
36
#define I_UF_1        PORT_B, PIN_0
37
#define SELECT_2A     PORT_B, PIN_1
38
#define I_UF_2        PORT_B, PIN_2
39
#define SELECT_2B     PORT_B, PIN_3
40
#define LED_1A_N      PORT_B, PIN_4
41
#define LED_2A_N      PORT_B, PIN_5
42
#define LED_1B_N      PORT_B, PIN_6
43
#define LED_2B_N      PORT_B, PIN_7
44
45
#define SCL           PORT_C, PIN_0
46
#define SDA           PORT_C, PIN_1
47
#define TCK           PORT_C, PIN_2
48
#define TMS           PORT_C, PIN_3
49
#define STATE_GREEN   PORT_C, PIN_4
50
#define TDI           PORT_C, PIN_5
51
#define RELAIS_LOOP   PORT_C, PIN_6
52
#define STATE_RED     PORT_C, PIN_7
53
54
#define RXD           PORT_D, PIN_0
55
#define TXD           PORT_D, PIN_1
56
#define I_OF_1        PORT_D, PIN_2
57
#define I_OF_2        PORT_D, PIN_3
58
#define P5V_ON_1      PORT_D, PIN_4
59
#define AC230_ON_1    PORT_D, PIN_5
60
#define P5V_ON_2      PORT_D, PIN_6
61
#define AC230_ON_2    PORT_D, PIN_7
1
//---------------------------------------------------------
2
// Set IO-Pin as Output(L,H,T) or as Input(Z,P)
3
//-----------------------------------------------------------
4
void set(volatile u08 *PORT, volatile u08 *DDR, volatile u08 *PIN, u08 msk, u08 status)
5
{
6
  if (status == H)
7
  {
8
    *PORT |=  msk;           // Set IO-pin High
9
    *DDR  |=  msk;           // Set IO-pin as output
10
  }
11
  else if (status == L)
12
  {
13
    *PORT &= ~msk;           // Set IO-pin Low
14
    *DDR  |=  msk;           // Set IO-pin as output
15
  }
16
  else if (status == T)
17
  {
18
    *PORT ^=  msk;           // Toggle IO-pin level
19
    *DDR  |=  msk;           // Set IO-pin as output
20
  }
21
  else if (status == Z)
22
  {
23
    *DDR  &= ~msk;           // Set IO-pin as input
24
    *PORT &= ~msk;           // Disable Pullup
25
  }
26
  else if (status == P)
27
  {
28
    *DDR  &= ~msk;           // Set IO-pin as input
29
    *PORT |=  msk;           // Enable Pullup
30
  }
31
}
32
33
//---------------------------------------------------------
34
// Get IO-Pin Level (returns 0 or 1)
35
//---------------------------------------------------------
36
u08 get(volatile u08 *PORT, volatile u08 *DDR, volatile u08 *PIN, u08 msk)
37
{
38
  if((*PIN & msk) != 0)
39
  {
40
    return H;
41
  }
42
  return L;
43
}
1
//--------------------------------------
2
// Anwendungs-Beispiel
3
//--------------------------------------
4
if (get(AC230_ON_2) == L)
5
{
6
  set(AC230_ON_2,L);    // drive output low
7
  set(AC230_ON_2,H);    // rising edge
8
  set(AC230_ON_2,Z);    // set as input High-Z
9
  _delay_us(100);
10
  if (get(AC230_ON_2) == H)   // check again
11
  {
12
    printf("State2: CONNECT => POWERED");
13
  }
14
}

von Mathiable (Gast)


Lesenswert?

Peter Dannegger schrieb:
> Ja das geht sogar sehr gut.
>
> Man braucht dazu ein Macro. Dann kann man die Portpins wie Bitvariablen
> ansprechen, also auf 0 oder 1 testen oder setzen.
> Hier eine Beispiel:
>
> http://www.mikrocontroller.net/attachment/30300/lcd_drv.zip
>
>
> Peter

Sieht schon mal vielversprechend aus. Ich werde das mal genauer 
studieren. Vielen Dank.

von Peter D. (peda)


Lesenswert?

Peter schrieb:
> Nicht super effizient, aber auch nicht so
> schlimm wie es zunächst aussieht...

Ich habs mal compiliert.
Es ist wirklich doch so schlimm, wie es aussieht.

Das sind riesige Unterfunktionen und elend lange Listen von Argumenten 
pro Aufruf:
1
  set(AC230_ON_2,L);    // drive output low
2
  f2:   82 e3           ldi     r24, 0x32       ; 50
3
  f4:   90 e0           ldi     r25, 0x00       ; 0
4
  f6:   61 e3           ldi     r22, 0x31       ; 49
5
  f8:   70 e0           ldi     r23, 0x00       ; 0
6
  fa:   40 e3           ldi     r20, 0x30       ; 48
7
  fc:   50 e0           ldi     r21, 0x00       ; 0
8
  fe:   20 e8           ldi     r18, 0x80       ; 128
9
 100:   00 e0           ldi     r16, 0x00       ; 0
10
 102:   0e 94 36 00     call    0x6c    ; 0x6c <set>

Ich schätze mal, es ereicht die gleiche Langsamkeit bei 8MHz, wie die 
Verwendung von Bitmacros bei 32kHz.


Peter

von Klaus Falser (Gast)


Lesenswert?

Peter Dannegger schrieb:
> Ich habs mal compiliert.
> Es ist wirklich doch so schlimm, wie es aussieht.

Möglicherweise würde es helfen, die Funktion als inline zu definieren.
Dann könnte der Optimizer das ganze überflüssige Zeug wegschmeissen.

von Peter (Gast)


Lesenswert?

Naja, Du übertreibst da etwas: 8 MHz / 32 kHz = 250000  ;o)

Und Flashspeicher ist bei einem ATXMEGA128A1 auch reichlich vorhanden! 
Mir ist ein pflegeleichter und übersichtlicher Code lieber, auch wenn er 
schlussendlich 20% grösser wird...

von Peter (Gast)


Lesenswert?

Man könnte das folgende auch in einem globalen Strukt defninieren, dann 
müsste man der set/get Funktion nur noch einen Pointer übergeben

#define PORT_A      &PORTA, &DDRA, &PINA
#define PORT_B      &PORTB, &DDRB, &PINB
#define PORT_C      &PORTC, &DDRC, &PINC
#define PORT_D      &PORTD, &DDRD, &PIND

Habe hier zugegebenrmassen nicht gross Kopfzerbrechen bereitet!

von Peter D. (peda)


Lesenswert?

Peter schrieb:
> Naja, Du übertreibst da etwas: 8 MHz / 32 kHz = 250000  ;o)

8 MHz / 32 kHz = 250

> Mir ist ein pflegeleichter und übersichtlicher Code lieber

Ist wohl Geschmackssache.
Ich finde Variablenzugriffe deutlich besser lesbar als Funktionsaufrufe:
1
if( KEY0 == KEY_PRESS )
2
  LED0 = LED_ON;

> auch wenn er
> schlussendlich 20% grösser wird...

Der Aufruf kostet 10 Words, das ist das 10-fache eines SBI-Befehls, also 
900% mehr.
Nur 20% mehr für das gesamte Programm dürfte daher kaum hinkommen.


Peter

von Mathiable (Gast)


Lesenswert?

Vielen Dank für die Antworten. Ich habe nun wie bei Peter Danneggers 
Beispiel eine h File geschrieben mit diversen defines und kann nun 
"LED=1;" schreiben und es fehlerfrei kompilieren. Ich habe die Hardware 
noch nicht fertig, aber wenn noch Fehler auftreten werde ich mich wider 
melden.

von Nils S. (kruemeltee) Benutzerseite


Lesenswert?

>eine h File geschrieben mit diversen defines und kann nun
>"LED=1;" schreiben und es fehlerfrei kompilieren. Ich habe die Hardware
>noch nicht fertig, aber wenn noch Fehler auftreten werde ich mich wider
>melden.
Wäre schön wenn du mal ein Beispiel zeigen würdest.

von Peter D. (peda)


Lesenswert?

Klaus Falser schrieb:
> Möglicherweise würde es helfen, die Funktion als inline zu definieren.
> Dann könnte der Optimizer das ganze überflüssige Zeug wegschmeissen.

Ja, mit "__attribute__ ((always_inline))" kommt sogar was brauchbares 
raus.

Wie gesagt, es ist Geschmackssache, ob man diese Schreibweise mag.


Peter

von Mathiable (Gast)


Lesenswert?

Ich habe eigentlich nur Copy Paste gemacht, aber in der h File steht 
jetzt folgendes:
1
typedef unsigned char  u8;
2
3
#define vu8(x)  (*(volatile u8*)&(x))
4
5
6
struct bits {
7
  u8 b0:1;
8
  u8 b1:1;
9
  u8 b2:1;
10
  u8 b3:1;
11
  u8 b4:1;
12
  u8 b5:1;
13
  u8 b6:1;
14
  u8 b7:1;
15
} __attribute__((__packed__));
16
17
#define SBIT(port,pin) ((*(volatile struct bits*)&port).b##pin)
18
19
20
#define  LED    SBIT( PORTA, 0 )

Kompilieren kann er es aber getestet habe ich es noch nicht.

von Stefan P. (Gast)


Lesenswert?

Hi,
ich hab mir diesbezüglich auch mal was geschrieben. Wie das als ASM 
ausschaut hab ich noch gar nie nachgeschaut. Ist aber eigentlich nur 
Bitmanipulation. OK so super ist der Code noch nicht... muss da mal noch 
etwas handanlegen und bitte nicht auf das miese Englisch achten. Sollte 
wohl doch besser in deutsch Kommentieren ;-)
1
#ifndef IO_CONTROL_H_
2
#define IO_CONTROL_H_
3
4
5
/* ------------------------------------------------------------------------- */
6
/* -------------------------- IO descriptoion ------------------------------ */
7
/* ------------------------------------------------------------------------- */
8
/*
9
 * DDRx : Datenrichtungsregister
10
 * if ddr is set (1)     --> OUTPUT
11
 * if ddr is not set (0) --> INPUT
12
 *
13
 * PINx : Eingangsadresse
14
 * Read the temporary status of the bit, !!if Port is INPUT (DDRx = 1)
15
 * if pin is set (1)     --> level is high (VCC)
16
 * if pin is not set (0) --> level is low (GND)
17
 *
18
 * PORTx : Datenregister
19
 * If Port is set as OUTPUT, you can set the bit level
20
 *   if port is set (1)     --> level is hight (VCC)
21
 *   if port is not set (0) --> level is low (GND)
22
 *
23
 * If Port is set as INPUT, you can enabel or disable the internal Pull-up Resistor
24
 *   if port is set (1)     --> pull-up is active
25
 *   if port is not set (0) --> pull-up is not active
26
 */
27
28
/* ------------------------------------------------------------------------- */
29
/* -------------------------- Global definitions --------------------------- */
30
/* ------------------------------------------------------------------------- */
31
/*
32
 * Define for example:
33
 * -> "IO_PORT_PIN(D)" and it returns an simular action like writing "PIND".
34
 * The "name" in "IO_PORT_PIN(name)" is for this example "D".
35
 * 
36
 * With the IO_DDR_INPUT/OUTPUT(type, name) functions you can set the Data
37
 * Direction Register as inpot or output.
38
 *
39
 * Declarations:
40
 * a ## b  --> combinates the two strings a=AAA, b=BBB to AAABBB
41
 *     a=DDR, b=B  -> result = DDRB
42
 */
43
44
#define IO_PORT_ARG(a, b)      a
45
#define IO_BIT_ARG(a, b)      b
46
47
#define IO_PORT_NAME(a, b)      IO_PORT_ARG(a, b)
48
#define IO_BIT_NUM(name)      IO_BIT_ARG(name)
49
50
#define IO_PORT_MERGE_TMP(a, b)    a ## b
51
#define IO_PORT_MERGE(a, b)      IO_PORT_MERGE_TMP(a, b)
52
53
54
#define IO_PORT_DDR(name)      IO_PORT_MERGE(DDR, IO_PORT_NAME(name) )
55
#define IO_PORT_PORT(name)      IO_PORT_MERGE(PORT, IO_PORT_NAME(name) )
56
#define IO_PORT_PIN(name)      IO_PORT_MERGE(PIN, IO_PORT_NAME(name) )
57
58
#define IO_DDR(type, name)      IO_PORT_DDR(type##__##name)
59
#define IO_PORT(type, name)      IO_PORT_PORT(type##__##name)
60
#define IO_PIN(type, name)      IO_PORT_PIN(type##__##name)
61
#define IO_BIT(type, name)      IO_BIT_NUM(type##__##name)
62
63
64
/* ------------------------------------------------------------------------- */
65
/* -------------------------- Global IO definitions ------------------------ */
66
/* ------------------------------------------------------------------------- */
67
68
#define IO_SET_INPUT(type, name)  IO_DDR(type, name) &= ~(1<<IO_BIT(type, name) )    // set Port as input
69
#define IO_SET_OUTPUT(type, name)  IO_DDR(type, name) |= (1<<IO_BIT(type, name) )    // set Port as output
70
71
//#define IO_IS_HIGH(type, name)    IO_DDR(type, name) |= (1<<IO_BIT(type, name) )    // ask if IO is high/VCC
72
//#define IO_IS_LOW(type, name)    IO_DDR(type, name) |= (1<<IO_BIT(type, name) )    // ask if IO is low/GND
73
74
/* ------------------------------------------------------------------------- */
75
/* -------------------------- Definitons for LED's ------------------------- */
76
/* ------------------------------------------------------------------------- */
77
/*
78
 * Functions tor switch ON / OFF or Toggle an device.
79
 * The "type" oft the device can be every kind of string.
80
 * For example LED, SWITCH,..
81
 * The "name" oft the device can be every kind of string. 
82
 * For example 1,2,3,blue,red,green,yellow,...
83
 *
84
 * Attention! On and off are defined for the follwoing wiring.
85
 * DDRx must defined as output. Use for this the IO_DDR_OUTPUT(type, name) fuction.
86
 * 
87
 *  VCC
88
 *   |
89
 *   |
90
 *   X LED
91
 *   |                 VCC
92
 *   -                  |
93
 *  | | Resistor     -------
94
 *   -              |       |
95
 *   |              |uC     |
96
 *   |______________|Pin ?? |
97
 *                  |       |
98
 *                   -------
99
 *                      |
100
 *                     GND
101
 *
102
 * To use these functions you have to define:
103
 * "type"_"name"_PORTNAME and "type"_"name"_BIT
104
 * "type" and "name" must be the same string.
105
 *
106
 * Example:
107
 * #define LED_red_PORTNAME    D
108
 * #define LED_red_BIT      2
109
 *
110
 * The Data Direction Register DDRx must defined as an output!
111
 * Use the IO_DDR_OUTPUT(LED, red) function to do this.
112
 *
113
 * In programm code you can use the ON/OFF/TOGGLE("type", "name") function like this:
114
 * IO_ON(LED, red);      //red LED on Pin-D2 ON
115
 * IO_OFF(LED, red);    //red LED on Pin-D2 OFF
116
 * IO_TOGGLE(LED, red);    //red LED on Pin-D2 TOGGLE
117
 *
118
 * type##_##name##_PORTNAME  --> fils the "type" and "name" into the string
119
 *     type = LED  ->  result = LED_"name"_PORTNAME
120
 *    name = red  ->  result = "type"_red_PORTNAME
121
 *    ---> LED_red_PORTNAME
122
 */
123
124
#define IO_OFF(type, name)        IO_PORT(type, name) |= (1<<IO_BIT(type, name) )    // OFF, active low
125
#define IO_ON(type, name)        IO_PORT(type, name) &= ~(1<<IO_BIT(type, name) )  // ON, active low
126
#define IO_TOGGLE(type, name)      IO_PORT(type, name) ^= (1<<IO_BIT(type, name) )    // Toggle
127
128
129
/* ------------------------------------------------------------------------- */
130
/*
131
 * Designed for switching an pin by using Port and Bit {_PB}
132
 */
133
#define IO_OFF_PB(port, bit)      port |= (1<<bit )    // OFF, active low
134
#define IO_ON_PB(port, bit)        port &= ~(1<<bit )    // ON, active low
135
#define IO_TOGGLE_PB(port, bit)      port ^= (1<<bit )    // Toggle
136
137
#define IO_SET_INPUT_DB(ddr, bit)    ddr &= ~(1<<bit )    // set Port as input
138
#define IO_SET_OUTPUT_DB(ddr, bit)    ddr |= (1<<bit )    // set Port as output
139
140
141
/* ------------------------------------------------------------------------- */
142
/* -------------------------- Definitons for LED's ------------------------- */
143
/* ------------------------------------------------------------------------- */
144
/*
145
 * Functions tor switch ON / OFF or Toggle an device.
146
 * The "type" oft the device can be every kind of string.
147
 * For example LED, SWITCH,..
148
 * The "name" oft the device can be every kind of string. 
149
 * For example 1,2,3,blue,red,green,yellow,...
150
 *
151
 * Attention! On and off are defined for the follwoing wiring.
152
 * DDRx must defined as output. Use for this the IO_DDR_OUTPUT(type, name) fuction.
153
 *
154
 *                     VCC
155
 *                      |
156
 *                   -------
157
 *    ______________|       |
158
 *   |              |uC     |
159
 *   |              |Pin ?? |
160
 *   X Device       |       |
161
 *   |               -------
162
 *   |                   |
163
 *  GND                 GND
164
 *
165
 *
166
 * The function works same as the one above. But inverse.
167
 * The index AH in the function means Active Hight.
168
 * To switch devices with litte more current (A) use the wiring above.
169
 */
170
 
171
 
172
#define IO_ON_AH(type, name)      IO_PORT(type, name) |= (1<<IO_BIT(type, name) )    // ON, active hight
173
#define IO_OFF_AH(type, name)      IO_PORT(type, name) &= ~(1<<IO_BIT(type, name) )  // OFF, active hight
174
175
#endif /* IO_CONTROL_H_ */

und in der config.h steht dann
1
#define LED__Control              D, 7
2
3
#define LED__Alarm        B, 0
4
5
#define RELAYS__00        B, 1
6
7
#define RELAYS__01        B, 2
Angesprochen wird das dann z. B. so...
1
IO_OFF(LED, Alarm);
Möglicherweise hab ich mich an manchen Stellen etwas verkünstelt aber 
ich kann noch nicht alle Kniffe beim Makros schreiben. Vielleicht habt 
ihr mir da ja mal nen guten Link mit einer Übersicht.
Gruß
Stefan

von Mathiable (Gast)


Lesenswert?

Also, die Hardware ist nun erstellt und so wie ich es oben geschrieben 
habe, funktioniert es nicht. Kenne mich auch überhaupt nicht mit Makros 
aus. Was habe ich falsch gemacht?

von Karl H. (kbuchegg)


Lesenswert?

Mathiable schrieb:
> Also, die Hardware ist nun erstellt und so wie ich es oben geschrieben
> habe, funktioniert es nicht. Kenne mich auch überhaupt nicht mit Makros
> aus. Was habe ich falsch gemacht?

Frische Hardware?
Dann würde ich vorschlagen du benutzt erst mal die klassische, 
konventionelle Methode, um zu sehen ob die Hardware korrekt 
funktioniert, ehe du da anfängst zu künsteln.

von Mathiable (Gast)


Lesenswert?

Karl heinz Buchegger schrieb:
> Frische Hardware?
> Dann würde ich vorschlagen du benutzt erst mal die klassische,
> konventionelle Methode, um zu sehen ob die Hardware korrekt
> funktioniert, ehe du da anfängst zu künsteln.

War natürlich das erste was ich gemacht habe. Ohne einen vollständigen 
Funktions- check, beginne ich erst gar nicht zu Programmieren.

von Karl H. (kbuchegg)


Lesenswert?

Gut.

Bei Makros ist ein sinnvolles Vorgehen bei der expandierten Fassung 
anzufangen.

Dein Programm sehe so aus
1
int main()
2
{
3
  DDRA = 0xFF;
4
5
  PORTA = ( 1 << PA0 );
6
7
  while( 1 )
8
    ;
9
}

Jetzt möchtest du den Port erst mal in die Struktur verpacken, so dass 
du auf die Bits zugreifen kannst. Dazu musst du die Adresse von PORTA 
auf einen entsprechenden Pointer auf die Struktur umcasten um dann über 
diesen Pointer auf das entsprechende Member zuzugreifen.
1
typedef unsigned char  u8;
2
3
struct bits {
4
  u8 b0:1;
5
  u8 b1:1;
6
  u8 b2:1;
7
  u8 b3:1;
8
  u8 b4:1;
9
  u8 b5:1;
10
  u8 b6:1;
11
  u8 b7:1;
12
} __attribute__((__packed__));
13
14
int main()
15
{
16
  DDRA = 0xFF;
17
18
  ((volatile struct bits*)&PORTA)->b0 = 1;
19
20
  while( 1 )
21
    ;
22
}

klappt das? (testen)

von Mathiable (Gast)


Lesenswert?

Karl heinz Buchegger schrieb:
> klappt das? (testen)
>

Nein hat leider nicht geklappt. Kann es etwas damit zu tun haben, dass 
es sich um einen XMEGA handelt? Der hat ja teilweise andere Syntax, z.B. 
bei der IO Definierung.

von Karl H. (kbuchegg)


Lesenswert?

Mathiable schrieb:
> Karl heinz Buchegger schrieb:
>> klappt das? (testen)
>>
>
> Nein hat leider nicht geklappt. Kann es etwas damit zu tun haben, dass
> es sich um einen XMEGA handelt?

Das kann durchaus sein.
Da müsste man jetzt mal nachgehen, wie PORTA definiert ist. Das wird ja 
auch nur ein Makro sein, welches irgendwo in den Header Files residiert.

Nur der Vollständigkeit halber

  (*(volatile struct bits*)&PORTA).b0 = 1;

wird auch nicht gehen, oder? (Ist aus C Sicht identisch zur -> 
Schreibweise)

von Mathiable (Gast)


Lesenswert?

Karl heinz Buchegger schrieb:
> Nur der Vollständigkeit halber
>
>   (*(volatile struct bits*)&PORTA).b0 = 1;
>
> wird auch nicht gehen, oder? (Ist aus C Sicht identisch zur ->
> Schreibweise)

Ok, hab’s rausgefunden. Anstelle von PORTA muss PORTA.OUT stehen, das 
währe der XMEGA Syntax für die Port Ansteuerung. Funktioniert jetzt 
einwandfrei. Vielen Dank.

von ... (Gast)


Lesenswert?

Alternativ dazu auch 'PORTA_OUT' statt 'PORTA.OUT'.
Wobei eigentlich die die OUTSET, OUTCLR und OUTTGL Varianten noch 
interessanter sind.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.