日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀]// 1602顯示字符#include #include#define lcd_bus PORTA // 數(shù)據(jù)總線 #define rs PORTC.0 // 數(shù)據(jù)&指令選擇,H:寫數(shù)據(jù),L:寫指令 #define rw PORTC.1 // 讀&寫選擇,H:read,L:write #define e PORTC.2 // 讀寫使能

// 1602顯示字符

#include
#include

#define lcd_bus PORTA // 數(shù)據(jù)總線
#define rs PORTC.0 // 數(shù)據(jù)&指令選擇,H:寫數(shù)據(jù),L:寫指令
#define rw PORTC.1 // 讀&寫選擇,H:read,L:write
#define e PORTC.2 // 讀寫使能
#define bf 7 // 忙閑狀態(tài)標(biāo)志位,PORTA.7,H:內(nèi)部正執(zhí)行操作,L:空閑
void chk_busy(void); // 檢測LCD忙閑
void init_lcd(void); // LCD初始化
void wr_comm(unsigned char comm); // 寫指令
void wr_comm_no(unsigned char comm);// 寫指令,不檢測忙閑
void wr_data(unsigned char dat); // 寫數(shù)據(jù)
void wr_str(unsigned char flash *p); // 顯示字符串

void main()
{
delay_ms(200);
init_lcd(); //LCD初始化
wr_comm(0x80); //第一行第一個字符地址
wr_str("lcd1602");
wr_comm(0xc0); // 第二行第一個字符地址
wr_str("Tai shan Dian Zi");
while(1);
}
/*------------------LCD初始化-----------------*/
void init_lcd(void)
{
PORTA = 0xff;
PORTC = 0xff;
DDRC = 0xff; // PC輸出,控制線
DDRA = 0xff; // PA輸出,數(shù)據(jù)線
wr_comm_no(0x38); //不檢測忙閑
delay_ms(5);
wr_comm_no(0x38);
delay_ms(5);
wr_comm_no(0x38);
delay_ms(5);
wr_comm_no(0x38);
delay_ms(5);
wr_comm(0x38); // 設(shè)定LCD為16*2顯示,5*7點陣,8位數(shù)據(jù)接口,檢測忙信號
delay_us(11); // 延時11us
wr_comm(0x08); // 關(guān)閉顯示,檢測忙信號
delay_us(3);
wr_comm(0x01); // 顯示清屏,檢測忙信號
delay_us(3);
wr_comm(0x06); // 顯示光標(biāo)自動右移,整屏不移動,檢測忙信號
delay_us(3);
wr_comm(0x0c); //開顯示,不顯示光標(biāo),檢測忙信號
delay_us(3);
}
/*--------------檢測LCD忙閑---------------*/
void chk_busy(void)
{
lcd_bus=0xff;
rs=0;
rw=1;
;
e=1;
DDRA &= ~(1< delay_us(2);
while((PINA&(1< e=0;
DDRA |= 1< delay_us(2);
}
/*------------寫命令到LCD--------------*/
void wr_comm(unsigned char comm)
{
chk_busy();
rs=0;//H:寫數(shù)據(jù),L:寫指令
rw=0;
e=0;
;
lcd_bus=comm;//內(nèi)容
delay_us(3);
e=1;
;
e=0;
}
/*------------寫命令到LCD不檢測忙閑--------------*/
void wr_comm_no(unsigned char comm)
{
rs=0;//H:寫數(shù)據(jù),L:寫指令
rw=0;
e=0;
;
lcd_bus=comm;//內(nèi)容
delay_us(3);
e=1;
;
e=0;
}
/*------------寫數(shù)據(jù)到LCD--------------*/
void wr_data(unsigned char dat)
{
chk_busy();
rs=1;//H:寫數(shù)據(jù),L:寫指令
rw=0;
e=0;
;
lcd_bus=dat;//內(nèi)容
delay_us(3);
e=1;
;
e=0;
}
/*-------------寫字符串----------------*/
void wr_str(unsigned char flash *s)
{
while(*s>0) //字符串以0結(jié)束
{
wr_data(*s);
s++;
}
}

本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉