液晶屏为LM6065,控制芯片为RA8802。最基本的显示程序,显示一行字:"型号:LM6065 芯片:RA8802 " 使用PORTA端口作为数据口,PORTD.2-PORTD.6共5个脚作为控制口。 #include <mega32.h>#include <delay.h>#define uchar unsigned char // 0~255#define uint unsigned int // 0~65535 #define _LED PORTB.3#define _SPK PORTB.2#define lcd_bus PORTA#define _RS PORTD.2#define _RD PORTD.3#define _CS PORTD.4#define _WR PORTD.5#define _RST PORTD.6// 厂家:http://www.topwaydisplay.com 型号:LM6065 芯片:RA8802uchar logo[]=...{"型号:LM6065 芯片:RA8802 "};//=============================================================================// 写命令//=============================================================================void display_command_sent(uchar command)...{ _WR = 1; _RS = 0; lcd_bus = command; _CS = 0; delay_us(1); _WR = 0; delay_us(1); _WR = 1; delay_us(1); _CS = 1; delay_us(10);}//=============================================================================// 写数据//=============================================================================void display_data_sent(uchar disdata)...{ _WR = 1; _RS = 1; lcd_bus = disdata; _CS = 0; delay_us(1); _WR = 0; delay_us(1); _WR = 1; delay_us(1); _CS = 1; delay_us(10);} //=============================================================================// 清屏//=============================================================================void LCD_clean(void)...{ uint i,j; display_command_sent(0x60);display_command_sent(0x00); display_command_sent(0x70);display_command_sent(0x00); for(i = 0;i<64; i++) ...{ for(j = 0;j < 30; j++) display_data_sent(0x00); }}//=============================================================================// 初始化//=============================================================================void LCD_mode_set(void)...{ _RST = 1; _RST = 0; delay_ms(50); _RST = 1; delay_ms(20); display_command_sent(0x00);display_command_sent(0xcd); //LCD控制寄存器 display_command_sent(0x08);display_command_sent(0x73); //通用寄存器 display_command_sent(0x10);display_command_sent(0xe9); //光标控制寄存器 display_command_sent(0x18);display_command_sent(0x20); //光标大小控制寄存器 display_command_sent(0x20);display_command_sent(0x1d); //工作窗右边界寄存器 display_command_sent(0x28);display_command_sent(0x1d); //显示窗右边界寄存器 display_command_sent(0x30);display_command_sent(0x3f); //工作窗底部边界寄存器 display_command_sent(0x38);display_command_sent(0x3f); //显示窗底部边界寄存器 display_command_sent(0x40);display_command_sent(0x00); //工作窗左边界寄存器 display_command_sent(0x50);display_command_sent(0x00); //工作窗顶部边界寄存器 display_command_sent(0x48);display_command_sent(0x00); //显示窗左边界寄存器 display_command_sent(0x58);display_command_sent(0x00); //显示窗顶部边界寄存器 display_command_sent(0x60);display_command_sent(0x00); //X方向光标寄存器 display_command_sent(0x70);display_command_sent(0x00); //Y方向光标寄存器 // display_command_sent(0x80);display_command_sent(0x40); //FRCA控制寄存器(初始化时芯片建议值) display_command_sent(0x80);display_command_sent(0x23); //闪烁时间寄存器 display_command_sent(0x90);display_command_sent(0x3e); //移位时钟控制寄存器 display_command_sent(0xe0);display_command_sent(0x00); //数据模式寄存器 display_command_sent(0xf0);display_command_sent(0xa0); //字体控制寄存器 delay_ms(2);} //=============================================================================// 初始化,闪亮LED//=============================================================================void initport(void)...{ uchar i; DDRA = 0xFF; /**//* output */ PORTA = 0xFF; /**//* all off */ DDRD = 0xFF; /**//* output */ PORTD = 0xFF; /**//* all off */ DDRB = 0xFF; PORTB = 0xFF; for(i=0; i<20; i++) ...{ _LED = ~_LED; delay_ms(50); } _SPK = 0; delay_ms(150); _SPK = 1; _CS = 1; _RD = 1; _WR = 1; _RS = 1; lcd_bus = 0xff; }//=============================================================================// LCD显示LOGO//=============================================================================uchar *txtdata;void LOGO_display(void)...{ uchar i,j,tempdata; txtdata = &logo[0]; display_command_sent(0x60);display_command_sent(0x00); display_command_sent(0x70);display_command_sent(0x00); display_command_sent(0x00);display_command_sent(0xcd); for(j = 0;j < 1; j++) ...{ for(i = 0;i < 30; i++) ...{ tempdata = (*(txtdata+(j*30)+i)); display_data_sent(tempdata); } } }//=============================================================================// 主程序//=============================================================================void main(void)...{ initport( ); LCD_mode_set( ); LCD_clean( ); while(1) ...{ LOGO_display( ); delay_ms(1000); } }