?? lcd.c
字號:
#include <REG52.H>
#ifndef uchar
#define uint unsigned int
#define uchar unsigned char
#endif
#define LCD_DATA P0
sbit RS=P2^7;
sbit RW=P2^6;
sbit EN=P2^5;
sbit RST=P2^4;
void delay_us(unsigned char us);
void delay_ms(unsigned int ms);
void LCD_Busy_Check() //等待LCD空閑
{
LCD_DATA &=~0x80;
EN=0;
RS=0;
RW=1; //RW=1
EN=1;
while (!(LCD_DATA&0x80)==0);
EN=0;
LCD_DATA |= 0xff;
}
void LCD_write(uchar wdat,uchar mode)
{
LCD_Busy_Check();
LCD_DATA |= 0xff;
EN=0; //EN=0
RS=mode; //RS=1
RW=0; //RW=0
EN=1;
LCD_DATA &= wdat; //send 8bit
EN=0;
RW=1;
RS=1;
}
void LCD_set_position( uchar x, uchar y )
{
uchar address;
switch(y)
{
case 0:
address = 0x80 + x;
break;
case 1:
address = 0x90 + x;
break;
case 2:
address = 0x88 + x;
break;
case 3:
address = 0x98 + x;
break;
default:address = 0x80 + x;
}
LCD_write( address, 0 );
}
void LCD_write_string(uchar X,uchar Y,uchar *s)
{
LCD_set_position( X, Y );
while (*s)
{
LCD_write(*s,1);
s++;
}
}
void LCD_set_pic_position(unsigned char x,unsigned char y)
{
if(y>31)
{
x+=0x88;
y=(y-32)+0x80;
}
else
{
x+=0x80;
y+=0x80;
}
LCD_write(0x34,0);
LCD_write(y,0);
LCD_write(x,0);
LCD_write(0x30,0);
}
void LCD_Convert(unsigned char x,unsigned char y,unsigned char weith,unsigned char mode) //反白
{
unsigned char flag=0;
unsigned char px=0;
unsigned char py=0;
if (mode) mode=0xff;
if(x%2)
{
flag=1;
}
x/=2;
for(py=0;py<16;py++)
{
LCD_set_pic_position(x,y*16+py);
if(flag) LCD_write(0,1);
for (px=weith;px>0;px--)
{
LCD_write (mode,1);
}
}
LCD_write(0x36,0);
LCD_write(0x30,0);
}
void LCD_clr_pic()
{
unsigned char i;
for(i=0;i<4;i++) LCD_Convert(0,i,16,0);
}
void LCD_init(void)
{
RST=0;
delay_us(50);
RST=1;
delay_us(50);
LCD_write(0x01,0); //顯示清屏
delay_ms(30);
LCD_write(0x0c,0); //顯示開,不顯示光標
delay_ms(30);
LCD_write(0x80,0); //顯示光標移動設置
delay_ms(30);
LCD_clr_pic();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -