上面各位遇到的问题我解决了,没有用忙判断。楼主有两个错误,一是写命令和写数据时序有问题,二是中文写入地址有问题,所以楼主的“日”字显示不出来,“年”地址是0x40,“月”地址是0x48,“日”地址应该是0x50,而不是0x56,因为是十六进制。代码如下:
/*************************************************************************
3ìDò1|Äü£oÔúLCDéÏÏÔê¾2013Äê08ÔÂ21èÕ
I Love Mcu
Author
x x x
******************í·ÎļtéùÃ÷**********************************************/
#include <reg51.h>
#include <intrins.h>
/*********************************¶Ë¿ú¶¨òå**********************************/
sbit rs= P3^5;
sbit rw = P3^6;
sbit en = P3^4;
sbit busy=P1^7;
/********************************ÏÔê¾êy¾Y±í*********************************/
unsigned char day[]={0x1f,0x11,0x11,0x1f,0x11,0x11,0x1f,0x00}; //èÕμÄ×Ö·û±í
unsigned char month[]={0x1f,0x11,0x1d,0x11,0x1d,0x11,0x11,0x00}; //ÔÂμÄ×Ö·û±í
unsigned char year[] ={0x40,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02}; //ÄêμÄ×Ö·û±í
unsigned char one[]={0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x00};//ò»
unsigned char two[]={0x00,0x00,0x0E,0x00,0x1F,0x00,0x00,0x00};//¶t
unsigned char three[]={0x00,0x1F,0x00,0x0E,0x00,0x1F,0x00,0x00};//èy
unsigned char time[] ={"20130821"};
unsigned char code1[]={"I Love Mcu"};
unsigned char author[]={"Author"};
unsigned char name[]={"X X X"};
/*****************************************************************************
oˉêy1|Äü:LCDÑóê±×ó3ìDò
*****************************************************************************/
void Delay(unsigned char x)
{
int i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
/*****************************************************************************
oˉêy1|Äü£o2aêÔLCD×′ì¬êÇ·ñÃ|Âμ
¼ì2aÔ-òò£oμ¥Ƭ»ú′|àíËù¶è½Ï¿ì£¬¶øLCDμÄ′|àíËù¶è½ÏÂy
*****************************************************************************/
//bit lcd_check_busy()
//{
// P1=0Xff;
// rs = 0;//Ö»òaéèÖÃáËrs=0,rw=1,¾íêÇòa¶áBFλ
// rw = 1;
// en = 0;
// _nop_(); //ÕaèyDDμÄ×÷óÃêǽøDDò»¸ö¿Õ2ù×÷£¬¶áBFêyÖ죬è»oóê1Äüêä3öBFÖμ
// en=1;
// return busy; //èç1ûLCDÃ|£¬¾í·μ»ØÃ|(BF=1)
//}
/*****************************************************************************
oˉêy1|Äü:D′Ö¸áîμ½LCD×ó3ìDò
*****************************************************************************/
void lcd_wcmd(unsigned char cmd)
{
// while(lcd_check_busy()); //ÅD¶ÏLCDêÇ·ñÃ|Â죬Ã|2ÅD′¡£ÎòÔø¾-¸Ä3飡lcd_check_busy()£¬ÎT·¨Õy3£ÏÔê¾
rs = 0; //D′Ö¸áî(Ö»òars = 0,rw = 0¾íêÇD′Ö¸áî)
rw = 0;
en = 1;
P1 = cmd;
_nop_();
Delay(5);
en = 0;
}
/*****************************************************************************
oˉêy1|Äü:D′êy¾Yμ½LCD×ó3ìDò
*****************************************************************************/
void lcd_wdat(unsigned char dat)
{
// while(lcd_check_busy()); //ÅD¶ÏLCDêÇ·ñÃ|Â죬Ã|2ÅD′
rs = 1; //D′êy¾Y(Ö»òars = 1,rw = 0¾íêÇD′Ö¸áî)
rw = 0;
en = 1;
P1 = dat;//Ïèê1Äü£¬2ÅÄü¶ádatêy¾Y
_nop_();
Delay(5);
en = 0;
}
/*****************************************************************************
oˉêy1|Äü:é趨ÏÔê¾Î»ÖÃ×ó3ìDò
*****************************************************************************/
void lcd_pos(unsigned char pos)
{
lcd_wcmd(pos | 0x80);//DDRAMμØÖ·éèÖã¬0x80=1000 0000£¬N = 1,·Öá½DDÏÔê¾£¬
Delay(50);
} //ê×DDA6-A0=00H-2FH|posÖ죬′ÎDDA6-A0 = 40H-67H|posÖμ
/*****************************************************************************
oˉêy1|Äü:LCD3õê¼»ˉ×ó3ìDò£¨óD¸öòéÎ꣬3õê¼»ˉ3ìDò£¬Îaê2Ã′ÏÔ꾿a1Ø2»Ö±½óéèÎa0x0c£¿
êÇ2»êÇòòÎaòaÏèè«2¿1رÕ£¬2ÅÄüÇåÆ᣿£©
*****************************************************************************/
void lcd_init() // òÔÏÂÖ¸áîÃûlcd_wcmdÖ»êÇóD¸öÃû×Ö¶øòÑ£¬0x38μè2ÅêÇ1ؼü
{
lcd_wcmd(0x38); //1|ÄüéèÖão8λêy¾Y£¬Ë«DDÏÔê¾£¬5*7μãÕó
lcd_wcmd(0x08); //ÏÔ꾿a1ØéèÖãoÏÔê¾1رÕ£¬ÎT1a±ê£¬2»éá˸--Ïè1رÕ
lcd_wcmd(0x01); //ÇåÆá
lcd_wcmd(0x06); //êäèë·½ê½éèÖão1a±ê×Ô¶ˉÔöò»
Delay(100);
lcd_wcmd(0x0c); //ÏÔ꾿a1ØéèÖãoÏÔ꾿aÆô£¬ÎT1a±ê£¬2»éá˸--Ôù¿aÆô
}
/****************************************************************************
oˉêy1|Äü£o½¨á¢ÄêÔÂèÕ×Ö·û
*****************************************************************************/
void lcd_setup() //Ï轨á¢ÄêÔÂèÕ×Ö·û
{
unsigned int i;
lcd_wcmd(0x40); //1|ÄüéèÖÃP0=0x40=0010 0000£¬4룬ò»DDÏÔê¾£¬5*7μãÕóÏÔê¾
for(i=0;i<8;i++)
{
lcd_wdat(year[i]);
Delay(50);
}
lcd_wcmd(0x48);
for(i=0;i<8;i++)
{
lcd_wdat(month[i]);
Delay(50);
}
lcd_wcmd(0x50);
for(i=0;i<8;i++)
{
lcd_wdat(day[i]);
Delay(50);
}
lcd_wcmd(0x58);
for(i=0;i<8;i++)
{
lcd_wdat(one[i]);
Delay(50);
}
lcd_wcmd(0x60);
for(i=0;i<8;i++)
{
lcd_wdat(two[i]);
Delay(50);
}
lcd_wcmd(0x68);
for(i=0;i<8;i++)
{
lcd_wdat(day[i]);
Delay(50);
}
}
/*****************************************************************************
oˉêy1|Äü:Ö÷3ìDò
*****************************************************************************/
void main(void)
{
unsigned char i;
lcd_init(); //3õê¼»ˉLCD
lcd_setup(); //½¨á¢×Ö·û
while(1)
{
lcd_pos(0x00);
for(i=0;i<4;i++)
{
lcd_wdat(time[i]); //ÏÔê¾2013
}
lcd_pos(0x04); //éèÖÃÆeê¼μØÖ·êÇ0x05£¬0x05|0x80=0x85
lcd_wdat(0x00); //D′Ö¸áP0=0x00
lcd_pos(0x06); //éèÖÃÆeê¼μØÖ·êÇ0x07£¬0x05|0x80=0x87
for(i=4;i<6;i++)
{
lcd_wdat(time[i]); //ÏÔê¾08
}
lcd_pos(0x09); //éèÖÃÆeê¼μØÖ·êÇ0x0a£¬0x0a|0x80=0x8a
lcd_wdat(0x01); //D′êy¾Y£¬P0=0x01
lcd_pos(0x0b); //éèÖÃÆeê¼μØÖ·êÇ0x0c£¬0x0c|0x80=0x8c
for(i=6;i<8;i++)
{
lcd_wdat(time[i]); //ÏÔê¾21
}
lcd_pos(0x0e); //éèÖÃÆeê¼μØÖ·êÇ0x0f£¬0x0f|0x80=0x8f
lcd_wdat(0x02); //D′êy¾Y£¬P0=0x02
lcd_pos(0x43); //éèÖÃÆeê¼μØÖ·êÇ0x43£¬0x43|0x80=0xc3
for(i=0;i<10;i++)
{
lcd_wdat(code1[i]); //ÏÔê¾I Love Mcu
}
//
// for(i=0;i<17;i++)
// {
// lcd_wcmd(0x18); //0001 1000ÏÔê¾×Ö·ûƽòÆò»¸ö×Ö·ûλ(0001)£¬
// Delay(50); //ÏÔê¾×Ö·ûÕûìå×óòÆ1λ(1000)
// }
// lcd_wcmd(0x01); //ÇåÆá
// Delay(50);
//
// lcd_pos(0x05);
// Delay(50);
// for(i=0;i<6;i++)
// {
// lcd_wdat(author[i]);
// Delay(50);
// }
// lcd_pos(0x41);
// Delay(50);
// for(i=0;i<13;i++)
// {
// lcd_wdat(name[i]);
// Delay(50);
// }
// Delay(10);
// lcd_wcmd(0x01);
}
} |