what does the following means in lcd interfacing program????(plz anybody help me brothers)
Code:
lcd_cmd(unsigned char item)
{
dataport=item;
ctlrport=(0<<rs)|(0<<rw)|(1<<en);//i dont understand this
delay(1);
ctrlport=(0<<rw)|(0<<rw)|(0<<en);//i dont understand this
delay(50);
return;
}
I think the problem is with the complexity here, the author of the code tried to make the code clear but it might become more complicated in an inexperienced's eyes. (S)he tried to emphasize 'rs' and 'rw' bits should be 0 when 'en' is clocked:
Code:
ctlrport=(0<<rs)|(0<<rw)|(1<<en); // rs and rw should be zero when
delay(1);
ctrlport=(0<<rw)|(0<<rw)|(0<<en); // en is clocked.
That code is basically the same as the code below:
Code:
ctlrport=(1<<en);//i dont understand this
delay(1);
ctrlport=(0<<en);//i dont understand this
Only difference is it doesn't tell about the state of 'rs' and 'rw' pins.
Apart from this being wrong because 8<<PORTA shifts 8 by PORTA bits even if you write it correctly like PORTA<<8 or PORTA>>8 the result is not what you describe, the shift operation is not rotating the content.
There isn't any operation applied to 'ctrlport' in the 1st line, it's just loaded with a new value which a '0' shifted 'en' number of times which is still a '0'. In the 2nd line it is again loaded with a new value but this time 3 values are ORed. While the '(0<<rs)' and '(0<<rw)' being '0', the 3rd however is '1' shifted 'en' number of times which concludes to a number with only its ENth bit is '1'. And when a number is ORed with '0', it's still the same number. So the result of the 2nd line is 'ctrlport' only with its ENth bit is set. Your code however clears the ENth bit of 'ctrlport' instead of loading it with a new value. Its really a matter of usage really as both codes do similar things but not exactly the same.