?? init_lcd.c
字號:
/*=========================================================================================
INITLCD RUTINE
===========================================================================================
AHTH: GDY
DATE:
COMMENT:
===========================================================================================*/
/*--------------------------------------INCLUDE--------------------------------------------*/
#include <c8051f020.h>
/*---------------------------------------FUCTION DECLARING---------------------------------*/
extern void set_xy(unsigned char x,unsigned char y);
extern void delay(int t);
unsigned char read_status();
unsigned char wcode(unsigned char c);
unsigned char wdata(unsigned char d);
/*---------------------------------------16BIT SFR DEFINE----------------------------------*/
sbit DINLCD=P1^0;
sbit RWLCD=P3^7;
sbit ESIG=P1^1;
/*---------------------------------------GLOBLE DEFINE OR DECLARING------------------------*/
extern unsigned char code zk[];
unsigned char read_status()
{
unsigned char status;
RWLCD=1;
// CSLCD=0;
DINLCD=0;
ESIG=1;
status=0;
ESIG=0;
return(status);
}
void init_lcd()
{
unsigned char status;
status=read_status()&0x80;
while(status)
status=read_status()&0x80;
wcode(0x3f);
status=read_status()&0x80;
while(status)
status=read_status()&0x80;
wcode(0xc0);
status=read_status()&0x80;
while(status)
status=read_status()&0x80;
wcode(0xb8);
status=read_status()&0x80;
while(status)
status=read_status()&0x80;
wcode(0x40);
}
/****************************************
THE BLOCK IS FOR WRITTING CODE
WR=0
DI=0
and when the e's fall ,the code would be latched.
****************************************/
unsigned char wcode(unsigned char c)
{
RWLCD=0;
delay(10);
// CSLCD=0;
DINLCD=0;
delay(10);
ESIG=1;
delay(10);
P2=c;
delay(10);
ESIG=0;
delay(10);
return(c);
}
/****************************************
THE BLOCK IS FOR WRITTING DATA
DI=1
RW=0
when e's falling ,the data would be latched
****************************************/
unsigned char wdata(unsigned char d)
{
DINLCD=1;
delay(10);
// CSLCD=0;
RWLCD=0;
delay(10);
ESIG=1;
delay(10);
// delay(5);
P2=d;
delay(100);
ESIG=0;
delay(10);
return(d);
delay(10);
}
/****************************************
THE BLOCK IS FOR CLEARING
****************************************/
void clear()
{
int i=0,x=0;
for(x=0;x<8;x++)
{
set_xy(x,0);
for(i=0;i<64;i++)
wdata(0x00);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -