Want to make a UNION in codewarrior 6.2 DEMOQE128

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Want to make a UNION in codewarrior 6.2 DEMOQE128

2,601件の閲覧回数
jreyes085
Contributor I

I tried this...please help

 

typedef union {
    struct {
    byte PTFD_PTFD7      :1;                                       /* Data Direction for Port D Bit 0 */
    byte PTFD_PTFD6      :1;                                       /* Data Direction for Port D Bit 1 */
    byte PTFD_PTFD5      :1;                                       /* Data Direction for Port D Bit 2 */
    byte PTFD_PTFD4      :1;                                       /* Data Direction for Port D Bit 3 */
    byte PTFD_PTFD3      :1;                                       /* Data Direction for Port D Bit 4 */
    byte PTFD_PTFD2      :1;                                       /* Data Direction for Port D Bit 5 */
    byte PTCD_PTCD6      :1;                                       /* Data Direction for Port D Bit 6 */
    byte PTCD_PTCD7      :1;                                       /* Data Direction for Port D Bit 7 */
  } Bits;
    byte busesito;
} LCD_BUS;

 

doesnt work..

 

i want to make a union for the bus data of my LCD...how tho do it_?

ラベル(1)
0 件の賞賛
返信
6 返答(返信)

1,133件の閲覧回数
jbezem
Contributor III

What do you mean with "doesn't work"? Does the compiler emit an error? If yes, which one? Does the debugger show you something? If yes, what?

Or does the executable on your demo board produce different behavior from what you expected? If yes, how different?

 

Please be more specific. At first glance, the typedef seems validif 'byte' is correctly defined (unsigned int or similar), perhaps packing maybe a problem; look at "#pragma pack(), other possibilities exist.

 

HTH,

 

Johan

0 件の賞賛
返信

1,133件の閲覧回数
jreyes085
Contributor I

What im doing is this....the script of my union is in my main.c file....

 

 #include <hidef.h>      /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "math.h"       /* include math functions */

An this is the main.c beginning "


/*********************************************************************
**  1. DEFINES QUE AYUDAN A SER MAS CLARO EL PROGRAMA
*********************************************************************/

#ifndef _medidor_pote
#define _medidor_pote

#define frecuencia_bus   24000
#define volt_gain 133
#define curr_gain 9
#define ws_wh     36           //Lo equivalente 36000 Wattseconds = 10 Watthour
                                  //36 porque el Kd es 732^-6 se lleva 3 ceros aqui
#define fs        4           //4khz hacer el filtro respectivo (6Khz pa 50armonic)
                                 //4 porque el kd es 732^-6 y se lleva los otros 3 ceros
#define kd        1
#define dc        2048             //Hallar el valor del DC en escala valor ADC
                                  //(1,5 Volt=x valor del ADC)
//xxxx#define LSB  7326             //Con 12 bits de resolucion, 3/(2^12-1)

//#define LCD_BUS     PTDD    HACER UNION!!!!           //El puerto D lo manejo como bus de datos del LCD.
#define LCD_RS      PTGD_PTGD3          //Senal de control RS del LCD 0:Instruccion 1:smileyvery-happy:ato
#define LCD_EN      PTGD_PTGD2          //Senal de control E del LCD 0:smileyvery-happy:eshabilita 1:Habilita ;x fila
#define LCD_RW      PTED_PTED6          //Senal para Read=1 Write=0
#define LCD_L2      0x40                //Direccion en DDRAM de la linea2
#define LCD_BUSY    PTCD_PTCD7

typedef union {
    struct {
    byte PTFD_PTFD7      :1;                                       /* Data Direction for Port D Bit 0 */
    byte PTFD_PTFD6      :1;                                       /* Data Direction for Port D Bit 1 */
    byte PTFD_PTFD5      :1;                                       /* Data Direction for Port D Bit 2 */
    byte PTFD_PTFD4      :1;                                       /* Data Direction for Port D Bit 3 */
    byte PTFD_PTFD3      :1;                                       /* Data Direction for Port D Bit 4 */
    byte PTFD_PTFD2      :1;                                       /* Data Direction for Port D Bit 5 */
    byte PTCD_PTCD6      :1;                                       /* Data Direction for Port D Bit 6 */
    byte PTCD_PTCD7      :1;                                       /* Data Direction for Port D Bit 7 */
  } Bits;
    byte busesito;
} LCD_BUS;

 

 

 

.....the rest of my main.c file

 

"

 

The error are in the attachment of this message...I dont know if this is wrong, in the mcf51qe.h file the unions are made...What i need is to have a variable called LCD_BUS to work all the i/o pins as a port...I dont know if i can do this...please help me...

 

 

0 件の賞賛
返信

1,133件の閲覧回数
taigbr
Contributor I

Hi,

 

if you take a look at your error messages you will see that the preprocessor

already knows a macro _PTFD and _PTCD and expands it. So your code gets messed

up and is unreadable to the compiler. Use some other names for your bits.

Kind regards,

Georg

0 件の賞賛
返信

1,133件の閲覧回数
jreyes085
Contributor I

other names? what i want to do is a link between a variable named LCD_BUS and the pins from differents ports of the MCU MCF51QE.

 

I solved yesterday by doing a function that takes every pin port registry and assign it to a value of my variable....i think i wasnt clear...what i did was this:

 

void lcd_to_bus(byte lcdtemp){

   PTFD_PTFD7=lcdtemp;

   PTFD_PTFD6=lcdtemp>>1;

   PTFD_PTFD5=lcdtemp>>2;

   PTFD_PTFD4=lcdtemp>>3;

   PTFD_PTFD3=lcdtemp>>4;

   PTFD_PTFD2=lcdtemp>>5;

   PTCD_PTCD6=lcdtemp>>6;

   PTCD_PTCD7=lcdtemp>>7;

}

 

With this function I can send to the LCD display the lcdtemp data using the LCD bus....This is what i need to do, but i will be nice to do it using an Union...

 

What did you mean with changing names? the pins i/o of the ports already has names, i want to link a variable LCD_BUS to that pins....

 

What's the best way to do it?

 

 

0 件の賞賛
返信

1,133件の閲覧回数
taigbr
Contributor I

Hi again,

 

why don't you take a look at your error_log.jpg?

Read the error messages and see what the precompiler substituted.

The names you are using are already defined somewhere.

Probably some include file.

The union was ok but you you have to use different names.

And you have to be aware that bits in structs are filled from the most

significant bit.

struct str_something

{

    byte bit7 : 1;  // this is the most significant one, 1 << 7

    ...

    byte bit0 : 1;  // 1 << 0

};

Kind regards, Georg

 

0 件の賞賛
返信

1,133件の閲覧回数
jreyes085
Contributor I

ohh my dear, i wasn't doing what i  want it to do...If i change the names, im only creating a new union between the busesito and the bits without being linked to the i/o pins ports that i want...I think i can't use an union to do what i want to do....Can I use pointers to have a link to the pins ports that i want? something like this?

 

typedef union {
    struct {
    byte bit07=*PTFD_PTFD7      :1;                                       /* Bit07 -> PTFD_PTFD7*/
    byte bit06=*PTFD_PTFD6      :1;                                      .
    byte bit05=*PTFD_PTFD5      :1;                                       .
    byte bit04=*PTFD_PTFD4      :1;                                       .
    byte bit03=*PTFD_PTFD3      :1;                                     
    byte bit02=*PTFD_PTFD2      :1;                                    
    byte bit01=*PTCD_PTCD6      :1;                                  
    byte bit00=*PTCD_PTCD7      :1;                                    
  } Bits;
    byte busesito;
} LCD_BUS;

 

I'm at my job and can't test this code...but at night im going to test it..

 

Can i do this using a pointer *? i don't know...

 

0 件の賞賛
返信