微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ATmega128并行控制带字库的12864程序

ATmega128并行控制带字库的12864程序

时间:08-02 来源:互联网 点击:
ATmega128的特点是io口很多,所以我们可以用并行的方式来驱动此液晶屏,增加总线的速度,此程序是是网上整理收集而来,但已经通过本人验证可以使用,故在此发表.大家在应用的时候只需更改相应的io就行了.
软件:GCC V4.20--------------------------------------------------------------- 实验内容:写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)    //液晶数据#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)//写指令,写指令时必须为RS=0;RW=0;{E_clear;RS_clear;RW_clear;_delay_ms(1);PORTC=value; //并入字符数据E_set;_delay_ms(2); //如果没有延时就必须要加查忙指令E_clear;}void wr_data(unsigned char sj)//写数据,写数据时必须为 RS=1;RW=0;{E_clear;RS_set;RW_clear;_delay_ms(1);PORTC=sj;E_set;_delay_ms(1);//如果没有延时就必须要加查忙指令E_clear;}void reset (void){wr_com(0x01);//清屏wr_com(0x08);//关显示wr_com(0x03);//归位wr_com(0x30);//功能设置wr_com(0x0f);//开显示wr_com(0x01);//清屏}//****************//outChinese 为函数名//place 为显示地址的首地址//unit  字符长度//charcode[]  要显示数据的内容 void outChinese(unsigned char place,unsigned char unit,unsigned char *point){unsigned char i,progdata;wr_com(place);for(i=0;iunit*2;i++)//一个汉字为两个字符{progdata=pgm_read_byte(point+i);wr_data(progdata);}}void outchar(unsigned char place,unsigned char unit,unsigned char *point){unsigned char i,progdata;wr_com(place);for(i=0;iunit;i++){progdata=pgm_read_byte(point+i);wr_data(progdata);}}void ydgb(void){wr_com(yb);//显示光标位置yb=yb+0x01;if(yb==0x88){yb=0x90;}if(yb==0x97){yb=0x88;}if(yb==0x8f){yb=0x98;}if(yb==0xa0){yb=0x80;}}void display1(void){ydgb();outChinese(0x80,8,name00);//第一行:80-87HoutChinese(0x90,8,name01);//第二行:90-97HoutChinese(0x88,8,name02);//第三行:88-8FHoutChinese(0x98,8,name03);//第四行:98-9FH//outchar(0x9f,2,name4);}void display2(void){ydgb();outChinese(0x80,8,name10);outChinese(0x90,8,name11);outChinese(0x88,8,name12);outChinese(0x98,8,name13);}void display3(void){ydgb();outchar(0x80,16,name20);outchar(0x90,16,name21);outchar(0x88,16,name22);outchar(0x98,16,name23);}int main(void){DDRC=0xff; //数据PORTC=0x00;DDRG=0xff; //命令PORTG=0xff;DDRD=0xff; //命令PORTD=0xff;reset();while(1){ydgb();j++;ydgb();wr_com(0x01);//清屏if(j==3)j=0;switch(j){case 0:display1();break;case 1:display2();break;case 2:display3();break;}_delay_ms(3000);}} 

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top