proteus 8
kile5
代码:
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^7;
uchar code k4[]={"welcome"};
uchar code k5[]={"to china!"};
void det()
{
uint i,j;
for(i=0;i<=5;i++)
{
for(j=0;j<500;j++);
}
}
void write_ml(uchar sum) //写入命令
{
RS=0; //选择命令
RW=0; //写入
P1=sum; //输入命令
det();
E=1;
det();
E=0; //开启使能,关闭使能产生 下降沿
}
void write_sj(uchar sum)//写入数据
{
RS=1; //接受数据
RW=0; //写
P1=sum; //输入数据
det();
E=1;
det();
E=0;
}
void init() //初始化程序
{
write_ml(0x38); //设置8位数据接口 ,2行显示
det();
write_ml(0x0c); //设置开显示,不显示光标
det();
write_ml(0x01); //显示清0 ,数据指针清0
det();
}
void main()
{
uint i=0;2
init();
while(1)
{
i=0;
write_ml(0x80+0x05);
while(k4[i]!='\0')
{
write_sj(k4[i]);
i++;
det();
}
write_ml(0x80+0x45);
for(i=0;i<=9;i++)
{
write_sj(k5[i]);
det();
}
}
}