📄 mylcd.c
字号:
#include "MYLCD.h"
int Lcd_i;
//char *Word;
void LCD_INIT(void)
{
Lcd_Instruct_Write(0x34);//扩展指令集
Lcd_Instruct_Write(0x30);//基本指令操作;
Lcd_Instruct_Write(0x01);//清除显示
Lcd_Instruct_Write(0x06);//指定在资料写入或读取时,光标的移动方向
Lcd_Instruct_Write(0x0C);//开显示,无光标
}
void Lcd_Instruct_Write(unsigned char Ins)
{
IsRam = 0x0; //下面进行指令操作
Delay(300);
LCD_PORT = Ins & 0xFF;//输出指令
}
void Lcd_Data_Write(unsigned char Data)
{
IsRam = 0x100; //下面进行指令操作
Delay(300);
LCD_PORT = Data & 0xFF;//输出指令
}
/*******************************************************************/
// 设置显示位置 X(1~16),Y(1~4)
/*******************************************************************/
void LCD_SetXY(unsigned char x,unsigned char y)
{
switch(y)
{
case 1:
Lcd_Instruct_Write(0X7F+x);break;
case 2:
Lcd_Instruct_Write(0X8F+x);break;
case 3:
Lcd_Instruct_Write(0X87+x);break;
case 4:
Lcd_Instruct_Write(0X97+x);break;
default:break;
}
}
/*******************************************************************/
// 在指定位置显示一半角字符(ASCII)
/*******************************************************************/
void LCD_WriteASCII(unsigned char dis_addr_x,unsigned char dis_addr_y,int dis_dat)
{
LCD_SetXY(dis_addr_x,dis_addr_y);
Lcd_Data_Write(dis_dat);
}
/*******************************************************************/
// 在指定位置显示一十六进制数
/*******************************************************************/
void LCD_DispHexData(unsigned char dis_addr_x,unsigned char dis_addr_y,int dis_dat)
{
int temp1;
//temp1=dis_dat;
temp1 =dis_dat/16;
if (temp1>9) //'A'的ASCII码为41H
temp1 += 0x37;
else
temp1 += 0x30;
LCD_SetXY(dis_addr_x,dis_addr_y);
Lcd_Data_Write(temp1);
temp1=dis_dat;
temp1 =dis_dat%16;
if (temp1>9)
temp1 += 0x37;
else
temp1 += 0x30;
Lcd_Data_Write(temp1);
}
/*******************************************************************/
// 在指定位置显示一十进制数
/*******************************************************************/
void LCD_DispDecData(unsigned char dis_addr_x,unsigned char dis_addr_y,int dis_dat)
{
int temp1;
//temp1=dis_dat;
LCD_SetXY(dis_addr_x,dis_addr_y); //先设显示首地址
temp1 =dis_dat/100; //取百位
if (temp1 !=0) //若百位为0则不显示
Lcd_Data_Write(temp1+0x30);
temp1 =(dis_dat%100)/10; //取十位
Lcd_Data_Write(temp1+0x30);
temp1 =(dis_dat%100)%10; //取个位
Lcd_Data_Write(temp1+0x30);
}
/*******************************************************************/
// 在指定位置显示字符串
/*******************************************************************/
void LCD_WriteStr(unsigned char dis_addr_x,unsigned char dis_addr_y,char *str)
{
unsigned char LCD_temp;
LCD_SetXY(dis_addr_x,dis_addr_y);
LCD_temp= *str;
while(LCD_temp != 0x00)
{
Lcd_Data_Write(LCD_temp);
LCD_temp= *(++str);
}
}
//void LCD_Delay(Uint32 num)
// {
// volatile Uint32 i;
// for (i=0;i<num;i++) { ; }
// }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -