Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C programing regarding 1602 LCD screen

  1. Jan 23, 2012 #1
    Here's a couple of programs that I really couldn't figure out some of their lines:

    This function checks if the 1602 is busy, I suppose it means whether data are being passed to the registers of 1602:

    bit LCD_Check_Busy(void)
    DataPort= 0xFF; // Dataport is P0. What does this do? Is this some kind of initialization? Couldn't you just leave P0 alone until you really start using it?
    RS_CLR; // RS register set to 0
    RW_SET; //R@ register set to 1 (write)
    EN_SET; // Here, EN register set to 0 then set back to 1 again, thus forming a rising edge, but 1602 was enabled when a falling edge was detected? Maybe it's not trying to enable the 1602 at all? Or may be there is a "Not" logic in the circuit? But I checked the schematic, there is none?
    return (bit)(DataPort & 0x80); // I have no idea how this very crucial line works.

    I'd really appreciate your help, thanks in advance and, in case there is not sufficient information to answer those question, please let me know.
  2. jcsd
  3. Jan 24, 2012 #2
    Okay what platform is this EXACTLY?! And what compiler/tools, etc.

    DataPort: On embedded devices you will often have "register" variables that are special in the sense that when you write to them, you will not just be writing to a memory location like you would in normal C, rather the act of writing bytes to that variable has some kind of actual effect which is defined in your part documentation. "Write this bit to 1 in order to ready this other data port for reading" is an idiom I've seen before. Writing 0xFF to a variable of course writes a full byte of all 1s. I don't know what this variable does but I bet it's in your documentation somewhere.

    EN_SET: I can't know what this does without reading the documentation. It might be helpful to look up exactly what the EN_CLR and EN_SET macros do.

    "return (bit)(DataPort & 0x80);" This is bit arithmetic. "DataPort & 0x80" means "the value of Dataport, with every bit individually ANDed with 0x80". 0x80 is of course a byte with only the highest order bit set. So DataPort & 0x80 means "mask off the highest order bit of DataPort". (The fact that you previously wrote 0xFF to DataPort is irrelevant because it is probably not a normal variable.) "DataPort & 0x80" will thus always be equal to either 0x00 or 0x80. I don't know what "bit" is, but probably it's typedef'd to bool or something, so I *imagine* casting to bit has the effect of snapping it to the values "either 0x00 or 0x01", but I'd have to see how bit is defined in your headers.
  4. Jan 29, 2012 #3

    Thanks 800 pounds Coin, you helped me a great deal in figuring out those "commands" that being written to those registers. Thank you.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook