📄 lcd.c
字号:
/*--------------------------------------------------*/
/* AVR-ARM开发网论坛 */
/* http://www.avrarm.com */
/* AVR生成代码测试程序 */
/*--------------------------------------------------*/
/* 程序由AVR辅助开发工具V2.0.0自动生成 */
/* AVR系统的处理器为: ATMega16 */
/* AVR系统的晶振频率: 8.0000 Mhz */
/*--------------------------------------------------*/
#include <iom16v.h>
#include <macros.h>
#include "lcd.h"
#include "delay.h"
/**********************************************************
光标命令
LCD16xx_write_char(1,0x0e); //光标开
LCD16xx_write_char(1,0x0d); //光标所在字符闪烁
LCD16xx_write_char(1,0x0c); //光标关
**********************************************************/
/**********************************************************
TC16xxB LCD DISPLAY
建立时间:2006年08月30日
修改日期:2006年08月30日
LCD_write函数功能:当command=0时,向LCD写入数据,否则向LCD写
入命令
LCD第一行显示寄存器地址:0x80-0x8F
LCD第二行显示寄存器地址:0xC0-0xCF
**********************************************************/
void LCD16xx_init(void)
{
LCD_DATA_DDR |= LCD_DATA;
LCD_EN_DDR |= LCD_EN;
LCD_RS_DDR |= LCD_RS;
LCD_RW_DDR |= LCD_RW;
LCD_RW_PORT &= ~LCD_RW;
LCD_DATA_PORT = 0x20;
LCD16xx_en_write();
delay_nus(50);
LCD16xx_write_char(1,0x28); //4bit test
LCD16xx_write_char(1,0x0c); //显示开
LCD16xx_write_char(1,0x01); //显示清屏
LCD16xx_write_char(1,0x06); //显示光标移动设置
}
void LCD16xx_en_write(void) //EN端产生一个高电平脉冲,写LCD
{
LCD_EN_PORT |= LCD_EN;
delay_nus(4); //如果晶振频率太高,则可相应提高延时
LCD_EN_PORT &= ~LCD_EN;
}
/************************************************************************/
/* LCD16xx清屏 */
/************************************************************************/
void LCD16xx_clr(void)
{
LCD16xx_write_char(1,0x01);
}
/*-----------------------------------------------------------------------
LCD16xx_write_char : 英文字符串显示函数
输入参数:*s :英文字符串指针;
X、Y : 显示字符串的位置,X:0-15,Y:0-1
LCD第一行显示寄存器地址:0x80-0x8F
LCD第一行显示寄存器地址:0xC0-0xCF
编写日期 :2006年08月30日
最后修改日期 :2006年08月30日
-----------------------------------------------------------------------*/
void LCD16xx_write_char(unsigned char command,unsigned char data)
{
unsigned char datah,datal;
datah = data;
datal = data<<4 ;
//LCD16xx_wait_Ready();
LCD_RW_PORT &= ~LCD_RW; //RW=0
if (command == 0) //data
LCD_RS_PORT |= LCD_RS; //RS=1
else //command
LCD_RS_PORT &= ~LCD_RS; //RS=0
LCD_DATA_PORT &= 0x0F;
LCD_DATA_PORT |= datah&0xf0; //send high 4bit
LCD16xx_en_write();
LCD_DATA_PORT &= 0x0F;
LCD_DATA_PORT |= datal&0xf0; //send low 4bit
LCD16xx_en_write();
}
void LCD16xx_wait_Ready(void) //等待LCD空闲
{
LCD_DATA_DDR &= ~0x80; //PD7 I/O口方向设置为输入
LCD_RW_PORT |= LCD_RW; //RW=1
LCD_RS_PORT &= ~LCD_RS; //RS=0
LCD_EN_PORT |= LCD_EN; //EN=1
while (!( LCD_DATA_PIN&0x80 ) == 0); //RW=1,读PD7,为0表示空闲;
LCD_EN_PORT &= ~LCD_EN; //EN=0
LCD_DATA_DDR |= LCD_DATA;
}
/*-----------------------------------------------------------------------
LCD_set_xy : 设置LCD显示的起始位置
输入参数:x、y : 显示字符串的位置,X:0-15,Y:0-1
LCD第一行显示寄存器地址:0x80-0x8F
LCD第一行显示寄存器地址:0xC0-0xCF
编写日期 :2006年08月30日
最后修改日期 :2006年08月30日
-----------------------------------------------------------------------*/
void LCD16xx_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
if (y == 0)
address = 0x80 + x;
else if(y == 1)
address = 0xc0 + x;
else if(y == 2)
address = 0x90 + x;
else
address = 0xd0 + x;
LCD16xx_write_char( 1,address );
}
/*-----------------------------------------------------------------------
LCD16xx_write_string : 英文字符串显示函数
输入参数:*s :英文字符串指针;
X、Y : 显示字符串的位置
编写日期 :2006年08月30日
最后修改日期 :2006年08月30日
-----------------------------------------------------------------------*/
void LCD16xx_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD16xx_set_xy( X, Y );
while (*s)
{
LCD16xx_write_char( 0, *s );
s++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -