ATmega128的特點(diǎn)是io口很多,所以我們可以用并行的方式來驅(qū)動此液晶屏,增加總線的速度,此程序是是網(wǎng)上整理收集而來,但已經(jīng)通過本人驗(yàn)證可以使用,故在此發(fā)表.大家在應(yīng)用的時(shí)候只需更改相應(yīng)的io就行了.
軟件:GCC V4.20--------------------------------------------------------------- 實(shí)驗(yàn)內(nèi)容:寫Lcd12864_ST7920。---------------------------------------------------------------硬件連接:LCD12864_ST7920 ATmega1281.GND -------- GND2.VCC -------- VCC3.V0 -------- NC4.RS(CS) -------- PD75.R/W(SID) -------- PG06.E(SCLK) -------- PG17.D0 -------- PC08.D1 -------- PC19.D2 -------- PC210.D3 -------- PC311.D4 -------- PC412.D5 -------- PC513.D6 -------- PC614.D7 -------- PC715.PSB -------- VCC16.NC -------- NC17.RST -------- VCC18.NC -------- NC19.LED+ -------- VCC20.LED- -------- GND以下是程序源代碼:---------------------------------------------------------------*/ #include avr/io.h>#includeavr/pgmspace.h>#include util/delay.h> #define E_set PORTG|=_BV(PG1) //液晶使能#define E_clear PORTG=~_BV(PG1)#define RW_set PORTG|=_BV(PG0) //液晶讀寫#define RW_clear PORTG=~_BV(PG0)#define RS_set PORTD|=_BV(PD7) //液晶數(shù)據(jù)#define RS_clear PORTD=~_BV(PD7) //液晶指令unsigned char j=0;unsigned char yb=0x80;unsigned char name00[] PROGMEM={"飛射白鹿雪連天,"};unsigned char name01[] PROGMEM={"笑書神俠倚碧鴛。"};unsigned char name02[] PROGMEM={"自古英雄多奇逸,"};unsigned char name03[] PROGMEM={"金老揮毫盡使然。"};unsigned char name10[] PROGMEM={"李白乘舟將欲行,"};unsigned char name11[] PROGMEM={"忽聞岸上踏歌聲。"};unsigned char name12[] PROGMEM={"桃花潭水深千尺,"};unsigned char name13[] PROGMEM={"不及汪倫送我情。"};unsigned char name20[] PROGMEM={"this is a 12864 "};unsigned char name21[] PROGMEM={"display program,"};unsigned char name22[] PROGMEM={"welcome to commu"};unsigned char name23[] PROGMEM={"nicate with me! "};void wr_com(unsigned char);void wr_data(unsigned char);void reset (void);void outChinese(unsigned char,unsigned char,unsigned char *point);void ydgb(void);void outchar(unsigned char,unsigned char,unsigned char *point);void wr_com(unsigned char value)//寫指令,寫指令時(shí)必須為RS=0;RW=0;{E_clear;RS_clear;RW_clear;_delay_ms(1);PORTC=value; //并入字符數(shù)據(jù)E_set;_delay_ms(2); //如果沒有延時(shí)就必須要加查忙指令E_clear;}void wr_data(unsigned char sj)//寫數(shù)據(jù),寫數(shù)據(jù)時(shí)必須為 RS=1;RW=0;{E_clear;RS_set;RW_clear;_delay_ms(1);PORTC=sj;E_set;_delay_ms(1);//如果沒有延時(shí)就必須要加查忙指令E_clear;}void reset (void){wr_com(0x01);//清屏wr_com(0x08);//關(guān)顯示wr_com(0x03);//歸位wr_com(0x30);//功能設(shè)置wr_com(0x0f);//開顯示wr_com(0x01);//清屏}//****************//outChinese 為函數(shù)名//place 為顯示地址的首地址//unit 字符長度//charcode[] 要顯示數(shù)據(jù)的內(nèi)容
評論