SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By vantusaonho
Code: Select all
void CParallelPortDlg::UpdatePins()
     int reg;

     if((reg & 0x40)==0) m_pin10=0;     else m_pin10=1;
     if((reg & 0x80)==0) m_pin11=0;     else m_pin11=1;
     if((reg & 0x20)==0) m_pin12=0;     else m_pin12=1;    
     if((reg & 0x10)==0) m_pin13=0;     else m_pin13=1;
     if((reg & 0x08)==0) m_pin15=0;     else m_pin15=1;
     if((reg & 0x01)==0) m_pin2=0;     else m_pin2=1;
     if((reg & 0x02)==0) m_pin3=0;     else m_pin3=1;    
     if((reg & 0x04)==0) m_pin4=0;     else m_pin4=1;
     if((reg & 0x08)==0) m_pin5=0;     else m_pin5=1;
     if((reg & 0x10)==0) m_pin6=0;     else m_pin6=1;
     if((reg & 0x20)==0) m_pin7=0;     else m_pin7=2;
     if((reg & 0x40)==0) m_pin8=0;     else m_pin8=1;
     if((reg & 0x80)==0) m_pin9=0;     else m_pin9=1;
     reg = _inp(CONTROL);

     if((reg & 0x01)==0) m_pin1=0;      else m_pin1=1;
     if((reg & 0x02)==0) m_pin14=0;     else m_pin14=1;
     if((reg & 0x04)==0) m_pin16=0;     else m_pin16=1;
     if((reg & 0x08)==0) m_pin17=0;     else m_pin17=1;


This is code that programming LPT port but i dont understand where
Code: Select all
(reg & 0x10)==0
(reg & 0x20)==0
(reg & 0x40)==0
(reg & 0x80)==0
i think they must be
Code: Select all
(reg & 0x16)==0
(reg & 0x32)==0
(reg & 0x64)==0
(reg & 0x128)==0
pls help me!
By frank26080115
the prefix "0x" indicates that the number is in base 16 (hexadecimal)
By stevech
Please don't post with "Help me!"
In english, that's an imperative - calling out a critical/dire situation.
By Liencouer
Code: Select all
if((reg & 0x40)==0) m_pin10=0;     else m_pin10=1; 

could be written like
Code: Select all
if((reg & _BV(4)) == 0){ 
     m_pin10 = 0;
     m_pin10 = 1;
its a whole bunch of 'if bit n is set in A, set bit m in B'

your snippet looks like something from the parallel lcd routines, cross mapping bits from one byte to another
By riden
Code: Select all
if((reg & 0x40)==0) m_pin10=0;     else m_pin10=1; 
could also be written as
Code: Select all
m_pin10 = (reg & 0x40) > 0;
By stevech
or more esoteric, in C

m_pin10 = (reg & 0x40) ? 1 : 0;

m_pin10 = ( (reg & 0x40) != 0); // this one adds clarity, but probably same asm code result