哪位大神帮我看看为什么 LCD的第二行的“T”为什么显示不出来?下面是我的代码
- #include <reg52.h>
- #include <string.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit SDA=P1^0; // DS1302数据线
- sbit CLK=P1^1; //DS1302时钟线
- sbit RST=P1^2; //DS1302复位线
- sbit RS=P2^0;
- sbit RW=P2^1;
- sbit EN=P2^2;
- uchar *WEEK[]={"SUN","TUS","MON","WEN","THU","FRI","SAT"};
- uchar LCD_DSY_BUFFER1[]={"Date 00-00-01 "}; //LCD显示缓冲
- uchar LCD_DSY_BUFFER2[]={"Time 00:00:00 "};
- uchar DateTime[7]; //所读取的日期时间
- void DelayMS(uint x)
- {
- uchar i;
- while(x--) for(i=0;i<120;i++);
- }
- void DS1302_Write_Byte(uchar x)
- {
- uchar i;
-
- for(i=0;i<8;i++)
- {
- SDA=x&1;
- CLK=1;
- CLK=0;
- x>>=1;
- }
- }
- uchar DS1302_Read_Byte()
- {
- uchar i,b,t;
- for(i=0;i<8;i++)
- {
- b>>=1;
- t=SDA;
- b|=t<<7;
- CLK=1;
- CLK=0;
- }
- return b/16*10+b%16;
- }
- uchar Read_Data(uchar addr)
- {
- uchar dat;
- RST=0;
- CLK=0;
- RST=1;
- DS1302_Write_Byte(addr);
- dat=DS1302_Read_Byte();
- CLK=1;
- RST=0;
- return dat;
- }
- void GetTime()
- {
- uchar i;
- for(i=0;i<7;i++)
- {
- DateTime[i]=Read_Data(0x81+2*i);
- }
- }
- uchar Read_LCD_State()
- {
- uchar state;
- RS=0;
- RW=1;
- EN=1;
- DelayMS(1);
- state=P0;
- EN=0;
- DelayMS(1);
- return state;
- }
- void LCD_Busy_Wait()
- {
- while((Read_LCD_State()&0x08)==0x80);
- DelayMS(5);
- }
- void Write_LCD_Data(uchar dat) //写数据
- {
- LCD_Busy_Wait();
- RS=1;
- RW=0;
- EN=0;
- P0=dat;
- EN=1;
- DelayMS(1);
- EN=0;
- }
- void Write_LCD_Command(uchar cmd)//写命令
- {
- LCD_Busy_Wait();
- RS=0;
- RW=0;
- EN=0;
- P0=cmd;
- EN=1;
- DelayMS(1);
- EN=0;
- }
- void Init_LCD() //LCD初始化
- {
- Write_LCD_Command(0x38); DelayMS(1);
- Write_LCD_Command(0x01); DelayMS(1);
- Write_LCD_Command(0x06); DelayMS(1);
- Write_LCD_Command(0x0C); DelayMS(1);
- }
- void Set_LCD_POS(uchar p)
- {
- Write_LCD_Command(p+0x80);
- }
- void Display_LCD_String(uchar p,uchar *s)
- {
- uchar i;
- Set_LCD_POS(p);
- for(i=0;i<16;i++)
- {
- Write_LCD_Data(s[i]);
- DelayMS(1);
- }
- }
- void Format_DateTime(uchar d,uchar *a)
- {
- a[0]=d/10+'0';a[1]=d%10+'0';
- }
- void main()
- {
- Init_LCD();
- while(1)
- {
- GetTime();
- Format_DateTime(DateTime[6],LCD_DSY_BUFFER1+5); //年
- Format_DateTime(DateTime[4],LCD_DSY_BUFFER1+8); //月
- Format_DateTime(DateTime[3],LCD_DSY_BUFFER1+11); //日
- strcpy(LCD_DSY_BUFFER1+13,WEEK[DateTime[5]]); //week
- Format_DateTime(DateTime[2],LCD_DSY_BUFFER2+5); //hour
- Format_DateTime(DateTime[1],LCD_DSY_BUFFER2+8);
- Format_DateTime(DateTime[0],LCD_DSY_BUFFER2+11);
- Display_LCD_String(0x00,LCD_DSY_BUFFER1);
- Display_LCD_String(0x40,LCD_DSY_BUFFER2);
- }
- }
复制代码
|