?? 1602動(dòng)態(tài).c
字號(hào):
/*1-VSS 2-VDD 3-V0 4-RS 5-R/W 6-E 7-14 DB0-DB7 15-BLA 16-BLK*/
/*-----------------------------------------------
名稱:LCD1602
公司:上海浩豚電子科技有限公司
編寫:師訪
日期:2009.5
修改:無(wú)
內(nèi)容:通過(guò)標(biāo)準(zhǔn)程序動(dòng)態(tài)顯示字符
------------------------------------------------*/
#include<reg52.h> //包含頭文件,一般情況不需要改動(dòng),頭文件包含特殊功能寄存器的定義
sbit RS = P2^4; //定義端口
sbit RW = P2^5;
sbit EN = P2^6;
#define RS_CLR RS=0
#define RS_SET RS=1
#define RW_CLR RW=0
#define RW_SET RW=1
#define EN_CLR EN=0
#define EN_SET EN=1
/******************************************************************/
/* 微秒延時(shí)函數(shù) */
/******************************************************************/
void delay_us(unsigned int n) //延時(shí) 如果需要高精度延時(shí) 請(qǐng)嵌入?yún)R編
{
if (n == 0)
{
return ;
}
while (--n);
}
/******************************************************************/
/* 毫秒函數(shù)聲明 */
/******************************************************************/
void delay_ms(unsigned char i)
{
unsigned char a, b;
for (a = 1; a < i; a++)
{
for (b = 1; b; b++)
{ ; }
}
}
/******************************************************************/
/* 寫入命令函數(shù) */
/******************************************************************/
void LCD_write_com(unsigned char com)
{
RS_CLR;
RW_CLR;
EN_SET;
P0 = com;
delay_us(5);
EN_CLR;
}
/******************************************************************/
/* 寫入數(shù)據(jù)函數(shù) */
/******************************************************************/
void LCD_write_Data(unsigned char Data)
{
RS_SET;
RW_CLR;
EN_SET;
P0 = Data;
delay_us(5);
EN_CLR;
}
/******************************************************************/
/* 清屏函數(shù) */
/******************************************************************/
void LCD_clear(void)
{
LCD_write_com(0x01);
delay_ms(5);}
/******************************************************************/
/* 寫入字符串函數(shù) */
/******************************************************************/
void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
{
LCD_write_com(0x80 + x);
}
else
{
LCD_write_com(0xC0 + x);
}
while (*s)
{
LCD_write_Data( *s);
s ++;
}
}
/******************************************************************/
/* 寫入字節(jié)函數(shù) */
/******************************************************************/
void LCD_write_char(unsigned char x,unsigned char y,unsigned char Data)
{
if (y == 0)
{
LCD_write_com(0x80 + x);
}
else
{
LCD_write_com(0xC0 + x);
}
LCD_write_Data( Data);
}
/******************************************************************/
/* 初始化函數(shù) */
/******************************************************************/
void LCD_init(void)
{
LCD_write_com(0x38); /*顯示模式設(shè)置*/
delay_ms(5);
LCD_write_com(0x38);
delay_ms(5);
LCD_write_com(0x38);
delay_ms(5);
LCD_write_com(0x38);
LCD_write_com(0x08); /*顯示關(guān)閉*/
LCD_write_com(0x01); /*顯示清屏*/
LCD_write_com(0x06); /*顯示光標(biāo)移動(dòng)設(shè)置*/
delay_ms(5);
LCD_write_com(0x0C); /*顯示開及光標(biāo)設(shè)置*/
}
/******************************************************************/
/* 主函數(shù) */
/******************************************************************/
void main(void)
{
unsigned char i;
unsigned char *p;
delay_ms(100);
LCD_init();
while (1)
{
i = 1;
p = "www.doflye.net";
LCD_clear();
LCD_write_str(2,0,"Welcome to");
delay_ms(250);
while (*p)
{
LCD_write_char(i,1,*p);
i ++;
p ++;
delay_ms(250);
}
delay_ms(250);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -