文档库 最新最全的文档下载
当前位置:文档库 › LCD1602简单显示程序

LCD1602简单显示程序

#include
#include
#define uchar unsigned char

sbit RS=P2^5;
sbit RW=P2^6;
sbit E=P2^7;
void delay(unsigned char ms) // 延时子程序
{
unsigned char i;
while(ms--)
{
for(i = 0; i< 250; i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
bit busy() //读忙状态
{
bit temp;
RS=0;
RW=1;
E=1;
_nop_();
_nop_();
_nop_();
_nop_();
temp=(bit)(P0&0x80);
E=0;
return temp;
}

void enable(uchar del)//写指令
{ while(busy());
RS = 0;
RW = 0;
E = 0;
_nop_();
_nop_();
_nop_();
_nop_();
P0 = del;
_nop_();
_nop_();
_nop_();
_nop_();
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
E=0;
}
void write(uchar del)//写数据
{ while(busy());
RS = 1;
RW = 0;
E = 0;
_nop_();
_nop_();
_nop_();
_nop_();
P0 = del;
_nop_();
_nop_();
_nop_();
_nop_();
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
E=0;
}
void L1602_init(void)//初始化
{
enable(0x01);
enable(0x38);
enable(0x0c);
enable(0x06);

}
void L1602_string(uchar hang,uchar lie,uchar *p)
{
uchar a;
if(hang == 1) a = 0x80;
if(hang == 2) a = 0xc0;
a = a + lie - 1;
enable(a);
while(1)
{
if(*p == '\0') break;
write(*p);
p++;
}
}
void Main()
{
uchar i = 48;
L1602_init();
L1602_char(1,5,'b');
L1602_string(1,1,"happy newyear");
L1602_string(2,1,"cc");
while(1);
}

相关文档
相关文档 最新文档