<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > AVR單片機驅動(dòng)的LCD2004的源程序

AVR單片機驅動(dòng)的LCD2004的源程序

作者: 時(shí)間:2016-11-18 來(lái)源:網(wǎng)絡(luò ) 收藏
/*=======================================================

20x4字符液晶主程序,編譯軟件(ICCAVR_6.31)

本文引用地址:http://dyxdggzs.com/article/201611/315729.htm

CPU內部晶振8M

數據線(xiàn)B0~B7接PORTB, E=D7 RW=D6 RS=D5

=========================================================

接線(xiàn)圖如下:

_______________ ______________

| --1|GND |

| --2|+5V |

| --3|V0 |

| | |

PD5|--------4|RS |

PD6|--------5|RW |

PD7|--------6|E |

CPU | | |

ATmmega16L PB0|--------7|D0 LCD20x4 |

PB1|--------8|D1 |

PB2|--------9|D2 |

PB3|-------10|D3 |

PB4|-------11|D4 |

PB5|-------12|D5 |

PB6|-------13|D6 |

PB7|-------14|D7 |

| | |

| --15|+LED |

| --16|-LED |

_______________| |______________|

========================================================*/

#i nclude //CPU_ATmmega16L

#define RS_H asm("sbi 0x12,5") //RS設為高電平

#define RS_L asm("cbi 0x12,5") //RS設為低電平

#define RW_H asm("sbi 0x12,6") //RW設為高電平

#define RW_L asm("cbi 0x12,6") //RW設為低電平

#define E_H asm("sbi 0x12,7") //E設為高電平

#define E_L asm("cbi 0x12,7") //E設為低電平

//=======================================================

//微秒級延時(shí)程序

void delay_us(int time)

{

do

{

time--;

}

while (time > 1);

}

//=======================================================

//毫秒級延時(shí)程序

void delay_ms(unsigned int time)

{

while(time != 0)

{

delay_us(1000);

time--;

}

}

//=======================================================

//讀取lcd是否內部操作(忙碌)狀態(tài)

char Lcd_Busy()

{

char r;

DDRB = 0x00; //端口B設為輸入方式

E_L;RS_L;RW_H; //E=0(致能),RS=0(命令),RW=1(讀)

delay_us(2); //液晶延時(shí)子程序

E_H;

delay_us(2); //液晶延時(shí)子程序

r = PINB & 0x80; //讀取lcd_data第八位

E_L;

DDRB=0xff; //端口B設為輸出方式

return r; //讀取結果返回

}

//=======================================================

//向Lcd發(fā)送命令程序

void Lcd_Command(unsigned char Command)

{

while(Lcd_Busy()); //判斷lcd是否內部操作狀態(tài)

E_L;RS_L;RW_L; //E=0(致能),RS=0(命令),RW=0(寫(xiě))

delay_us(2); //液晶延時(shí)子程序

E_H;

PORTB = Command; //向Lcd發(fā)送命令

delay_us(2); //液晶延時(shí)子程序

E_L;

}

//=======================================================

//向lcd寫(xiě)入一個(gè)字符程序

void Lcd_Write(unsigned char Data)

{

while(Lcd_Busy()); //判斷lcd是否內部操作狀態(tài)

E_L;RS_H;RW_L; //E=0(致能),RS=1(數據),RW=0(寫(xiě))

delay_us(2); //液晶延時(shí)子程序

E_H;

PORTB = Data; //向lcd寫(xiě)入一個(gè)字符

delay_us(2); //液晶延時(shí)子程序

E_L;

}

/*=======================================================

LCD第1行顯示地址1~20(0x80~0x93)

LCD第2行顯示地址1~20(0xc0~0xd3)

LCD第3行顯示地址1~20(0x94~0xa7)

LCD第4行顯示地址1~20(0xd4~0xe7)

=======================================================*/

//初始化LCD_8位接口,4行x20字符的工作方式

void Lcd_Init()

{

DDRB = 0xff; //端口B設為輸出方式

DDRD = 0xff; //端口D設為輸出方式

Lcd_Command(0x38); //

Lcd_Command(0x38); //

Lcd_Command(0x38); //

Lcd_Command(0x38); //

Lcd_Command(0x08); //令顯示器off

Lcd_Command(0x01); //清除顯示器

Lcd_Command(0x06); //令LCD每接收到1Byte數據后,AC自動(dòng)加1

Lcd_Command(0x0C); //令光標,0x0c=不顯示,0x0d=顯示閃動(dòng).

}

//=======================================================

//寫(xiě)ASCII字符串程序

void asc_tran(unsigned char *asc)

{

while((*asc) != 0) //判斷字是否結束

{

Lcd_Write(*asc); //向lcd寫(xiě)入字符串

asc++; //移下一個(gè)字符

}

}

//=======================================================

//測試主LCD主程序

void main()

{

Lcd_Init(); //初始化LCD

while(1)

{

Lcd_Command(0x83); //設置顯示位址

asc_tran("-----@_@------"); //顯示字符串

Lcd_Command(0x97); //設置顯示位址

asc_tran("www.ouravr.com"); //顯示字符串

delay_ms(1000); //延遲1秒

Lcd_Command(0x01); //清除顯示器

Lcd_Command(0x83); //設置顯示位址

asc_tran("-----^_^------"); //顯示字符串

Lcd_Command(0x94); //設置顯示位址

asc_tran("http://59.36.96.196"); //顯示字符串

delay_ms(1000); //延遲

Lcd_Command(0x01); //清除顯示器

}

}



關(guān)鍵詞: AVR單片機驅動(dòng)LCD200

評論


技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>