专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

1602液晶显示汉字

作者:huqin   来源:本站原创   点击数:  更新时间:2014年04月04日   【字体:

此为变态法,操作有待提高

程序代码如下:
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code line1[] = {"welcome!"};
uchar p[]= //自定义字模数组
{
0x00,0x0f,0x04,0x0f,0x05,0x07,0x00,0x00,
0x0f,0x12,0x1f,0x15,0x1f,0x15,0x1f,0x15, //确
0x04,0x02,0x0e,0x02,0x02,0x03,0x02,0x00,
0x04,0x04,0x04,0x04,0x04,0x0a,0x11,0x00, //认
0x00,0x0f,0x09,0x06,0x06,0x06,0x09,0x00,
0x1f,0x0a,0x0e,0x0e,0x0a,0x1f,0x02,0x02 //取
};
sbit E=P2^7;
sbit RW=P2^5;
sbit RS=P2^6;
busying ()
{
bit result;
RS = 0;
RW = 1;
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
result = (bit)(P0&0x80);
E = 0;
return result;
}
writeorder (uchar cmd)
{
while (busying());
RS = 0;
RW = 0;
E = 0;
_nop_();
_nop_();
P0 = cmd;
_nop_();
_nop_();
_nop_();
_nop_();
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
E = 0;
}
writedata (uchar dat)
{
while (busying());
RS = 1;
RW = 0;
E = 0;
_nop_();
_nop_();
P0 = dat;
_nop_();
_nop_();
_nop_();
_nop_();
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
E = 0;
}
delay(uchar i)
{
while(i--)
{
uchar j=250;
while(j--)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
initial ()
{
delay (150);
writeorder (0x38); //工作方式:8位、2行、5x7
delay(5);
writeorder (0x06); //输入方式:光标右移、屏幕不动
delay(5);
writeorder (0x0c); //显示状态:显示开、有光标、不闪烁
delay(5);
writeorder (0x01); //清屏
delay(5);
}
newbyte (void) //设置自定义字符
{
uchar i,j,k=0;
uchar temp=0x40;
for(j=0;j<6;j++)
{
for(i=0;i<8;i++)
{
writeorder(temp+i);
writedata(p[k]);
k++;
}
temp += 8;
}
}
main (void)
{
uchar i=0;
initial ();
newbyte ();
writeorder (0x85); //设置第一行显示位置
writedata (0x00);
writedata (0x01);
writedata (0x02);
writedata (0x03);
writedata (0x04);
writedata (0x05);
writeorder (0xc4); //设置第二行显示位置
while(line1[i] != '\0')
{ // 显示字符"welcome!"
writedata(line1[i]);
i++;
}
while (1);
}

关闭窗口

相关文章