在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
芯片精品文章合集(500篇!)    创芯人才网--重磅上线啦!
查看: 2708|回复: 2

[原创] 如何在LCD1602 中显示各种想要的字符 ?

[复制链接]
发表于 2013-9-18 08:55:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x

mikroE的编译器mikroC ,mikroBasic, mikroPascal 中提供了多种附加工具,如LCD定制字符工具,GLCD位图编辑器,七段编辑器,UART终端,UDP终端,HID终端,ASCII图表,现场注释编辑器,先进的统计功能,等等


LCD定制字符工具可以设计为任意你想要显示的字符,以下以mikroC PRO for PIC编译器为例,说明如何使用LCD定制字符工具的。


比如,如果你想要在你的lcd 1602屏的第一行,第3个字符显示美元的单位符号 $  ,你可以在mikroC PRO for PIC 中打开LCD Custom Character 工具,然后点击需要显示出的字符,在此工具窗口的底部有两个图标:Generate Code ,CopyCode to Clipboard , 先点第一个Generate Code  ,生成代码后,再点击CopyCode to Clipboard ,然后把代码粘贴到编译器的代码编辑器中。

图片1.jpg


图片2.jpg




代码如下:

// Lcd module connections

sbit LCD_RS at LATB4_bit;

sbit LCD_EN at LATB5_bit;

sbit LCD_D4 at LATB0_bit;

sbit LCD_D5 at LATB1_bit;

sbit LCD_D6 at LATB2_bit;

sbit LCD_D7 at LATB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;

sbit LCD_EN_Direction at TRISB5_bit;

sbit LCD_D4_Direction at TRISB0_bit;

sbit LCD_D5_Direction at TRISB1_bit;

sbit LCD_D6_Direction at TRISB2_bit;

sbit LCD_D7_Direction at TRISB3_bit;

// End Lcd module connections


const char character[] = {4,14,21,12,6,21,14,4};

void CustomChar(char pos_row, char pos_char) {

  char i;

    Lcd_Cmd(64);

    for (i = 0; i<=7; i++) Lcd_Chr_CP(character);

    Lcd_Cmd(_LCD_RETURN_HOME);

    Lcd_Chr(pos_row, pos_char, 0);

}

void main(){

  ANSELB = 0;                        // Configure PORTB pins as digital

  Lcd_Init();                        // Initialize Lcd

  Lcd_Cmd(_LCD_CLEAR);               // Clear display

  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

   CustomChar(1,3);

}




如果要在LCD中显示两种定制的字符,请参考以下的代码。

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections



// The first  custom character
const char characterUp[] = {0,4,4,10,17,4,4,4};


void CustomCharUp(char pos_row, char pos_char) {
  char i;
    Lcd_Cmd(64);
    for (i = 0; i<=7; i++) Lcd_Chr_CP(characterUp);
    Lcd_Cmd(_LCD_RETURN_HOME);
    Lcd_Chr(pos_row, pos_char, 0);
}
// End of the first  custom character

// The second  custom character
const char characterDown[] = {4,4,4,4,17,10,4,4};

void CustomCharDown(char pos_row, char pos_char) {
  char i;
    Lcd_Cmd(64);
    for (i = 0; i<=7; i++) Lcd_Chr_CP(characterDown);
    Lcd_Cmd(_LCD_RETURN_HOME);
    Lcd_Chr(pos_row, pos_char, 0);
}
//End  of the second  custom character

void main() {

    ANSEL = 0;
    ANSELH = 0;
   
     C1ON_bit = 0;
    C2ON_bit = 0;

     Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);   

     while(1){
    CustomCharUp(1,1);
    Delay_ms(1000);
    Lcd_Cmd(_LCD_CLEAR);
    CustomCharDown(2,1);
    Delay_ms(1000);
    Lcd_Cmd(_LCD_CLEAR);
    }

关于mirkoE 的编译器请参考 :http://www.hkemsys.com/ProductList.asp?ID=500&SortID=500&SortPath=0,500,
 楼主| 发表于 2013-9-18 09:02:28 | 显示全部楼层
附上一个字符定制的参考图 :

2x16charset_LCD定制.jpg
发表于 2013-9-21 17:45:44 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-1 02:51 , Processed in 0.026261 second(s), 10 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表