#pragma db oe sb
#include < reg51.h>
#include < absacc.h>
#define DW_ADD XBYTE[0x0000] /* LCD屏数据口写地址 */
#define CW_ADD XBYTE[0x0100] /* LCD屏指令口写地址 */
#define DR_ADD XBYTE[0x0100] /* LCD屏数据口读地址 */
#define CR_ADD XBYTE[0x0000] /* LCD屏指令口读地址 */
/* SYSTEM SET 初始化参数 P1-P8 */
unsigned char code System_set[8] = {0x30,0x87,0x07,0x27,0x42,0xf0,0x28,0x00};
/* SCROLL SET 初始化参数 P1-P10 */
unsigned char code Scroll_set[10] = {0x00,0x00,0xf0,0x00,0x40,0xf0,0x00,0x80,0x00,0x00};
/*-- 调入了一幅图像:SHARP图标.BMP --*/
/*-- 宽度x高度=144x24 --*/
数据区省掉,请点此处从本站下载此单片机驱动SED1335液晶图像显示的完整版本http://www.51hei.com/ziliao/file/sed1335的例子lm32019t.rar
void delay0() /* 延时约 ? mS */
{
register unsigned char i,j;
for(i=0;i<0x64;i++)
{
for(j=0;j<0xff;j++);
}
}
void delay1() /* 延时约 ? mS */
{
register unsigned char i,j;
for(i=0;i<0x19;i++)
{
for(j=0;j<0xff;j++);
}
}
void delay2() /* 延时约 ? mS */
{
register unsigned char h,i,j;
for(h=0;h<0x14;h++)
{
for(i=0;i<0xff;i++)
{
for(j=0;j<0xff;j++);
}
}
}
void delay3() /* 延时约 ? mS */
{
register unsigned char i;
for(i=0;i<0x96;i++);
}
void delay4() /* 延时约 ? mS */
{
register unsigned char i,j,k;
for(i=0;i<0x02;i++)
{
for(j=0;j<0xff;j++)
{
for(k=0;k<0xff;k++);
}
}
}
void LCD_order(unsigned char Order_Code)
{
/* 向LCD内部控制器发命令 */
CW_ADD = Order_Code;
}
void LCD_write(unsigned char Data_Code)
{
/* 向LCD内部控制器写入数据 */
DW_ADD = Data_Code;
}
unsigned char LCD_read()
{
/* 读当前光标处字符码 */
char Data_code;
Data_code = DR_ADD;
return(Data_code);
}
void Screen_switch(unsigned char mode_code,unsigned char control_code)
{
/* 屏幕的开与关 */
/* mode_code -为开或关的命令码(0x59 或 0x58) */
/* control_code -控制方式码 */
LCD_order(mode_code);
LCD_write(control_code);
}
void Init_system()
{
/* 系统初始化 */
unsigned char i;
LCD_order(0x40);
for(i=0;i<8;i++)
{
LCD_write(System_set[i]);
}
LCD_order(0x44);
for(i=0;i<10;i++)
{
LCD_write(Scroll_set[i]);
}
LCD_order(0x5a);
LCD_write(0x00);
LCD_order(0x5b);
LCD_write(0x0f);
Screen_switch(0x59,0x00);
}
void Locate_cursor(unsigned char high_bit,unsigned char low_bit)
{
/* 锁定光标位置 */
LCD_order(0x46);
LCD_write(low_bit);
LCD_write(high_bit);
}
void LCD_cls()
{
/* 清全屏幕 */
unsigned char i,j;
LCD_order(0x4c);
Locate_cursor(0x00,0x00);
LCD_order(0x42);
for(i=0;i<240;i++)
{
for(j=0;j<40;j++) LCD_write(0x00);
}
}
void Graph_locate(unsigned int row,unsigned char column)
{
/* 图形模式下屏幕锁定光标 */
/* row-行(以像素为单位) column-列(以字节为单位) */
unsigned int address;
unsigned char high_bit,low_bit;
address = ((row - 1) * 40) + (column - 1);
high_bit = (address >> 8) & 0xff;
low_bit = address & 0xff;
Locate_cursor(high_bit,low_bit);
}
void Picture_display(unsigned int row,unsigned char column,
unsigned char *picture_code,unsigned int width,
unsigned int high,unsigned char mode)
{
/* 图形模式下在指定行指定列显示指定大小的图形 */
/* row-行(以像素为单位) column-列(以字节为单位) *picture_code-图形数组 */
/* width-图形宽度(以像素为单位) high-图形高度(以像素为单位) */
/* mode-显示模式:1-正常 2-反白 */
unsigned char i,j,d_code;
LCD_order(0x4c);
width = width / 8;
for(i=0;i{
Graph_locate(row,column);
LCD_order(0x42);
for(j=0;j{
d_code = *picture_code;
if(mode==2) d_code = ~d_code;
LCD_write(d_code);
picture_code++;
}
row++;
}
}
void Fill_area(unsigned char row,unsigned char column,unsigned char width,
unsigned char high,unsigned char mode_code)
{
/* 图形模式下在指定行指定列填充一定的矩形区域 */
/* row-行(以像素为单位) column-列(以字节为单位) */
/* width-区域宽度(以字节为单位) high-区域高度(以像素为单位) */
/* mode_code-填充方式码 */
unsigned char i,j;
LCD_order(0x4c);
for(i=0;i{
Graph_locate(row,column);
LCD_order(0x42);
for(j=0;jrow++;
}
}
void Test_grid(bit start_mode,unsigned char grid_code)
{
/* 整屏棋盘格填充测试 */
unsigned char i,j,row,column;
bit grid_mode = start_mode;
Screen_switch(0x59,0x00);
for(i=0;i<15;i++)
{
row = i * 16 + 1;
for(j=0;j<20;j++)
{
column = j * 2 + 1;
if(grid_mode==0)
{
Fill_area(row,column,2,16,0xff);
}else
{
Fill_area(row,column,2,16,grid_code);
}
grid_mode = ~grid_mode;
}
grid_mode = ~grid_mode;
}
Screen_switch(0x59,0x04);
}
void Test_movegrid()
{
/* 屏幕中央走马灯显示测试 */
unsigned char row,column,i,j;
bit grid_mode = 0;
for(j=0;j<15;j++)
{
Screen_switch(0x59,0x00);
column = 8;
row = 81;
for(i=0;i<13;i++)
{
column = 8 + i * 2;
if(grid_mode==0)
{
Fill_area(row,column,2,16,0xff);
}else
{
Fill_area(row,column,2,16,0x00);
}
grid_mode = ~grid_mode;
}
column = 32;
row = 97;
for(i=0;i<3;i++)
{
row = 97 + i * 16;
if(grid_mode==0)
{
Fill_area(row,column,2,16,0xff);
}else
{
Fill_area(row,column,2,16,0x00);
}
grid_mode = ~grid_mode;
}
column = 32;
row = 145;
for(i=0;i<13;i++)
{
column = 32 - i * 2;
if(grid_mode==0)
{
Fill_area(row,column,2,16,0xff);
}else
{
Fill_area(row,column,2,16,0x00);
}
grid_mode = ~grid_mode;
}
column = 8;
row = 129;
for(i=0;i<3;i++)
{
row = 129 - i * 16;
if(grid_mode==0)
{
Fill_area(row,column,2,16,0xff);
}else
{
Fill_area(row,column,2,16,0x00);
}
grid_mode = ~grid_mode;
}
Screen_switch(0x59,0x04);
delay4();
grid_mode = ~grid_mode;
}
}
void Empty_screen(unsigned char mode)
{
/* 艺术化清显示屏 */
/* 1-上向下方式 1-下向上方式 3-左往右方式 4-右往左方式 */
unsigned char i,j,row,column;
LCD_order(0x4c);
if(mode==1)
{
row = 1;
for(i=0;i<240;i++)
{
column = 1;
Graph_locate(row,column);
LCD_order(0x42);
for(j=0;j<40;j++) LCD_write(0x00);
delay1();
row++;
}
}else if(mode==2)
{
row = 240;
for(i=240;i>0;i--)
{
column = 1;
Graph_locate(row,column);
LCD_order(0x42);
for(j=0;j<40;j++) LCD_write(0x00);
delay1();
row--;
}
}else if(mode==3)
{
for(column=1;column<=40;column++)
{
row = 1;
for(i=0;i<240;i++)
{
Graph_locate(row,column);
LCD_order(0x42);
LCD_write(0x00);
delay3();
row++;
}
}
}else if(mode==4)
{
for(column=40;column>=1;column--)
{
row = 1;
for(i=0;i<240;i++)
{
Graph_locate(row,column);
LCD_order(0x42);
LCD_write(0x00);
delay3();
row++;
}
}
}
}
void Move_scroll(unsigned char move_mode)
{
/* 滚屏效果 */
/* move_mode: 1-上滚屏 2-下滚屏 3-左滚屏 4-右滚屏 */
unsigned int address;
unsigned char high_bit,low_bit,i,j;
address = 0x0000;
if((move_mode==1)||(move_mode==2))
{
for(i=0;i<240;i++)
{
high_bit = (address >> 8) & 0xff;
low_bit = address & 0xff;
LCD_order(0x44);
LCD_write(low_bit);
LCD_write(high_bit);
delay0();
if(move_mode==1)
{
address = address + 40;
}else
{
address = address - 40;
}
}
}else if((move_mode==3)||(move_mode==4))
{
if(move_mode==3)
{
for(i=0;i<40;i++)
{
for(j=0;j<8;j++)
{
LCD_order(0x5a);
LCD_write(j);
}
high_bit = (address >> 8) & 0xff;
low_bit = address & 0xff;
LCD_order(0x44);
LCD_write(low_bit);
LCD_write(high_bit);
LCD_order(0x5a);
LCD_write(0x00);
delay4();
address = address + 1;
}
}else
{
for(i=0;i<40;i++)
{
for(j=7;j>=0;j--)
{
LCD_order(0x5a);
LCD_write(j);
}
high_bit = (address >> 8) & 0xff;
low_bit = address & 0xff;
LCD_order(0x44);
LCD_write(low_bit);
LCD_write(high_bit);
LCD_order(0x5a);
LCD_write(0x07);
delay4();
address = address - 1;
}
}
}
LCD_order(0x44);
LCD_write(0x00);
LCD_write(0x00);
}
void Test_LCD()
{
/* 测试液晶显示屏 */
Init_system();
LCD_cls();
Screen_switch(0x59,0x04);
while(1)
{
Picture_display(108,12,char_seg0,144,24,1);
delay2();
Test_movegrid();
delay2();
Picture_display(1,1,char_seg1,320,240,1);
delay2();
Empty_screen(1);
Test_grid(0,0x00);
delay2();
Picture_display(1,1,char_seg2,320,240,1);
delay2();
Move_scroll(3);
delay2();
Empty_screen(2);
Picture_display(1,1,char_seg3,320,240,1);
delay2();
Empty_screen(3);
Picture_display(1,1,char_seg4,320,240,1);
delay2();
Empty_screen(4);
Picture_display(1,1,char_seg5,320,240,1);
delay2();
Empty_screen(1);
Picture_display(1,1,char_seg6,320,240,2);
delay2();
Empty_screen(2);
}
}
void main()
{
/* 主程序开始 */
Test_LCD();
}