⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd_init.h

📁 使用IAR编写的DS1302时钟芯片驱动和4*4矩阵按键的扫描函数
💻 H
字号:
//**********************
//文件名称:LCD_INIT
//功能:液晶模块初始化
//2008.9.29
//designed by lvshichao
//*********************
//#include "io430.h"

#define BIT0_LCD 0
#define BIT1_LCD 1
#define BIT2_LCD 2
#define BIT3_LCD 3
#define BIT4_LCD 4
#define BIT5_LCD 5
#define BIT6_LCD 6
#define BIT7_LCD 7
//*********************
#define delay_num 100
//液晶模块管脚定义
/*
P45---RS
P46---R/W
P47---EN
P50---DB0
P51---DB1
P52---DB2
P53---DB3
P54---DB4
P55---DB5
P56---DB6
P57---DB7
*/
//*********************
//命令或是数据选择
//RS=0  命令
//RS=1  数据
#define RS_CLR P4OUT&=~(1<<BIT5_LCD)
#define RS_SET P4OUT|=(1<<BIT5_LCD)
#define RS_IN  P4DIR&=~(1<<BIT5_LCD)
#define RS_OUT P4DIR|=(1<<BIT5_LCD)

//读取或是写入选择
//RW=1 读
//RW=0 写
#define RW_CLR P4OUT&=~(1<<BIT6_LCD)
#define RW_SET P4OUT|=(1<<BIT6_LCD)
#define RW_IN  P4OUT&=~(1<<BIT6_LCD)
#define RW_OUT P4OUT|=(1<<BIT6_LCD)
//读写使能信号
#define EN_CLR P4OUT&=~(1<<BIT7_LCD)
#define EN_SET P4OUT|=(1<<BIT7_LCD)
#define EN_IN  P4OUT&=~(1<<BIT7_LCD)
#define EN_OUT P4OUT|=(1<<BIT7_LCD)
//---------------------------------------------------------------
//函数名称:lcd_delay()
//功能:延时
//---------------------------------------------------------------
void lcd_delay(unsigned int i)
{
while(i--);
}
//--------------------------------------------------------------
//函数名称:chk_busy()
//功能:检查液晶的繁忙状态
//--------------------------------------------------------------
void chk_busy(void)
{
 
 P5OUT=0XFF;
 lcd_delay(delay_num);
 RS_CLR;
 lcd_delay(delay_num);
 RW_SET;
 lcd_delay(delay_num);
 P5DIR=0X00;
 lcd_delay(delay_num);
 EN_SET;
 lcd_delay(delay_num);
 while(P5IN&0X80);
   EN_CLR;
 lcd_delay(delay_num);
 P5DIR=0XFF;
}
//-------------------------------------------------------------
//函数名称:LCD_write_code()
//功能:显示屏命令写入函数
//-------------------------------------------------------------
void LCD_write_code(unsigned char code)
{
chk_busy();
lcd_delay(delay_num);
RS_CLR;
lcd_delay(delay_num);
RW_CLR;
lcd_delay(delay_num);
P5OUT=code;
EN_SET;
lcd_delay(delay_num);
EN_CLR;
lcd_delay(delay_num);
}
//-----------------------------------------------------------
//函数名称:LCD_write_data()
//功能:显示屏数据写入函数
//-----------------------------------------------------------
void LCD_write_data(unsigned char data)
{
chk_busy();
lcd_delay(delay_num);
RS_SET;
lcd_delay(delay_num);
RW_CLR;
lcd_delay(delay_num);
P5OUT=data;
EN_SET;
lcd_delay(delay_num);
EN_CLR; 
lcd_delay(delay_num);
}
//----------------------------------------------------------
//函数名称:disp_char()
//功能:显示一个字符
//position--显示位置
//ascii------显示内容
//---------------------------------------------------------
void disp_char(unsigned char position,unsigned char ascii)
{
 LCD_write_code(position);
 LCD_write_data(ascii);
}
//---------------------------------------------------------
//函数名称:disp_char_str()
//功能:显示字符串
//position--起始位置
//str------字符串地址
//-------------------------------------------------------
void disp_char_str(unsigned char position,unsigned char *str)
{
 LCD_write_code(position);
 while(*str!=0)                    //含义???
      {
	   
	   LCD_write_data(*str);
	   str++;
	  }
}
//------------------------------------------------------------
//函数名称:disp_word()
//功能:汉字输入
//position--显示的起始位置
//word------汉字地址
//-----------------------------------------------------------
void disp_word(unsigned char position,unsigned char *word)
{
LCD_write_code(position);//要显示的位置
while(*word!=0)
     {
	  LCD_write_data(*word);
	  word++;
     } 
 
}
//液晶数字写入函数--7,显示07,12,显示12,16进制 --DS1302使用
void disp_number(unsigned char position,unsigned char num)
{
 unsigned char num_h;//十位
 unsigned char num_l;
 LCD_write_code(position);//要显示的位置
 if(num>=10)
   {
    num_h=(num/16);
	num_l=(num%16);
	LCD_write_data(num_h+0x30);
	LCD_write_data(num_l+0x30);
	
   } 
   else
   {
    LCD_write_data(0x30);
	LCD_write_data(num+0x30);
   }
}
//----------------------------------------------------------
//函数名称:disp_init()
//功能:显示屏初始化
//----------------------------------------------------------
void disp_init(void)
{
P5DIR=0XFF;
P4DIR=0XFF;
LCD_write_code(0x30);//功能设定/*30---基本指令动作
LCD_write_code(0x01);//清屏,地址指针指向00H
LCD_write_code(0x06);//光标的移动方向
LCD_write_code(0x0c);//光标反白显示--0x0f/*开显示,关游标
//LCD_write_code(0x0e);//显示状态开关--
//LCD_write_code(0x34);//扩展指令集
//LCD_write_code(0x04);//第一行,第三行反白显示
//LCD_write_code(0x30);
//LCD_write_code(0x02);//游标控制
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -