Página 1 de 1

struct keil

MensagemEnviado: 13 Nov 2009 14:58
por deniro
olá, amigos estou com uma duvida no keil. Não consigo enviar um valor para uma estrutura, e depois acessa a parte alta e parte baixa deste valor. Segue o codigo.

#include<reg52.h>

typedef unsigned char BYTE;
typedef unsigned int WORD;


typedef struct _WORD_BYTES
{
BYTE high;
BYTE low;

}WORD_BYTES;

Alguem pode me ajudar?




void main (void)
{
WORD_BYTES dado;
BYTE bx, al;

dado = 0x8000;
bx = dado.high;
al = dado.low;

}



Alguem pode me ajudar?

MensagemEnviado: 13 Nov 2009 17:59
por barboza
Para fazer o que esta querendo vc precisa de uma union tb.



Código: Selecionar todos
typedef struct t_st_bytes
{
   char hi;
   char lo;
}

typedef union t_un_word_byte
{
   t_st_bytes bytes;
   int word;
}


main ()
{
   t_un_word_byte teste;
   char h, l;

   teste.word = 0xAA55;
   h = teste.hi;
   l = teste.lo;
}



Or something like that.....

MensagemEnviado: 14 Nov 2009 10:10
por deniro
funcionol, mas eu tive que fazer algumas mudanças

typedef struct
{
unsigned char hi;
unsigned char lo;
}t_st_bytes;

typedef union
{
t_st_bytes bytes;
int word;
}t_un_word_byte;


void main (void)
{
t_un_word_byte teste;
unsigned char h, l;

teste.word = 0x2255;
h = teste.bytes.hi;
l = teste.bytes.lo;
}