📄 lcd._c
字号:
/*********************************Copyright (c)*********************************
** 深 圳 德 先 电 子 有 限 公 司
** 开 发 部
** http://www.t-sum.com
** 文 件 名: LCD.c
** 最后修改日期: 2005年06月8日
** 描 述: 1602液晶驱动函数
** 版 本: V1.0
** 主 控 芯 片:M16 晶振频率:8 MHZ
*******************************************************************************/
#include <iom16v.h>
#include <macros.h>
#include "function.h"
#include "define.h"
#include "defineLCD.h"
/******************************************************************************
函数定义
******************************************************************************/
void LCD_init(void) //液晶初始化
{
delay_nms(15);
LCD_write_char(0x28,0); //4位显示
LCD_write_char(0x0c,0); //显示开
LCD_write_char(0x01,0); //清屏
}
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD_set_xy( X, Y ); //写地址
while (*s) // 写显示字符
{
LCD_write_char( 0, *s );
s ++;
}
}
void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数
{
unsigned char address;
if (y == 0) address = 0x80 + x;
else
address = 0xc0 + x;
LCD_write_char( address, 0 );
}
void LCD_en_write(void) //液晶使能
{
LCD_EN_PORT|=LCD_EN;
delay_nus(1);
LCD_EN_PORT&=~LCD_EN;
}
void LCD_write_char(unsigned command,unsigned data) // 写数据
{
unsigned command_temp,data_temp;
command_temp=command;
data_temp=data;
delay_nus(16);
if(command==0)
{
LCD_RS_PORT|=LCD_RS; //RS=1
LCD_DATA_PORT&=0X0f;
LCD_DATA_PORT|=data_temp&0xf0; //写高四位
LCD_en_write();
data_temp=data_temp<<4;
LCD_DATA_PORT&=0X0f;
LCD_DATA_PORT|=data_temp&0xf0; //写低四位
LCD_en_write();
}
else
{
LCD_RS_PORT&=~LCD_RS; //RS=0
LCD_DATA_PORT&=0X0f;
LCD_DATA_PORT|=command_temp&0xf0; //写高四位
LCD_en_write();
command_temp=command_temp<<4;
LCD_DATA_PORT&=0x0f;
LCD_DATA_PORT|=command_temp&0xf0; //写低四位
LCD_en_write();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -