C programing regarding 1602 LCD screen

  • Thread starter Thread starter Alex_Sanders
  • Start date Start date
  • Tags Tags
    Lcd Screen
Click For Summary
SUMMARY

This discussion focuses on programming for the 1602 LCD screen using C, specifically analyzing the function LCD_Check_Busy. The function checks if the LCD is busy by manipulating the DataPort register and using bitwise operations to return a status. Key points include the initialization of DataPort to 0xFF, the roles of the EN_CLR and EN_SET macros, and the significance of the line return (bit)(DataPort & 0x80); which performs bit masking. Understanding the specific hardware documentation is crucial for accurate implementation.

PREREQUISITES
  • Understanding of C programming language
  • Familiarity with embedded systems concepts
  • Knowledge of bitwise operations and masking
  • Access to the 1602 LCD screen documentation
NEXT STEPS
  • Research the function and purpose of EN_CLR and EN_SET macros in embedded C programming
  • Learn about the specific register variables in embedded systems
  • Explore bitwise operations in C, focusing on masking techniques
  • Review the 1602 LCD screen datasheet for detailed operational guidelines
USEFUL FOR

Embedded systems developers, C programmers working with hardware interfaces, and anyone involved in the integration of LCD displays in electronic projects.

Alex_Sanders
Messages
73
Reaction score
0
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_CLR;
_nop_();
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.
 
Technology news on Phys.org
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.
 
Coin said:
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.


Thanks 800 pounds Coin, you helped me a great deal in figuring out those "commands" that being written to those registers. Thank you.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 13 ·
Replies
13
Views
7K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
Replies
3
Views
5K
  • · Replies 6 ·
Replies
6
Views
2K