软件:GCC V4.20 --------------------------------------------------------------- 实验内容:写Lcd12864_ST7920。 --------------------------------------------------------------- 硬件连接: LCD12864_ST7920 ATmega128 1.GND -------- GND 2.VCC -------- VCC 3.V0 -------- NC 4.RS(CS) -------- PD7 5.R/W(SID) -------- PG0 6.E(SCLK) -------- PG1 7.D0 -------- PC0 8.D1 -------- PC1 9.D2 -------- PC2 10.D3 -------- PC3 11.D4 -------- PC4 12.D5 -------- PC5 13.D6 -------- PC6 14.D7 -------- PC7 15.PSB -------- VCC 16.NC -------- NC 17.RST -------- VCC 18.NC -------- NC 19.LED+ -------- VCC 20.LED- -------- GND 以下是程序源代码: ---------------------------------------------------------------*/ #include#include #include #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;i
上一篇:AVR单片机与74HC595的SPI显示程序
下一篇:基于AVR的4*4矩阵键盘扫描与LED显示程序
推荐阅读最新更新时间:2024-03-16 14:25