#include <stdio.h>
#include <math.h>
#include <reg52.h>
#include <string.h>
unsigned char code IC_DAT[];
unsigned char code pic1[];
unsigned char code pic2[];
unsigned char code pic3[];
sbit RS =P2^4;
sbit WRD=P2^5;
sbit E= P2^6;
sbit PSB=P2^1;
sbit RES=P2^3;
void TransferData(char data1,bit DI);
void display(void);
void display_grapic(void);
void delayms(unsigned int n);
void DisplayLine(unsigned char line1,unsigned char line2);
void DisplayGraphic(unsigned char code *adder);
void delay(unsigned int m);
void lcd_mesg(unsigned char code *adder1);
unsigned char code IC_DAT[]={
"上海浩豚电子科技"
"单片机开发板系列"
"中文字库测试程序"
"恭喜发财身体健康"
};
unsigned char code IC_DAT2[]={
"海纳百川宽容为先"
"欲成大业诚信为先"
"游弋商海济世为先"
"人立于世守法为先"
};
void initinal(void) //LCD字库初始化程序
{
delay(40); //大于40MS的延时程序
PSB=1; //设置为8BIT并口工作模式
delay(1); //延时
RES=0; //复位
delay(1); //延时
RES=1; //复位置高
delay(10);
TransferData(0x30,0); //Extended Function Set :8BIT设置,RE=0: basic instruction set, G=0 :graphic display OFF
delay(100); //大于100uS的延时程序
TransferData(0x30,0); //Function Set
delay(37); ////大于37uS的延时程序
TransferData(0x08,0); //Display on Control
delay(100); //大于100uS的延时程序
TransferData(0x10,0); //Cursor Display Control光标设置
delay(100); //大于100uS的延时程序
TransferData(0x0C,0); //Display Control,D=1,显示开
delay(100); //大于100uS的延时程序
TransferData(0x01,0); //Display Clear
delay(10); //大于10mS的延时程序
TransferData(0x06,0); //Enry Mode Set,光标从右向左加1位移动
delay(100); //大于100uS的延时程序
}
void initina2(void) //LCD显示图片(扩展)初始化程序
{
delay(40); //大于40MS的延时程序
PSB=1; //设置为8BIT并口工作模式
delay(1); //延时
RES=0; //复位
delay(1); //延时
RES=1; //复位置高
delay(10);
TransferData(0x36,0); //Extended Function Set RE=1: extended instruction
delay(100); //大于100uS的延时程序
TransferData(0x36,0); //Extended Function Set:RE=1: extended instruction set
delay(37); ////大于37uS的延时程序
TransferData(0x3E,0); //EXFUNCTION(DL=8BITS,RE=1,G=1)
delay(100); //大于100uS的延时程序
TransferData(0x01,0); //CLEAR SCREEN
delay(100); //大于100uS的延时程序
}
void main(void)
{
while(1)
{
initina2(); //调用LCD显示图片(扩展)初始化程序
DisplayGraphic(pic2); //显示图片2
delayms(200);
DisplayGraphic(pic3); //显示图片3
delayms(200);
initinal(); //调用LCD字库初始化程序
delay(100); //大于100uS的延时程序
lcd_mesg(IC_DAT); //显示中文汉字1
delayms(240);
delayms(240);
initinal(); //调用LCD字库初始化程序
delay(100); //大于100uS的延时程序
lcd_mesg(IC_DAT2); //显示中文汉字2
delayms(240);
delayms(240);
}
}
void lcd_mesg(unsigned char code *adder1)
{
unsigned char i;
TransferData(0x80,0); //Set Graphic Display RAM Address
delay(100);
for(i=0;i<32;i++)
{
TransferData(*adder1,1);
adder1++;
}
TransferData(0x90,0); //Set Graphic Display RAM Address
delay(100);
for(i=32;i<64;i++)
{
TransferData(*adder1,1);
adder1++;
}
}
void TransferData(char data1,bit DI) //传送数据或者命令,当DI=0是,传送命令,当DI=1,传送数据.
{
WRD=0;
RS=DI;
delay(1);
P0=data1;
E=1;
delay(1);
E=0;
}
void delayms(unsigned int n) //延时10×n毫秒程序
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<2000;j++);
}
void delay(unsigned int m) //延时程序
{
unsigned int i,j;
for(i=0;i<m;i++)
for(j=0;j<10;j++);
}
void DisplayGraphic(unsigned char code *adder)
{
int i,j;
//*******显示上半屏内容设置
for(i=0;i<32;i++) //
{
TransferData((0x80 + i),0); //SET 垂直地址 VERTICAL ADD
TransferData(0x80,0); //SET 水平地址 HORIZONTAL ADD
for(j=0;j<16;j++)
{
TransferData(*adder,1);
adder++;
}
}
//*******显示下半屏内容设置
for(i=0;i<32;i++) //
{
TransferData((0x80 + i),0); //SET 垂直地址 VERTICAL ADD
TransferData(0x88,0); //SET 水平地址 HORIZONTAL ADD
for(j=0;j<16;j++)
{
TransferData(*adder,1);
adder++;
}
}
}
unsigned char code pic2[]=
{
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x1F,0xFF,0x81,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x1F,0xFF,0x81,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x18,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x08,0x00,0x00,0x00,0x03,
0xC0,0x1F,0xFF,0x80,0x00,0x00,0x04,0x07,0x81,0xE0,0x10,0x10,0x03,0xC0,0x30,0x03,
0xC0,0x1F,0xFF,0x80,0x00,0x00,0x0C,0x0C,0xC3,0x30,0x08,0x20,0x0C,0xE0,0x70,0x03,
0xC0,0x18,0x01,0x87,0xFF,0xFE,0x3C,0x18,0x66,0x18,0x04,0x40,0x0C,0x60,0x70,0x03,
0xC0,0x1F,0xFF,0x87,0xFF,0xFE,0x0C,0x18,0x66,0x18,0x02,0x80,0x18,0x00,0xB0,0x03,
0xC0,0x1F,0xFF,0x80,0x06,0x00,0x0C,0x18,0x66,0x18,0x01,0x00,0x1B,0x81,0x30,0x03,
0xC0,0x01,0x98,0x00,0x06,0x00,0x0C,0x00,0xE3,0x30,0x02,0x80,0x1C,0xC1,0x30,0x03,
0xC0,0x19,0x99,0x80,0x66,0x60,0x0C,0x00,0xC1,0xE0,0x04,0x40,0x18,0x62,0x30,0x03,
0xC0,0x19,0x99,0x80,0x66,0x30,0x0C,0x01,0x83,0x30,0x08,0x20,0x18,0x66,0x30,0x03,
0xC0,0x0D,0x9B,0x00,0xC6,0x38,0x0C,0x03,0x06,0x18,0x10,0x10,0x18,0x67,0xFC,0x03,
0xC0,0x0D,0x9B,0x01,0xC6,0x1C,0x0C,0x06,0x06,0x18,0x20,0x08,0x18,0x60,0x30,0x03,
0xC0,0x01,0x98,0x03,0x86,0x0C,0x0C,0x0C,0x06,0x18,0x00,0x00,0x08,0x60,0x30,0x03,
0xC0,0x7F,0xFF,0xE3,0x06,0x00,0x0C,0x18,0x03,0x30,0x00,0x00,0x0C,0xC0,0x30,0x03,
0xC0,0x7F,0xFF,0xE0,0x1E,0x00,0x0C,0x1F,0xE1,0xE0,0x00,0x00,0x07,0x80,0x30,0x03,
0xC0,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0
- 1
- 2
前往页