//lcd init code
void lcd_init(void)
{
CSA=0;CSB=0;//left block
write_com(0xc0);
write_com(0x3f);
NOP();
CSA=1;CSB=0;//right block
write_com(0xc0);
write_com(0x3f);
NOP();
CSA=0;CSB=1;//medium block
write_com(0xc0);
write_com(0x3f);
}
1.原理图
2.LCD驱动代码
//lcd IO 宏定义
//LCD I/O
#define LCD_LIGHT (_RD13)
#define RSTB PORTBbits.RB13
#define DI PORTAbits.RA14
#define RW PORTAbits.RA7
#define E PORTAbits.RA6
#define DBUS PORTD
#define CSA (_RF7)
#define CSB (_RD9)
//LCD 基本操作代码
//-------------LCD 复位-------------------------
void lcd_reset(void)
{
RSTB=0;
NOP();NOP();NOP();
RSTB=1;
}
//------------------------------------------
//write command,read busy signal
//------------------------------------------
//bit key;
void busy_check(void)
{
unsigned char temp;
TRISD=0x1ff;
while(1)
{
RW=1;//read
DI=0;
E=1;//clock out the Busy Data from LCD
NOP();
temp=DBUS;
NOP();
E=0;//End this Bus Term,prepare Next Bus Data
if((temp&0x80)==0x00)break;
}
TRISD=0x100;
}
//*******************************************
//write command
//******************************************
void write_com(unsigned char com)
{
unsigned int temp;
/*
temp=com;
if(LCD_LIGHT==1)
{temp=temp|(int)(1<<13);}
if(CSB==1)
{temp=temp|(int)(1<<9);}
*/
temp=PORTD;//read PORTD 16 bits
temp=temp&0xff00;
temp=temp|com;
busy_check();//if busy ,always wait
TRISD=0x100;
RW=0;//write
DI=0;//command
/*
if(CSB==1)
{DBUS=com|((int)1<<9);}
else
{DBUS=com;}*/
DBUS=temp;
E=1;//clock in prepare
NOP();
E=0;//clock in valid data
}
//----------------------------------------------
//write data
//----------------------------------------------
void write_data(unsigned char dat)
{
//TRISD=0x00;
unsigned int temp;
/*
temp=dat;
if(LCD_LIGHT==1)
{temp=temp|(int)(1<<13);}
if(CSB==1)
{temp=temp|(int)(1<<9);}
*/
temp=PORTD;//read PORTD 16 bits
temp=temp&0xff00;
temp=temp|dat;
busy_check();
TRISD=0x100;
RW=0;//write
DI=1;//data
NOP();
/*
if(CSB==1)
{DBUS=dat|((int)1<<9);}
else
{DBUS=dat;}
*/
DBUS=temp;
E=1;//clock in prepare
NOP();
E=0;//clock in valid data
NOP();
}
void ioInterfaceInit(void)
{
//disable analog pin
/*
ADCON1=0x06;
//init the i/o direction
TRISA1=0;//reset pin
TRISA3=0;//data or command pin
TRISB5=0;//light pin
TRISE1=0;//rw pin
TRISA2=0;//e pin
TRISA4=0;//CSB pin
TRISA5=0;//CSA pin
*/
/************LCD I/O init******************/
_TRISB13=0;
_TRISA14=0;
_TRISA7=0;
_TRISA6=0;
_TRISF7=0;
_TRISD9=0;
/**********74HC595 I/O init****************/
_TRISG13=0;
_TRISG12=0;
_TRISG1=0;
_TRISG0=0;
/***********key i/o init********************/
_TRISG15=1;
_TRISC3=1;
_TRISC2=1;
_TRISC1=1;
}
void lcd_init(void)
{
CSA=0;CSB=0;//left block
write_com(0xc0);
write_com(0x3f);
NOP();
CSA=1;CSB=0;//right block
write_com(0xc0);
write_com(0x3f);
NOP();
CSA=0;CSB=1;//medium block
write_com(0xc0);
write_com(0x3f);
}
//
const uchar hz_dong[]={\
0x08,0x08,0x08,0x88,0x68,0x18,0x0F,0xE8,\
0x08,0x08,0x08,0x88,0x08,0x0C,0x08,0x00,\
0x00,0x40,0x21,0x11,0x0D,0x41,0x81,0x7F,\
0x01,0x05,0x09,0x31,0x61,0x00,0x00,0x00 \
};
//
const uchar hz_sheng[]={\
0x00,0x00,0xFC,0x24,0x24,0x24,0xE4,0x04,\
0x3F,0xC4,0x05,0xC6,0x34,0x04,0x00,0x00,\
0x44,0x43,0x40,0x78,0x49,0x4A,0x79,0x48,\
0x7A,0x4A,0x49,0x7A,0x44,0x64,0x47,0x00};
//
const uchar hz_an[]={\
0x90,0x8C,0x84,0x84,0x84,0x84,0xF5,0x86,\
0x84,0x84,0x84,0x84,0x84,0xD4,0x8C,0x00,\
0x00,0x00,0x80,0x84,0x46,0x49,0x28,0x10,\
0x10,0x28,0x47,0xC0,0x00,0x00,0x00,0x00};
//
const uchar hz_xin[]={\
0x80,0x40,0x20,0xF8,0x07,0x24,0x24,0x24,\
0x25,0x26,0x24,0x24,0xB4,0x26,0x04,0x00,\
0x00,0x00,0x00,0xFF,0x00,0x01,0xFD,0x45,\
0x45,0x45,0x45,0x45,0xFD,0x01,0x00,0x00};
//科
const uchar hz_ke[]={\
0x24,0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,\
0x24,0x48,0x00,0xFF,0x00,0x80,0x00,0x00,\
0x10,0x08,0x06,0x01,0xFF,0x00,0x01,0x02,\
0x02,0x02,0x02,0xFF,0x01,0x01,0x01,0x00};
//技
const uchar hz_ji[]={\
0x10,0x10,0x10,0xFF,0x10,0x10,0x88,0x88,\
0x88,0xFF,0x88,0x88,0x8C,0x08,0x00,0x00,\
0x04,0x44,0x82,0x7F,0x01,0x80,0x81,0x46,\
0x28,0x10,0x28,0x26,0x41,0xC0,0x40,0x00};
//创
const uchar hz_chuang[]={\
0x80,0x40,0xF0,0x4C,0x43,0x44,0xC8,0x10,\
0x30,0x00,0xF8,0x00,0x00,0xFF,0x00,0x00,\
0x00,0x00,0x3F,0x40,0x42,0x44,0x43,0x70,\
0x00,0x00,0x07,0x40,0x80,0x7F,0x00,0x00};
//造
const uchar hz_zhao[]={\
0x40,0x42,0x44,0xCC,0x00,0x50,0x4E,0x48,\
0x48,0x7F,0x48,0x4C,0xC8,0x60,0x40,0x00,\
0x00,0x40,0x20,0x1F,0x20,0x40,0x5F,0x51,\
0x51,0x51,0x51,0x51,0x5F,0x61,0x20,0x00};
//未
const uchar hz_wei[]={\
0x80,0x88,0x88,0x88,0x88,0x88,0x88,0xFF,\
0x88,0x88,0x88,0x88,0x8C,0xC8,0x80,0x00,\
0x00,0x20,0x10,0x08,0x04,0x02,0x01,0xFF,\
0x01,0x02,0x04,0x08,0x10,0x30,0x10,0x00};
//来
const uchar hz_lai[]={\
0x00,0x08,0x28,0x48,0xC8,0x08,0x08,0xFF,\
0x08,0x88,0x48,0x68,0x0C,0x88,0x00,0x00,\
0x21,0x21,0x11,0x11,0x09,0x05,0x03,0xFF,\
0x03,0x05,0x09,0x19,0x11,0x31,0x11,0x00 \
};
//!
void hz_disp_at(uchar x,uchar y,const uchar *p)
{
//logic pos.-> phy.pos.
uchar i;
uchar phy_y;
if(y<4){select_left_block();phy_y=y;}
if((y>=4)&&(y<8)){select_medium_block();phy_y=y-4;}
if(y>=8){select_right_block();phy_y=y-8;}
write_com(0xb8+x);
write_com(0x40+phy_y*16);
for(i=0;i<16;i++)
{write_data(*p);p++;}
write_com(0xb8+x+1);
write_com(0x40+phy_y*16);
for(i=0;i<16;i++)
{write_data(*p);p++;}
}
void face_disp(void)//开机画面显示
{
hz_disp_at(1,4,hz_dong);
hz_disp_at(1,5,hz_sheng);
hz_disp_at(1,6,hz_an);
hz_disp_at(1,7,hz_xin);
hz_disp_at(4,3,hz_ke);
hz_disp_at(4,4,hz_ji);
hz_disp_at(4,5,hz_chuang);
hz_disp_at(4,6,hz_zhao);
hz_disp_at(4,7,hz_wei);
hz_disp_at(4,8,hz_lai);
hz_disp_at(4,9,hz_th);
}