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!=‘ 百乐坊百家乐娱乐城| 澳门百家乐走势图| 棋牌娱乐城注册送58| 中原百家乐官网的玩法技巧和规则 | 破解百家乐官网真人游戏| 永利高现金网可信吗| 网上百家乐有没有假| 百家乐官网下注瀛钱法| 战神百家乐官网的玩法技巧和规则| 安图县| 大发888网页多少| 百家乐游戏程序出售| 百家乐官网大轮转| 讷河市| 大发888娱乐城dmwd| 百家乐庄闲和收益| 蓝盾百家乐官网的玩法技巧和规则 | 888棋牌游戏| 百家乐官网赌场信息| 融水| 视频棋牌游戏| 大发888娱乐场 下载| 百家乐稳赢秘笈| 百家乐有几种打法| 沙龙百家乐官网娱乐场开户注册| 百家乐官网网络视频游戏| 10BET娱乐城| 博彩机| 大发888娱乐场玩什么| 博彩百家乐带连线走势图| 在线百家乐怎么下注| 华盛顿百家乐官网的玩法技巧和规则 | 六合彩网页| 大发888下载删除| 赌百家乐2号破解| 百家乐网上真钱娱乐| 百家乐高额投注| 百家乐视频多开器| 百家乐体育直播| 澳门百家乐心德| 免费百家乐官网追号工具|