?? 1602液晶顯示1.c
字號(hào):
#include <iom16v.h>
#include <macros.h>
#include "1602LCD.h"
/**********************************************************
光標(biāo)命令
LCD_write_char(0x0e,0); //光標(biāo)開
LCD_write_char(0x0d,0); //光標(biāo)所在字符閃爍
LCD_write_char(0x0c,0); //光標(biāo)關(guān)
**********************************************************/
/**********************************************************
TC1602B LCD DISPLAY
建立時(shí)間:2003年11月9號(hào)
修改日期:2003年11月14號(hào)
LCD_write函數(shù)功能:當(dāng)command=0時(shí),向LCD寫入數(shù)據(jù),否則向LCD寫
入命令
LCD第一行顯示寄存器地址:0X80-0X8F
LCD第二行顯示寄存器地址:0XC0-0XCF
**********************************************************/
void LCD_init(void)
{
DDRB |= LCD_DATA | LCD_RW;
DDRB |= LCD_RS | LCD_EN;
delay_nms(15);
LCD_write_char(0x28,0); //4bit test
LCD_write_char(0x0c,0); //顯示開
LCD_write_char(0x01,0); //顯示清屏
LCD_write_char(0x06,0); //顯示光標(biāo)移動(dòng)設(shè)置
}
void LCD_en_write(void) //EN端產(chǎn)生一個(gè)高電平脈沖,寫LCD
{
LCD_EN_PORT |= LCD_EN;
delay_nus(1);
LCD_EN_PORT &= ~LCD_EN;
}
/*-----------------------------------------------------------------------
LCD_write_char : 英文字符串顯示函數(shù)
輸入?yún)?shù):*s :英文字符串指針;
X、Y : 顯示字符串的位置,X:0-15,Y:0-1
LCD第一行顯示寄存器地址:0X80-0X8F
LCD第一行顯示寄存器地址:0XC0-0XCF
編寫日期 :2003-11-19
最后修改日期 :2004-8-19
-----------------------------------------------------------------------*/
void LCD_write_char(unsigned command,unsigned data)
{
unsigned command_temp,data_temp;
command_temp = command;
data_temp = data;
LCD_wait_Ready();
LCD_RW_PORT &= ~LCD_RW; //RW=0
if (command == 0)
{
LCD_RS_PORT |= LCD_RS; //RS=1
LCD_DATA_PORT &= 0X0F;
LCD_DATA_PORT |= data_temp&0xf0; //send high 4bit
}
else
{
LCD_RS_PORT &= ~LCD_RS; //RS=0
LCD_DATA_PORT &= 0X0F;
LCD_DATA_PORT |= command_temp&0xf0;//send high 4bit
}
LCD_en_write();
command_temp=command_temp << 4; //send low 4bit
data_temp=data_temp << 4;
LCD_DATA_PORT &= 0X0F;
if (command==0)
LCD_DATA_PORT |= data_temp&0xf0;
else
LCD_DATA_PORT |= command_temp&0xf0;
LCD_en_write();
LCD_RW_PORT |= LCD_RW;
LCD_RS_PORT ^= LCD_RS;
}
void LCD_wait_Ready(void) //等待LCD空閑
{
LCD_DATA_DDR &= ~0x80; //PD7 I/O口方向設(shè)置為輸入
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 |= 0xf0;
}
/*-----------------------------------------------------------------------
LCD_set_xy : 設(shè)置LCD顯示的起始位置
輸入?yún)?shù):x、y : 顯示字符串的位置,X:0-15,Y:0-1
LCD第一行顯示寄存器地址:0X80-0X8F
LCD第一行顯示寄存器地址:0XC0-0XCF
編寫日期 :2004-8-19
最后修改日期 :2004-8-19
-----------------------------------------------------------------------*/
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 );
}
/*-----------------------------------------------------------------------
LCD_write_string : 英文字符串顯示函數(shù)
輸入?yún)?shù):*s :英文字符串指針;
X、Y : 顯示字符串的位置
編寫日期 :2004-8-19
最后修改日期 :2004-8-19
-----------------------------------------------------------------------*/
void LCD_write_str_time(unsigned char X,unsigned char Y,unsigned char *s,int i)
{
LCD_set_xy( X, Y );
while (*s)
{
LCD_write_char( 0, *s );
delay_nms(i);
s ++;
}
}
void LCD_write_str(unsigned char X,unsigned char Y,char *s)
{
LCD_set_xy( X, Y );
while (*s)
{
LCD_write_char( 0, *s );
s ++;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -