STC12C5A60S2 液晶显示什么都没有是哪的问题
时间:10-02
整理:3721RD
点击:
#include "STC12c5a60s2.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define LCD_Data P0
sbit LCD_RS = P2^7;
sbit LCD_EN = P2^5;
sbit LCD_RW = P2^6;
void Delay5ms();
void Delay400ms();
void LCD_WriteCommand(uchar Cmd);
void LCD_WriteData(uchar Data);
void LCD_WriteAddress(uchar x);
void LCD_WriteString(uchar *p);
void Init_LCD();
void LCD_WriteCommand(uchar Cmd)
{
LCD_Data = Cmd;
LCD_RS = 0;
LCD_EN = 0;
_nop();
_nop();
_nop();
LCD_EN = 1;
Delay5ms(); //延时5ms ,给硬件一点反应时间
}
void LCD_WriteData(uchar Data)
{
LCD_Data = Data; //把要写的数据放到数据线上
LCD_RS = 1; //写数据
LCD_EN = 0; //拉低LCD_EN线,将数据线的状态锁存在LCD内
_nop();
LCD_EN = 1;
_nop();
_nop();
_nop();
LCD_EN = 0; //拉低LCD_EN线
Delay5ms(); //延时5ms ,给硬件一点反应时间
}
void LCD_WriteAddress(uchar x)
{
LCD_WriteCommand(x|0x80); //显示位置的确定方法规定为"80H+地址码x"
}
void LCD_WriteString(uchar *p) //输入字符串函数
{
while( (*p) != '\0' ) //如果没有达到字符串结尾,则显示该字符
{
LCD_WriteData(*p); //调用写字符函数向LCD写入一个字符
p++; //指向字符串中下一个字符
}
}
void Init_LCD()
{
LCD_Data = 0;
LCD_WriteCommand(0x38); //连续三次显示模式设置,确保初始化成功
LCD_WriteCommand(0x38);
LCD_WriteCommand(0x38);
LCD_WriteCommand(0x01); //显示清屏
LCD_WriteCommand(0x06); // 显示光标移动设置
LCD_WriteCommand(0x0C); // 显示开及光标设置
}
void main()
{
LCD_RW = 0;
Delay400ms(); //启动等待,等LCD讲入工作状态
Init_LCD(); //LCD初始化
LCD_WriteCommand(0x38);
LCD_WriteCommand(0x0f);
LCD_WriteAddress(0x00); //显示位置的确定方法规定为"80H+地址码x"
LCD_WriteString("temp:");
}
void Delay400ms() [url=]//@12.000MHz[/url]
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 19;
j = 62;
k = 43;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Delay5ms() [url=]//@12.000MHz[/url]
{
unsigned char i, j;
i = 59;
j = 90;
do
{
while (--j);
} while (--i);
}
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define LCD_Data P0
sbit LCD_RS = P2^7;
sbit LCD_EN = P2^5;
sbit LCD_RW = P2^6;
void Delay5ms();
void Delay400ms();
void LCD_WriteCommand(uchar Cmd);
void LCD_WriteData(uchar Data);
void LCD_WriteAddress(uchar x);
void LCD_WriteString(uchar *p);
void Init_LCD();
void LCD_WriteCommand(uchar Cmd)
{
LCD_Data = Cmd;
LCD_RS = 0;
LCD_EN = 0;
_nop();
_nop();
_nop();
LCD_EN = 1;
Delay5ms(); //延时5ms ,给硬件一点反应时间
}
void LCD_WriteData(uchar Data)
{
LCD_Data = Data; //把要写的数据放到数据线上
LCD_RS = 1; //写数据
LCD_EN = 0; //拉低LCD_EN线,将数据线的状态锁存在LCD内
_nop();
LCD_EN = 1;
_nop();
_nop();
_nop();
LCD_EN = 0; //拉低LCD_EN线
Delay5ms(); //延时5ms ,给硬件一点反应时间
}
void LCD_WriteAddress(uchar x)
{
LCD_WriteCommand(x|0x80); //显示位置的确定方法规定为"80H+地址码x"
}
void LCD_WriteString(uchar *p) //输入字符串函数
{
while( (*p) != '\0' ) //如果没有达到字符串结尾,则显示该字符
{
LCD_WriteData(*p); //调用写字符函数向LCD写入一个字符
p++; //指向字符串中下一个字符
}
}
void Init_LCD()
{
LCD_Data = 0;
LCD_WriteCommand(0x38); //连续三次显示模式设置,确保初始化成功
LCD_WriteCommand(0x38);
LCD_WriteCommand(0x38);
LCD_WriteCommand(0x01); //显示清屏
LCD_WriteCommand(0x06); // 显示光标移动设置
LCD_WriteCommand(0x0C); // 显示开及光标设置
}
void main()
{
LCD_RW = 0;
Delay400ms(); //启动等待,等LCD讲入工作状态
Init_LCD(); //LCD初始化
LCD_WriteCommand(0x38);
LCD_WriteCommand(0x0f);
LCD_WriteAddress(0x00); //显示位置的确定方法规定为"80H+地址码x"
LCD_WriteString("temp:");
}
void Delay400ms() [url=]//@12.000MHz[/url]
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 19;
j = 62;
k = 43;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Delay5ms() [url=]//@12.000MHz[/url]
{
unsigned char i, j;
i = 59;
j = 90;
do
{
while (--j);
} while (--i);
}