#include
#define Disp_On 0x3f //开显示
#define Disp_Off 0x3e //关显示
#define Col_Add 0x40 //
#define Page_Add 0xb8 //页起始地址
#define Start_Line 0xc0 //行起始地址
#define Lcd_Bus P0 // MCU P0<------> LCM
***it Di =P1^0; //Data or Instrument Select RS
***it RW =P1^1; //Write or Read R/W
***it Enable =P1^2; //6800 mode Enable single E
***it Mcs =P1^3; //Master chip enable CS1
***it Scs =P1^4; //Slave chip enable CS2
unsigned char i;
char code wang[]=
{
0x00,0x02,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0xC3,0x82,0x00,
0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x30,0x20,0x00
};
char code jun[]=
{
0x00,0x18,0x26,0x22,0xA2,0x72,0x2E,0xAA,0x22,0x22,0x22,0x32,0x22,0x0A,0x06,0x00,0x00,0x10,
0x10,0x12,0x13,0x12,0x12,0xFF,0x12,0x12,0x12,0x13,0x12,0x18,0x10,0x00
};
char code hua[]=
{
0x20,0x10,0x08,0xFC,0x03,0x02,0x10,0x10,0x7F,0x88,0x88,0x84,0x86,0xE4,0x00,0x00,0x00,0x04,0x04,
0x05,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00
};
void delay(unsigned int t) //延时子程序
{
unsigned int i,j;
for(i=0;i
for(j=0;j<10;j++);
}
void write_com(unsigned char cmdcode) //写指令
{
Di=0;
RW=0;
Lcd_Bus=cmdcode;
delay(5);
Enable=1;
delay(5);
Enable=0;
}
void write_data(unsigned char Dispdata) //写数据
{
Di=1;
RW=0;
Lcd_Bus=Dispdata;
delay(5);
Enable=1;
delay(5);
Enable=0;
}
void init_lcd() //显示初始化
{
Mcs=1;
Scs=1;
delay(100);
write_com(Disp_Off);
write_com(Page_Add+0);
write_com(Start_Line+0);
write_com(Col_Add+0);
write_com(Disp_On);
}
void Clr_Scr()
{
unsigned char j,k;
Mcs=1;Scs=1;
write_com(Page_Add+0);
write_com(Col_Add+0);
for(k=0;k<8;k++)
{
write_com(Page_Add+k);
for(j=0;j<64;j++)
write_data(0x00);
}
}
void main()
{
init_lcd();
write_com(0x01);
Clr_Scr();
write_com( 0xb8);
write_com( 0x40);
for(i=0;i<16;i++)
write_data(wang);
write_com( 0xb8+1);
write_com( 0x40);
for(i=16;i<32;i++)
write_data(wang);
write_com( 0xb8);
write_com( 0x40+16);
for(i=0;i<16;i++)
write_data(jun);
write_com( 0xb8+1);
write_com( 0x40+16);
for(i=16;i<32;i++)
write_data(jun);
write_com( 0xb8);
write_com( 0x40+32);
for(i=0;i<16;i++)
write_data(hua);
write_com( 0xb8+1);
write_com( 0x40+32);
for(i=16;i<32;i++)
write_data(hua);
while(1);
}
更多回帖