DDRAM is the Display Data RAM for these modules which represents the hexadecimal Display data adresses。 See below:
至此,我们已经知道了足够的信息,现在我们可以编写代码让我们的LCD活动起来了。在我的程序里,有三个非常重要的函数:Prepare_LCD|move_to_specific|button_Write_to_Screen_Click。 下面的代码是Prepare_LCD函数: private void Prepare_LCD(int cursor_status) { /* Look at the instruction table to make these comments make sense */ /* Thread。Sleep() function is not needed for some type of LCD instructions * and also this is changeable from an LCD * to another so tryout the best for your module */ /* Sends 12(d) = 1100 binary to open the entire display and * makes a delay that LCD needs for execution */ if(cursor_status == 0) PortAccess。Output(data, 12); //Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* Sends 14(d) = 1110 binary to open the entire display * and makes the cursor active and also * makes a delay that LCD needs for execution */ if(cursor_status == 1) PortAccess。Output(data, 14); //Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* Sends 15(d) = 1111 binary to open the entire display, makes * the cursor active and blink and also * makes a delay that LCD needs for execution */ if(cursor_status == 2) PortAccess。Output(data, 15); //Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* Makes the enable pin high and register pin low */ PortAccess。Output(control, 8); Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* Makes the enable pin low for LCD to read its * data pins and also register pin low */ PortAccess。Output(control, 9); Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* Clears entire display and sets DDRAM address * 0 in address counter */ PortAccess。Output(data, 1); //Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* Makes the enable pin high and register pin low */ PortAccess。Output(control, 8); Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* Makes the enable pin low for LCD to read its * data pins and also register pin low */ PortAccess。Output(control, 9); Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* We are setting the interface data length to 8 bits * with selecting 2-line display and 5 x 7-dot character font。 * Lets turn the display on so we have to send */ PortAccess。Output(data, 56); //Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* Makes the enable pin high and register pin low */ PortAccess。Output(control, 8); Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article /* Makes the enable pin low for LCD to read its * data pins and also register pin low */ PortAccess。Output(control, 9); Thread。Sleep(1); //The delays can be smaller, Check Busy Flag info in the article }
move_to_specific函数可以移动光标到屏幕上任何位置: private void move_to_specific(int line, int column) { /* Makes the RS pin low */ PortAccess。Output(control, 8); //Thread。Sleep(1); if(line == 1) { /* Sets RAM address so that the cursor is positioned * at a specific column of the 1st line。 */ PortAccess。Output(data, 127+column); //Thread。Sleep(1); } if(line == 2) { /* Sets RAM address so that the cursor * is positioned at a specific column of the 2nd line。 */ PortAccess。Output(data, 191+column); //Thread。Sleep(1); } }
看下面的Ascii码和二进制码转换表,你可以明白button_Write_to_screen_Click函数的作用: 现在你可以看看这个函数到底是如何实现的,我不打算把代码放在这里,因为我不想让我的这篇文章难于阅读。 注意:如果LCD执行的时间非常快,你可以激活Thread。Sleep函数。 写在最后有人可能要问“我自己编写程序控制LCD有什么好处?”其实这完全是个人爱好,但如果想象一下,我们用自己编写的LCD显示从网络上获取的CodeProject的新闻,那是多么美妙的事情。 关于译者Aweay是学生。他目前大四,对基于组件技术的软件设计有深入研究。任CSDN C++Builder板块版主,可以通过 siney@yeah。net 与他联系,同时欢迎你访问他的网站 http://siney。yeah。net。
| 相关文章: 相关软件: |