lcd1602顯示程序代碼
前些天弄了最小系統(tǒng)板后就想著學(xué)習(xí)1602的顯示程序,可惜壇子里的或網(wǎng)上的,都沒(méi)有簡(jiǎn)單的1602顯示程序,無(wú)柰在網(wǎng)上下載了一段經(jīng)過(guò)反復(fù)修改測(cè)試,終于有了下面一段代碼:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - 初始化接口
# define LCD_DB P0 // - - P0 = DB0~DB7
sbit LCD_RS=P2^0; // - - p2.0 = RS
sbit LCD_RW=P2^1; // - - p2.1 = RW
sbit LCD_E=P2^2; // - - p2.2 = E
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - 定義函數(shù)
# define uchar unsigned char
# define uint unsigned int
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - 定義子程序函數(shù)
void LCD_init(void); // - - 初始化LCD1602函數(shù)
void LCD_write_command(uchar command); // - - 向LCD1602寫(xiě)指令函數(shù)
void LCD_write_data(uchar dat); // - - 向LCD1602寫(xiě)數(shù)據(jù)函數(shù)
void LCD_set_xy(uchar x,uchar y); // - - 設(shè)置LCD1602顯示位置 X(0-16),y(1-2)
void LCD_disp_char(uchar x,uchar y,uchar dat); // - - 在LCD1602上顯示一個(gè)字符
void LCD_disp_string(uchar X,uchar Y,uchar *s); // - - 在LCD1602上顯示一個(gè)字符串
//void LCD_check_busy(void);//檢查忙函數(shù)。我沒(méi)用到此函數(shù),因?yàn)橥ㄟ^(guò)率極低。
void LCD_delay_10us(uint n); // - - 10微秒的延時(shí)子程序
void LCD_delay_50us(uint n); // - - 50微秒的延時(shí)子程序
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - 初始化LCD1602
void LCD_init(void)
{
LCD_delay_10us(20);
LCD_write_command(0x38); // - - 設(shè)置8位格式,2行,5x7
LCD_delay_10us(5);
LCD_write_command(0x0c); // - - 整體顯示,關(guān)光標(biāo),不閃爍
LCD_delay_10us(5);
LCD_write_command(0x06); // - - 設(shè)定輸入方式,增量不移位
LCD_delay_10us(5);
LCD_write_command(0x01); // - - 清除屏幕顯示
LCD_delay_50us(40);
}
//********************************
// - - 向LCD1602寫(xiě)指令
void LCD_write_command(uchar dat)
{
LCD_delay_10us(5);
LCD_RS=0; // - - 指令
LCD_RW=0; // - - 寫(xiě)入
LCD_DB=dat;
LCD_delay_10us(5);
LCD_E=1; // - - 允許
LCD_delay_10us(5);
LCD_E=0;
}
// - - 向LCD1602寫(xiě)數(shù)據(jù)
void LCD_write_data(uchar dat)
{
LCD_delay_10us(5);
LCD_RS=1;// - - 數(shù)據(jù)
LCD_RW=0;// - - 寫(xiě)入
LCD_DB=dat;
LCD_delay_10us(5);
LCD_E=1;// - - 允許
LCD_delay_10us(5);
LCD_E=0;
}
// - - 設(shè)置顯示位置
void LCD_set_xy(uchar x,uchar y)
{
uchar address;
if(y==1)
{
address=0x80+x; // - - 第一行位置
} else {
address=0xc0+x; // - - 第二行位置
}
LCD_delay_10us(5);
LCD_write_command(address);
}
// - - 顯示一個(gè)字符函數(shù)
void LCD_disp_char(uchar x,uchar y,uchar dat) // - - LCD_disp_char(0,1,0x38); // - - 顯示8
{
LCD_set_xy(x,y);
LCD_delay_10us(5);
LCD_write_data(dat);
}
// - - 顯示一個(gè)字符串函數(shù)
void LCD_disp_string(uchar x,uchar y,uchar *s)
{
LCD_set_xy(x,y);
LCD_delay_10us(5);
while(*s!=‘ 风水24山图解| 百家乐有秘技吗| bet365体育在线投注| 百家乐赌博走势图| 百家乐官网如何切牌好| 博九注册| 尊龙百家乐娱乐网| 澳门百家乐官网长赢打| 百家乐官网网址是多少| 二八杠自行车| 百家乐视频麻将游戏| 伯爵百家乐官网娱乐场| 六合彩图纸| 郑州百家乐的玩法技巧和规则| 百家乐官网赌博器| 百家乐官网真人视屏游戏| 澎湖县| 易胜博足球开户| 裕昌太阳城业主论坛| 百家乐永利娱乐场| 百家乐百家乐伴侣| 百家乐官网正品地址| 百家乐官网平台哪个好本站所有数据都是网友推荐及提供 | 澳门百家乐官网一把决战输赢| 博九开户| 大发888 yule| 威尼斯人娱乐城信誉好不好| 百家乐游戏平台有哪些哪家的口碑最好 | 百家乐长龙怎么预判| 蓝盾百家乐官网赌场娱乐网规则 | 澳门赌场娱乐城| 娱乐城注册送彩金100| 大发888的促销代码| 百家乐游戏源码手机| 百家乐程序软件| 百家乐心术| 巴黎人百家乐的玩法技巧和规则| 网上百家乐赌城| 澳门百家乐必赢看| 天猫百家乐娱乐城| 威尼斯人娱乐开户|