Nightcrawler escreveu:Estou usando a SPI do Z8F0822, pra se comunicar com um HT1380. Só que a o padrão de envio e recebimento do HT1380 é iniciando pelo LSB. Pelo que eu li, o Z8F0822 inica somente pelo MSB. Como poderia fazer uma rotina para inverter os bits MSB pelos LSB ?? Programo em C.
unsigned char inverte_bits(unsigned char dado)
{
unsigned char d = 0;
if(dado & 0x80) d |= 1;
if(dado & 0x40) d |= 2;
if(dado & 0x20) d |= 4;
if(dado & 0x10) d |= 8;
if(dado & 8) d |= 0x10;
if(dado & 4) d |= 0x20;
if(dado & 2) d |= 0x40;
if(dado & 1) d |= 0x80;
return d;
}
eletroinf escreveu:Eita...
Que mão de obra...
Pode fazer assim:
unsigned char near teste; //Variável global, usa o near (pág. direta)
Daí, no programa:
asm("BSWAP teste"); //Pronto, faz o que tu quer!
Rodrigo_P_A escreveu:kra, esta instrução troca os NIBBLES ela num inverte os bits, ou inverte?
eletroinf escreveu:unsigned char near teste; //Variável global, usa o near (pág. direta)
Daí, no programa:
asm("BSWAP teste"); //Pronto, faz o que tu quer!
unsigned char Zswap_bits( unsigned char data_byte)
{
static unsigned char temp_value;
temp_value = data_byte;
asm("ldx R0,_0temp_value"); // Static variables to be
// prefixed by_0
asm("bswap R0"); // when accessing through the assembly
function
asm("ldx _0temp_value, R0");
}
Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante