#include <reg52.h>
#include "delay.h"
sbit RS = P2^4;//Êý¾Ý/Ö¸Áî
sbit RW = P2^5;//¶Á/д
sbit E = P2^6;//ʹÄÜ
#define DATAPORT P0
#define KEYPORT P3
void lcd_write(unsigned char com,unsigned char dat)
{
if(1 == com)//ÃüÁî
{
RS = 0;
}
else if(0 == com)//Êý¾Ý
{
RS = 1;
}
RW = 0;//дÈë
DATAPORT = dat;
E = 1;//ʹÄÜ
delay_us(10);
E = 0;//ʧÄÜ
}
void lcd_init()
{
delay_ms(15);
lcd_write(1,0x38);//8λÊý¾Ý½Ó¿Ú£¬Á½ÐÐÏÔʾ£¬5*8µãÕó×Ö·û
delay_ms(5);
lcd_write(1,0x38);
delay_ms(5);
lcd_write(1,0x38);
delay_ms(5);
lcd_write(1,0x08);//ÏÔʾ¹Ø£¬¹â±ê¹Ø£¬ÉÁ˸¹Ø
delay_ms(5);
lcd_write(1,0x01);//ÏÔʾÇåÆÁ
delay_ms(5);
lcd_write(1,0x06);//¹â±ê×Ô¶¯¼Ó1£¬»Ãæ²»¶¯
delay_ms(5);
lcd_write(1,0x0c);//ÏÔʾ¿ª£¬¹â±ê¹Ø£¬ÉÁ˸¹Ø
delay_ms(5);
}
void display_lcd_char(unsigned char x,unsigned char y,unsigned char ch)
{
if(y>1 ||y<0 || x>39)
return ;
if(0 == y)
{
lcd_write(1,0x80+x);
}
else if(1 == y)
{
lcd_write(1,0xc0+x);
}
lcd_write(0,ch);
}
unsigned char key_scan()
{
unsigned char keyvalue;
KEYPORT = 0xf0;
if(KEYPORT !=0xf0)
{
delay_ms(10);
if(KEYPORT !=0xf0)
{
KEYPORT = 0xfe;
if(KEYPORT != 0xfe)
{
#include "delay.h"
sbit RS = P2^4;//Êý¾Ý/Ö¸Áî
sbit RW = P2^5;//¶Á/д
sbit E = P2^6;//ʹÄÜ
#define DATAPORT P0
#define KEYPORT P3
void lcd_write(unsigned char com,unsigned char dat)
{
if(1 == com)//ÃüÁî
{
RS = 0;
}
else if(0 == com)//Êý¾Ý
{
RS = 1;
}
RW = 0;//дÈë
DATAPORT = dat;
E = 1;//ʹÄÜ
delay_us(10);
E = 0;//ʧÄÜ
}
void lcd_init()
{
delay_ms(15);
lcd_write(1,0x38);//8λÊý¾Ý½Ó¿Ú£¬Á½ÐÐÏÔʾ£¬5*8µãÕó×Ö·û
delay_ms(5);
lcd_write(1,0x38);
delay_ms(5);
lcd_write(1,0x38);
delay_ms(5);
lcd_write(1,0x08);//ÏÔʾ¹Ø£¬¹â±ê¹Ø£¬ÉÁ˸¹Ø
delay_ms(5);
lcd_write(1,0x01);//ÏÔʾÇåÆÁ
delay_ms(5);
lcd_write(1,0x06);//¹â±ê×Ô¶¯¼Ó1£¬»Ãæ²»¶¯
delay_ms(5);
lcd_write(1,0x0c);//ÏÔʾ¿ª£¬¹â±ê¹Ø£¬ÉÁ˸¹Ø
delay_ms(5);
}
void display_lcd_char(unsigned char x,unsigned char y,unsigned char ch)
{
if(y>1 ||y<0 || x>39)
return ;
if(0 == y)
{
lcd_write(1,0x80+x);
}
else if(1 == y)
{
lcd_write(1,0xc0+x);
}
lcd_write(0,ch);
}
unsigned char key_scan()
{
unsigned char keyvalue;
KEYPORT = 0xf0;
if(KEYPORT !=0xf0)
{
delay_ms(10);
if(KEYPORT !=0xf0)
{
KEYPORT = 0xfe;
if(KEYPORT != 0xfe)
{