#include<reg52.h>
#define LCD_DB P2
#define PAGE 0xb8
#define COL 0x40
#define ROW 0xc0
#define OFF 0x3e
#define ON 0x3f
#define uint unsigned int
#define uchar unsigned char
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^5;
sbit cs1=P2^2;
sbit cs2=P2^3;
sbit RES=P1^2;
uint cha[]={0x00,0x00,0xc0,0x38,0xe0,0x00,0x00,0x00,0x20,0x3c,0x23,0x02,0x02,0x27,0x38,0x20};
uint code c1[]={0x20,0x20,0x30,0x30,0xA9,0x6A,0x3A,0x24,0xE4,0x2A,0x29,0x30,0x20,0x20,0x20,0x00,
0x08,0x04,0x02,0x01,0x3F,0x01,0x01,0x01,0xFF,0x01,0x21,0x61,0x3F,0x00,0x00,0x00};
uint code c2[]={0x04,0x04,0xFC,0x85,0x46,0x24,0x04,0x80,0x7E,0x2A,0x2A,0xAA,0xAA,0xFE,0x00,0x00,
0x00,0x40,0x42,0x4A,0x4A,0x4A,0x4A,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x42,0x40,0x00};
uint code c3[]={0x40,0x42,0x44,0xCC,0x00,0x08,0x28,0x48,0x89,0x0E,0xCA,0x38,0x08,0x08,0x00,0x00,
0x80,0x40,0x20,0x1F,0x20,0x40,0x50,0x48,0x44,0x43,0x44,0x48,0x50,0x40,0x40,0x00};
uint code c4[]={0x00,0xFE,0x02,0x02,0xF2,0x12,0x12,0x12,0x12,0x12,0xF2,0x02,0x02,0xFE,0x00,0x00,
0x00,0x7F,0x40,0x40,0x47,0x44,0x44,0x44,0x44,0x44,0x47,0x40,0x40,0x7F,0x00,0x00};
uchar pic_1[5]={0,0,0,0,0};
void wr_cmd(uchar);
void wr_dat(uchar);
void B_C();
void delay(uint);
void wr_char_8_16(uint,uint);
void wr_chinese_16_16(uint,uint,uint);
void wr_pic1();
void inti();
void fillscr(uint);
void clear();
void lcd_rol();
void wr_cmd(uchar cmd)
{ RS=0;
RW=0;
E=1;
LCD_DB=cmd;
delay(5);
E=0;
delay(5);
//B_C();
}
void wr_dat(uchar dat)
{ RS=1;
RW=0;
E=1;
LCD_DB=dat;
delay(5);
E=0;
delay(5);
//B_C();
}
void B_C()
{
RS=0;
RW=1;
E=1;
delay(5);
while(LCD_DB&0X80);
}
void delay(uint x)
{ int i;
while(--x!=0)
for(i=0;i<125;i++);
}
void wr_char_8_16(uint page,uint col)
{ int i,j;
for(j=0;j<2;j++)
{ wr_cmd(PAGE+page+j); //数组cha[]
wr_cmd(COL+col);
for(i=0;i<8;i++)
{ wr_dat(cha[j*8+i]);
}
}
}
void wr_chinese_16_16(uint page,uint col,uint code *chin)
{
int i,j;
for(j=0;j<2;j++)
{ wr_cmd(PAGE+page+j); //数组chin[]
wr_cmd(COL+col);
for(i=0;i<16;i++)
{ wr_dat(chin[j*16+i]);
delay(30);
}
}
}
void wr_pic1() //图片显示
{ uint i,j;
for(j=0;j<8;j++) //全屏图,故每页依次显示
{ cs1=1; //选中左页
cs2=0;
wr_cmd(PAGE+j); //从第一页开始显示
wr_cmd(COL); //从第0列开始
for(i=0;i<64;i++)wr_dat(pic_1[j*128+i]); //此页前64个数
cs1=0; //选中右页
cs2=1;
wr_cmd(PAGE+j); //从第一页开始显示
wr_cmd(COL); //从第0列开始
for(i=64;i<128;i++)wr_dat(pic_1[j*128+i]); //此页后64个数
} //换下一页
}
void inti()
{
RES=0;
RES=1;
cs1=1;
cs2=1;
wr_cmd(OFF);
delay(5);
wr_cmd(PAGE);
delay(5);
wr_cmd(ROW);
delay(5);
wr_cmd(COL);
delay(5);
wr_cmd(ON);
}
void lcd_rol() //向上滚屏
{
uchar i;
for(i = 0; i < 64; i++)
{ cs1=0;cs2=0;
wr_cmd(ROW+i);
delay(8);
}
}
main()
{ inti();
cs1=0;cs2=1;
delay(30);
wr_chinese_16_16(0,0,c1);
delay(30);
wr_chinese_16_16(0,16,c2);
delay(30);
wr_chinese_16_16(0,32,c3);
delay(30);
wr_chinese_16_16(0,48,c4);
delay(30);
cs1=1;cs2=0;
delay(30);
/* wr_chinese_16_16(0,0,c5);
delay(30);
wr_chinese_16_16(0,16,c6);
delay(30);
wr_chinese_16_16(0,32,c7);
delay(30);
wr_chinese_16_16(0,48,c8);
delay(30); */
while(1)
{
lcd_rol();
delay(10);
}
}
文章评论(0条评论)
登录后参与讨论