#include <reg52.h> //此文件中定义了单片机的一些特殊功能寄存器
typedef unsigned int u16; //对数据类型进行声明定义
typedef unsigned char u8;
#ifndef uchar
#define uchar unsigned char
#endif
void LcdInit();
void lcdset(unsigned char x,unsigned char y);
void lcdshow(unsigned char x,unsigned char y);
void lcdshow1(unsigned char x,unsigned char y);
void lcdshow2(unsigned char x,unsigned char y);
sbit LCD1602_E=P2^7;
sbit LCD1602_RW=P2^5;
sbit LCD1602_RS=P2^6;
void speeds(); //显示speed
void liquid(); //显示liquid
void ml();
#define LCD1602_DATAPINS P0
void LcdWriteData(uchar dat);
u16 buf1[]={0,0,0,0};
u16 buf2[]={0,0,0,0};
u8 sp[]="speed";
void main(void)
{
LcdInit();
while(1)
{
u8 i;
for(i=0;i<16;i++)
{
LcdWriteData(sp);
} //显示speed
}
}
//***********************************************************
void Lcd1602_Delay1ms(unsigned int c) //误差 0us
{
uchar a,b;
for (; c>0; c--)
{
for (b=199;b>0;b--)
{
for(a=1;a>0;a--);
}
}
}
void LcdWriteCom(uchar com) //写入命令
{
LCD1602_E = 0; //使能
LCD1602_RS = 0; //选择发送命令
LCD1602_RW = 0; //选择写入
LCD1602_DATAPINS = com; //放入命令
Lcd1602_Delay1ms(1);
} //等待数据稳定
void LcdWriteData(uchar dat) //写入数据
{
LCD1602_E = 0; //使能清零
LCD1602_RS = 1; //选择输入数据
LCD1602_RW = 0; //选择写入
LCD1602_DATAPINS = dat; //写入数据
Lcd1602_Delay1ms(1);
LCD1602_E = 1; //写入时序
Lcd1602_Delay1ms(5); //保持时间
LCD1602_E = 0;
}
void LcdInit() //LCD初始化子程序
{
LcdWriteCom(0x38); //开显示
LcdWriteCom(0x0c); //开显示不显示光标
LcdWriteCom(0x06); //写一个指针加1
LcdWriteCom(0x80); //设置数据指针起点
}
//***************************************************************************
请大神指点,谢谢啦。
|