# include & ltreg52.h & gt
#定義uint無符號整數
#定義uchar無符號字符
#定義x1 0x80
#定義x2 0x88
#定義y 0x80
#定義通信0
#定義dat 1
sbit cs = p3^3;
sbit STD = p3^1;
sbit sclk = p3^0;
void wr_lcd (uchar dat_comm,uchar content);
無效延遲(uint us);
uchar代碼tab1[]={
“天行健君子自強不息。”
“君子高騖遠,以大德載事。”
};
uchar代碼tab31[]={
歡迎來到北京
};
uchar代碼tab32[]={
/*-傳輸了壹個圖像:F:\ beam \ drawing \ hoco 12832 . BMP-*/
/*-寬度x高度= 128x32-*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x7F,0x80,0x00,0x00,0x00,0x00,0x18,0x0C,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x01,0xFF,0x80,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x13,0x10,0x03,0xFE,0x00,
0x03,0xFF,0xC0,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x3F,0x30,0x1F,0xFF,0xC0,
0x03,0xFF,0xE0,0x00,0x00,0x00,0x00,0x8C,0x03,0xF0,0x00,0x7F,0xE0,0x7C,0x01,0xE0,
0x03,0xFF,0xF0,0x00,0x00,0x00,0x01,0x36,0x06,0xC0,0x00,0x5F,0xC0,0xFF,0xFC,0x60,
0x01,0xFF,0xF0,0x00,0x00,0x00,0x02,0x1B,0x0F,0x80,0x00,0xFF,0x01,0xFE,0x0F,0x30,
0x00,0xEF,0xF0,0x00,0x00,0x00,0x02,0x6D,0x9F,0x00,0x00,0x3E,0x03,0xFF,0xF1,0x90,
0x00,0xFF,0xF8,0x00,0x00,0x00,0x04,0x36,0xFE,0x00,0x01,0xFF,0x07,0xFF,0xFC,0x90,
0x00,0xEF,0xFF,0xFF,0x80,0x00,0x04,0xDB,0x7E,0x00,0x03,0xFF,0x87,0xFF,0xFC,0xD0,
0x00,0x0F,0xFF,0xFF,0xC0,0x00,0x04,0x6D,0xFC,0x00,0x07,0xFF,0x8F,0xFF,0xFE,0x50,
0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x04,0x36,0xFC,0x10,0x07,0xFF,0x8F,0xFF,0xFE,0x90,
0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x04,0x1B,0xF8,0x10,0x07,0xFF,0xCF,0xFF,0xFE,0x80,
0x00,0x0F,0xFF,0xFF,0xF0,0x00,0x04,0x0F,0xF8,0x10,0x07,0xFF,0xFF,0xFF,0xFA,0x00,
0x00,0x07,0xFF,0xFF,0xF0,0x00,0x04,0x07,0xF0,0x10,0x07,0xFF,0xFF,0xFF,0xFA,0x00,
0x00,0xFF,0xFF,0xFF,0xF8,0x00,0x02,0x03,0xF0,0x20,0x07,0xFF,0xFF,0xFF,0xBA,0x00,
0x00,0xFD,0xFF,0xFF,0xFC,0x00,0x02,0x03,0xF0,0x20,0x03,0xFF,0xFF,0xDF,0xB8,0x00,
0x00,0xC1,0xC0,0x3F,0xFC,0x00,0x01,0x01,0xE0,0x40,0x00,0xFF,0xFF,0xDF,0xB0,0x00,
0x00,0x81,0xC0,0x3F,0xCE,0x00,0x00,0x81,0xE0,0x80,0x00,0x7F,0xFF,0xDF,0xA0,0x00,
0x00,0x81,0x80,0x1D,0xCF,0x00,0x00,0x41,0x 1,0x00,0x00,0x3F,0xFF,0x9B,0x00,0x00,
0x01,0x83,0x80,0x1F,0xC7,0x80,0x00,0x21,0x2,0x00,0x00,0x1F,0xFD,0xB6,0x00,0x00,
0x01,0xC3,0x00,0x0E,0xE6,0x80,0x00,0x19,0xEC,0x00,0x00,0x07,0xFE,0x20,0x00,0x00,
0x00,0xC3,0x00,0x07,0x67,0x40,0x00,0x07,0xF0,0x00,0x00,0x03,0x3E,0x00,0x00,0x00,
0x00,0x02,0x00,0x03,0xE7,0xA0,0x00,0x00,0x00,0x00,0x00,0x02,0x8E,0x00,0x00,0x00,
0x00,0x06,0x00,0x03,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x00,0x00,0x00,
0x00,0x06,0x00,0x07,0x03,0x00,0x77,0x46,0x74,0x24,0x80,0x06,0x04,0x00,0x00,0x00,
0x00,0x1C,0x00,0x06,0x00,0x00,0x55,0x45,0x54,0x57,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x1C,0x00,0x0E,0x00,0x00,0x45,0x45,0x74,0x57,0x80,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1C,0x00,0x00,0x55,0x45,0x44,0x74,0x80,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x38,0x00,0x00,0x77,0x76,0x47,0x54,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar代碼tab5[]={
/*-傳輸了壹個圖像:F:\ beam \ drawing \ cock.bmp-*/
/*-寬度x高度= 128x64-*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x80,0x00,0x0F,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0C,0x43,0x01,0x80,0x00,0x7F,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x19,0xFF,0x07,0x00,0x07,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x3F,0xFC,0x1E,0x00,0x1F,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xBF,0xFF,0xFC,0x00,0x7F,0xFC,0x00,0x7F,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xFF,0xFF,0xF0,0x00,0xFF,0xC0,0x00,0x0F,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xFF,0xFF,0xE0,0x03,0xFF,0xFF,0xFC,0x01,0xF0,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xDF,0xFF,0xC0,0x07,0xFF,0xFF,0xFF,0x80,0xF0,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0xFF,0xFF,0x00,0x0F,0xFF,0xFF,0xE0,0x38,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xFF,0xF8,0x00,0x1F,0xFF,0xF0,0x03,0xF8,0x38,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xFF,0xE0,0x00,0x3F,0xFF,0xFF,0xC0,0x7C,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x04,0x7F,0xF0,0x00,0x3F,0xFF,0xFF,0xF8,0x1E,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xFF,0xF8,0x00,0x7F,0xFF,0xFF,0xFE,0x0F,0x08,0x00,0x00,0x00,
0x00、0x00、0x00、0x0F、0xFF、0xFC、0x00、0xFF、0xFF、0xFF、0x87、0x08、0x00、0x00、0x00、
0x00,0x00,0x00,0x1F,0xFF,0xFE,0x00,0xFF,0xFF,0xFF,0xFF,0x83,0x88,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0xFF,0xFE,0x01,0xFF,0xFF,0xFF,0xFF,0xC3,0x88,0x00,0x00,0x00,
0x00,0x00,0x00,0x7F,0xFF,0xFE,0x01,0xFF,0xFF,0xFF,0xFF,0xE1,0x88,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0xFE,0x03,0xFF,0xFF,0xFF,0xFF,0xE1,0x88,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFE,0x03,0xFF,0xFF,0xFF,0xFF,0xF1,0x88,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFE,0x03,0xFF,0xFF,0xFF,0xFF,0xF3,0x08,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0xF2,0x10,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0x8F,0xFF,0xFF,0xFF,0xFF,0xF0,0x20,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x ff,0x70,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0x7F,0x20,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xBF,0xFF,0x7F,0x20,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xDF,0xFF,0x7E,0x20,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xDF,0xFF,0x3E,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xCF,0xFF,0x3C,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xCF,0xFE,0x38,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0x8F,0xFE,0x38,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0x8F,0xFE,0x30,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x1F,0x7C,0x20,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFE,0x1E,0x78,0x00,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFE,0x1E,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xDA,0x3C,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xF2,0x30,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xF1,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFE,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x 07c,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x78,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x 00,
0x00,0x00,0x00,0x00,0x00,0x72,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,
0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,
0x00,0x00,0x00,0x00,0x01,0x40,0x04,0xD8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x08,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0C,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x38,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xE2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*-初始化-*/
void init_lcd (void)
{
wr_lcd (comm,0x 30);/* 30-基本命令操作*/
wr_lcd (comm,0x 01);/*清空屏幕,地址指針指向00H*/
延時(100);
wr_lcd (comm,0x 06);/*光標移動的方向*/
wr_lcd (comm,0x0c);/*顯示打開,光標關閉*/
}
/*-上屏顯示漢字或字符-*/
void chn_dispup (uchar代碼*chn)
{
uchar i,j;
wr_lcd (comm,0x 30);//30-基本命令操作
wr_lcd (comm,0x 80);//將顯示地址設置為0X80,即第壹行的第壹頁。
j = 0;
for(I = 0;我& lt16;i++)
wr_lcd (dat,CHN[j * 16+I]);
}
/*-屏幕的後半部分顯示漢字或字符-*/
void chn_dispdown (uchar代碼*chn)
{
uchar i,j;
wr_lcd (comm,0x 30);/* 30-基本命令操作*/
wr_lcd (comm,0x 90);//將顯示地址設置為0X90,即第二行的第壹頁。
j = 0;
for(I = 0;我& lt16;i++)
wr_lcd (dat,CHN[j * 16+I]);
}
/*-漢字或字符依次顯示在上半屏和下半屏-*/
void chn_disp1 (uchar代碼*chn)
{
uchar i,j;
wr_lcd (comm,0x 30);/* 30-基本命令操作*/
wr_lcd (comm,0x 80);//將顯示地址設置為0X80,即第壹行的第壹頁。
j = 0;
for(I = 0;我& lt16;i++)
wr_lcd (dat,CHN[j * 16+I]);
wr_lcd (comm,0x 90);//將顯示地址設置為0X90,即第二行的第壹頁。
j = 1;
for(I = 0;我& lt16;i++)
wr_lcd (dat,CHN[j * 16+I]);
}
/*-顯示圖形-*/
void img_disp (uchar代碼*img)
{
uchar i,j;
for(j = 0;j & lt32;j++)
{
for(I = 0;我& lt8;i++)
{
wr_lcd (comm,0x 34);//擴展指令操作
wr_lcd (comm,y+j);//首先將垂直字節坐標(y)寫入繪圖RAM地址。
wr_lcd (comm,x 1+I);//然後將水平字節坐標(x)寫入繪圖RAM地址。
wr_lcd (comm,0x 30);//基本命令操作
wr_lcd (dat,img[j * 16+I * 2]);//寫入第壹個字節
wr_lcd (dat,img[j * 16+I * 2+1]);//寫入第二個字節
}
}
for(j = 32;j & lt64;j++)
{
for(I = 0;我& lt8;i++)
{
wr_lcd (comm,0x 34);//擴展指令操作
wr_lcd (comm,y+j-32);//首先將垂直字節坐標(y)寫入繪圖RAM地址。
wr_lcd (comm,x2+I);//然後將水平字節坐標(x)寫入繪圖RAM地址。
wr_lcd (comm,0x 30);//基本命令操作
wr_lcd (dat,img[j * 16+I * 2]);//寫入第壹個字節
wr_lcd (dat,img[j * 16+I * 2+1]);//寫入第二個字節
}
}
wr_lcd (comm,0x 36);
}
/* -顯示點陣/
Voidlat _ disp (uchardata1,uchardata2)//data1,其中data2是要顯示的數據。
{
uchar i,j,k,x;
x = x 1;
for(k = 0;k & lt2;k++)
{
for(j = 0;j & lt16;j++)
{
for(I = 0;我& lt8;i++)
{
wr_lcd (comm,0x 34);//擴展指令操作
wr_lcd (comm,y+j * 2);//首先將垂直字節坐標(y)寫入繪圖RAM地址。
wr_lcd (comm,x+I);//然後將水平字節坐標(x)寫入繪圖RAM地址。
wr_lcd (comm,0x 30);//功能設置:壹次發送8位數據,基本指令集。
wr_lcd (dat,data 1);//寫入第壹個字節
wr_lcd (dat,data 1);//寫入第二個字節
}
for(I = 0;我& lt8;i++)
{
wr_lcd (comm,0x 34);//擴展指令操作
wr_lcd (comm,y+j * 2+1);//首先將垂直字節坐標(y)寫入繪圖RAM地址。
wr_lcd (comm,x+I);//然後將水平字節坐標(x)寫入繪圖RAM地址。
wr_lcd (comm,0x 30);//基本指令操作
wr_lcd (dat,data 2);//寫入第壹個字節
wr_lcd (dat,data 2);//寫入第二個字節
}
}
x = x2
}
wr_lcd (comm,0x 36);
}
/* -清除DDRAM */
void clrram (void)
{
wr_lcd (comm,0x 30);
wr_lcd (comm,0x 01);
延時(180);
}
/* - */
void wr_lcd (uchar dat_comm,uchar內容)
{
uchar a,I,j;
延遲(50);
a =內容;
cs = 1;
sclk = 0;
STD = 1;
for(I = 0;我& lt5;i++)
{
sclk = 1;
sclk = 0;
}
STD = 0;
sclk = 1;
sclk = 0;
if(dat_comm)
STD = 1;//數據
其他
STD = 0;//命令
sclk = 1;
sclk = 0;
STD = 0;
sclk = 1;
sclk = 0;
for(j = 0;j & lt2;j++)
{
for(I = 0;我& lt4;i++)
{
a = a & lt& lt1;
std = CY
sclk = 1;
sclk = 0;
}
STD = 0;
for(I = 0;我& lt4;i++)
{
sclk = 1;
sclk = 0;
}
}
}
/* - */
無效延遲(uint us)//延遲時間
{
while(us-);
}
無效延遲1(單位毫秒)
{
uint i,j;
for(I = 0;我& ltms;i++)
for(j = 0;j & lt15;j++)
延時(1);
}
/* -主程序*/
void main()
{
SP = 0x5f
init _ LCD();
while (1)
{
clr ram();
lat_disp (0x00,0x 00);//顯示點陣
delay 1(8000);
clr ram();
lat_disp (0xcc,0x cc);//顯示點陣
delay 1(8000);
clr ram();
CHN _ disp 1(tab 1);//上下屏幕依次顯示漢字或字符。
delay 1(8000);
clr ram();
lat_disp (0xff,0x 00);//顯示點陣
delay 1(8000);
img _ disp(tab 5);//顯示圖形
delay 1(8000);
clr ram();
CHN _ dispup(tab 31);//屏幕上半部分按順序顯示漢字或字符。
delay 1(8000);
clr ram();
CHN _ disp down(tab 31);//屏幕下半部分按順序顯示漢字或字符。
delay 1(8000);
}
}