C programing regarding 1602 LCD screen

  • Thread starter Alex_Sanders
  • Start date
  • Tags
    Lcd Screen
In summary, 800 pounds Coin said that there are two programs that he can't figure out, and that he would appreciate help from someone who is more familiar with them. One of the programs is an embedded device, and the other is a C program. 800 pounds Coin told the person that he is unsure what the bit arithmetic in the return statement does, and that he needs help understanding it. The person provided a summary of the conversation, and stated that the two programs are for an embedded device and a C program, and that the bit arithmetic is for setting a flag.
  • #1
Alex_Sanders
73
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
  • #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.
 
  • #3
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.
 

What is a 1602 LCD screen and how does it work?

A 1602 LCD screen is a type of display commonly used in electronic devices. It stands for "16 characters by 2 lines", meaning it can display up to 16 characters per line and has 2 lines of display. The screen works by using liquid crystal technology to create images and text on the display.

What is the role of C programming in controlling a 1602 LCD screen?

C programming is often used to control the display of information on a 1602 LCD screen. This involves writing code that sends specific commands to the screen, such as setting the cursor position or displaying text at a certain location.

What are the basic steps for displaying text on a 1602 LCD screen using C programming?

The basic steps for displaying text on a 1602 LCD screen using C programming include initializing the screen, setting the cursor position, sending the text to be displayed, and refreshing the screen. Detailed instructions and code examples can be found in the screen's datasheet or online tutorials.

Can a 1602 LCD screen be used with any microcontroller or does it require specific hardware?

A 1602 LCD screen can be used with any microcontroller that has the necessary pins and capabilities to communicate with the screen. This typically includes a data bus, control pins, and power supply connections. It is important to consult the screen's datasheet and your microcontroller's specifications to ensure compatibility.

Are there any common issues or troubleshooting tips for using C programming with a 1602 LCD screen?

Some common issues when using C programming with a 1602 LCD screen include incorrect wiring, incorrect initialization of the screen, and incorrect command or data sequences being sent. Troubleshooting tips include carefully checking connections, double-checking code, and consulting online resources for common errors and solutions.

Similar threads

  • Electrical Engineering
Replies
1
Views
2K
  • Electrical Engineering
Replies
5
Views
2K
  • Programming and Computer Science
Replies
25
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • General Math
Replies
16
Views
2K
  • Programming and Computer Science
Replies
13
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
4K
  • Electrical Engineering
Replies
6
Views
1K
Back
Top