这两天又捣鼓了一下DS1307和诺基亚屏幕,几经研究发现以前的那个是错误的,确实是需要转换BCD格式,之前能够正确显示可能和设定的时间有关系,毕竟没有 尝试j爱你运行。
好了,先上图。
这个是整体实物,不会画连线图,我是MAC系统,不知道什么软件可以画图。
中文显示
英文显示
发现在中文模式下宽度不够啊,字体是12点阵的,如果有8点阵的话就可以和英文等高了,显示也会多一些。
代码如下
[pre lang="arduino" line="1" file="DS1307"]#include "Wire.h"
///////////////////// DS1307寄存器变量定义 /////
#define DS1307_STOP_START 0x00
#define DS1307_REG_SECOND 0x00
#define DS1307_REG_MINITUE 0x01
#define DS1307_REG_HOURS 0x02
#define DS1307_REG_WEEK 0x03
#define DS1307_REG_DATE 0x04
#define DS1307_REG_MONTH 0x05
#define DS1307_REG_YEAR 0x06
#define DS1307_REG_CTRL 0x07
#define DS1307_HOUR_12 0x40
#define DS1307_HOUR_24 0x00
#define DS1307_START 0x00
#define DS1307_STOP 0x80
//////////////////////////////////////////////
//////////// LCD 接口定义//////////////////////
#define PIN_SCE 10
#define PIN_RESET 11
#define PIN_DC 9
#define PIN_SDIN 8
#define PIN_SCLK 7
/////////////////////////////////////////////
///////////// LCD 状态控制 ///////////////////
#define LCD_C LOW
#define LCD_D HIGH
#define LCD_CMD 0
/////////////////////////////////////////////
//////////// LCD 屏幕大小 ////////////////////
#define LCD_X 84
#define LCD_Y 48
////////////////////////////////////////////
int scrollPosition = -10;
////////////////////////////////////////////
byte rtc[7];
byte year,month,date,hour,minitue,second,week;
byte year_H,year_L,month_H,month_L,date_H,date_L;
byte hour_H,hour_L,minitue_H,minitue_L,second_H,second_L;
/////////////////////////////////////////////
/////////////////英文 ASCII 字符定义///////////
static const byte ASCII[][5] =
{
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c &
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f →
};
////////////////////////////////////////////////
////////////////中文汉字定义 12*12点阵////////////
static const char charch[][24]=
{
//一
{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
//二
{0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00},
//三
{0x00,0x02,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x02,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00},
//四
{0x00,0xFE,0x02,0x82,0x7E,0x02,0x02,0x7E,0x82,0x82,0xFE,0x00,0x00,0x0F,0x05,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x0F,0x00},
//五
{0x02,0x22,0x22,0xE2,0x3E,0x22,0x22,0x22,0xE2,0x02,0x00,0x00,0x08,0x08,0x0E,0x09,0x08,0x08,0x08,0x08,0x0F,0x08,0x08,0x00},
//六
{0x10,0x10,0x10,0xD0,0x11,0x16,0x10,0x50,0x90,0x10,0x10,0x00,0x08,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x00},
//日
{0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x0F,0x00,0x00},
//年
{0x10,0x08,0xE7,0x24,0x24,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x0F,0x01,0x01,0x01,0x01,0x00},
//月
{0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x08,0x06,0x01,0x00,0x00,0x00,0x00,0x08,0x08,0x0F,0x00,0x00},
//时
{0xFE,0x22,0x22,0xFE,0x00,0x08,0x48,0x88,0x08,0xFF,0x08,0x00,0x07,0x02,0x02,0x07,0x00,0x00,0x00,0x09,0x08,0x0F,0x00,0x00},
//分
{0x20,0x10,0x2C,0x23,0xE0,0x20,0x20,0x23,0xEC,0x10,0x20,0x00,0x00,0x08,0x04,0x03,0x00,0x08,0x08,0x08,0x07,0x00,0x00,0x00},
//秒
{0x12,0xD2,0xFE,0x91,0x40,0x38,0x00,0xFF,0x00,0x04,0xB8,0x00,0x01,0x00,0x0F,0x00,0x08,0x08,0x04,0x04,0x02,0x01,0x00,0x00},
//星
{0x00,0xDF,0x95,0x95,0x95,0xF5,0x95,0x95,0x95,0x9F,0x00,0x00,0x09,0x08,0x0A,0x0A,0x0A,0x0F,0x0A,0x0A,0x0A,0x08,0x08,0x00},
//期
{0x04,0xFF,0x54,0x54,0xFF,0x04,0x00,0xFE,0x92,0x92,0xFE,0x00,0x09,0x05,0x01,0x01,0x05,0x09,0x08,0x07,0x00,0x08,0x0F,0x00},
};
/////////////////////////////////////////////////////////////////////
/////////////////////写寄存器/////////////////////////////////////////
void registerSet(int deviceAddress, int registerAddress, int registerValue)
{
Wire.beginTransmission(deviceAddress);
Wire.write(registerAddress);
Wire.write(registerValue);
Wire.endTransmission();
}
//////////////////// 读寄存器 ////////////////////////////////////////
void registerRead(int deviceAddress, int registerAddress)
{
int i;
Wire.beginTransmission(deviceAddress);
Wire.write(registerAddress);
Wire.endTransmission();
Wire.requestFrom(deviceAddress,7);
if(Wire.available() <= 7);;
{
for( i = 0 ; i < 7 ; i++)
rtc = Wire.read();
}
Wire.endTransmission();
}
///////////////// 时间获取 ///////////////////////////////////////////////
byte timeGet()
{
byte PM;
registerRead(DS1307_ADDRESS,DS1307_REG_SECOND);
year = 10 * ((rtc[6] & 0xF0 ) >> 4 ) + ( rtc[6] & 0x0F );
month = 10 * ((rtc[5] & 0x10 ) >> 4 ) + ( rtc[5] & 0x0F );
date = 10 * ((rtc[4] & 0x30 ) >> 4 ) + ( rtc[4] & 0x0F );
minitue = 10 * ((rtc[1] & 0x70 ) >> 4 ) + ( rtc[1] & 0x0F );
second = 10 * ((rtc[0] & 0x70 ) >> 4 ) + ( rtc[0] & 0x0F );
week = rtc[3] & 0x07;
///////////////// 12时制,hour 寄存器bit 6 为高位(1),bit 5 为AM/PM位,PM为高(1) ////////
if (bitRead(rtc[2],6))
{
hour = 10 * (( rtc[2] & 0x10 ) >> 4 ) + ( rtc[2] & 0x0F );
PM = bitRead(rtc[2],5);
return PM;
}
//////////////// 24时制,hour 寄存器bit 6 为低位(0),bit 5 为时间,20~23 时为高位(1)////
else
{
hour = 10 * (( rtc[2] & 0x30 ) >> 4 ) + ( rtc[2] & 0x0F );
PM = 3 ;
return PM;
}
}
//////////////////////获取时间,字符串形式////////////
byte timeGetcharacter()
{
byte PM;
registerRead(DS1307_ADDRESS,DS1307_REG_SECOND);
year_H = 0x30 + ((rtc[6] & 0xF0 ) >> 4 ) ;
year_L = 0x30 + (rtc[6] & 0x0F ) ;
month_H = 0x30 + ((rtc[5] & 0x10 ) >> 4 ) ;
month_L = 0x30 + (rtc[5] & 0x0F ) ;
date_H = 0x30 + ((rtc[4] & 0x30 ) >> 4 ) ;
date_L = 0x30 + (rtc[4] & 0x0F ) ;
minitue_H = 0x30 + ((rtc[1] & 0x70 ) >> 4 ) ;
minitue_L = 0x30 + (rtc[1] & 0x0F ) ;
second_H = 0x30 + ((rtc[0] & 0x70 ) >> 4 ) ;
second_L = 0x30 + (rtc[0] & 0x0F ) ;
week = rtc[3] & 0x07;
///////////////// 12时制,hour 寄存器bit 6 为高位(1),bit 5 为AM/PM位,PM为高(1) ////////
if (bitRead(rtc[2],6))
{
hour_H = 0x30 + ((rtc[2] & 0x10 ) >> 4 ) ;
hour_L = 0x30 + (rtc[2] & 0x0F ) ;
PM = bitRead(rtc[2],5);
return PM;
}
//////////////// 24时制,hour 寄存器bit 6 为低位(0),bit 5 为时间,20~23 时为高位(1)////
else
{
hour_H = 0x30 + ((rtc[2] & 0x30 ) >> 4 ) ;
hour_L = 0x30 + (rtc[2] & 0x0F ) ;
PM = 3 ;
return PM;
}
}
//////////////////// 时间设置,按照年月日,时分秒,星期,12/24时制 ,AM/PM 输入////////////////////
byte timeSet(byte yr,byte mh,byte da,byte hr,byte mt,byte se,byte we,boolean t24,boolean pm)
{
byte H24,startt;
//////////////确保时间日期输入不超范围////////////////////////////////////////////////////////
if ( yr < 0 || yr > 99 ) return 99;
if ( mh < 0 || mh > 12 ) return 12;
if ( da < 0 || da > 31 ) return 31;
if ( hr < 0 || hr > 23 ) return 24;
if ( mt < 0 || mt > 59 ) return 60;
if ( se < 0 || se > 59 ) return 60;
if ( we < 0 || we > 7 ) return 7;
///////////////////// 12/24时制,AM/PM 选择判断//////////////////////////////////////////////
if(hr >= 0 && hr <= 12) ////////////如果输入的小时大于0且小于12,需要判别是否为24时制
{
if (t24) //////////////如果为24时制,设置寄存器为24时模式
{
H24 = DS1307_HOUR_24;
}
else
{
H24 = DS1307_HOUR_12; //////////////如果为12时制,设置寄存器为12时模式
if (pm)
{
bitWrite( H24,5,1); //////////////如果PM为真,将12时寄存器bit 5 设置为1
}
else
{
bitWrite( H24,5,0); ///////////// 如果PM为假,将12时寄存器bit 5 设置为0
}
}
}
else if ( hr > 12 && hr < 24 ) //////////////如果输入的时间大于12且小于24,确定为24时制
{
H24 = DS1307_HOUR_24;
}
///////////////////// 时间转化为BCD格式 (寄存器格式)////////////////
yr = (( yr / 10 ) << 4 ) + ( yr % 10 );
mh = (( mh / 10 ) << 4 ) + ( mh % 10 );
da = (( da / 10 ) << 4 ) + ( da % 10 );
hr = (( hr / 10 ) << 4 ) + ( hr % 10 );
hr = hr | H24 ;
mt = (( mt / 10 ) << 4 ) + ( mt % 10 );
se = (( se / 10 ) << 4 ) + ( se % 10 );
we = we ;
///////////////////////////////////////////////////////////////
////////////////////写寄存器数据,设置时间初始值/////////////////////////////////
registerSet(DS1307_ADDRESS,DS1307_STOP_START,DS1307_STOP); //时钟计数器停止
registerSet(DS1307_ADDRESS,DS1307_REG_SECOND,se); //设置秒
registerSet(DS1307_ADDRESS,DS1307_REG_MINITUE,mt); //设置分钟
registerSet(DS1307_ADDRESS,DS1307_REG_HOURS,hr); //设置时
registerSet(DS1307_ADDRESS,DS1307_REG_WEEK,we); //设置星期
registerSet(DS1307_ADDRESS,DS1307_REG_DATE,da); //设置日
registerSet(DS1307_ADDRESS,DS1307_REG_MONTH,mh); //设置月
registerSet(DS1307_ADDRESS,DS1307_REG_YEAR,yr); //设置年
registerSet(DS1307_ADDRESS,DS1307_REG_CTRL,0x10); // 输出控制
registerSet(DS1307_ADDRESS,DS1307_STOP_START,startt); //时钟计数器开始
}
////////////////// 将星期数字转化为字符串 ///////////////////////
char* weektoString(byte week)
{
char *weekstring[9];
switch(week)
{
case 1 :
weekstring[9] = "Monday" ;
return weekstring[9];
break;
case 2 :
weekstring[9] = "Thuesday" ;
return weekstring[9];
break;
case 3 :
weekstring[9] = "Wednesday" ;
return weekstring[9];
break;
case 4 :
weekstring[9] = "Tursday" ;
return weekstring[9];
break;
case 5 :
weekstring[9] = "Friday" ;
return weekstring[9];
break;
case 6 :
weekstring[9] = "Saturrday" ;
return weekstring[9];
break;
case 7 :
weekstring[9] = "Sunday" ;
return weekstring[9];
break;
default :
weekstring[9] = "Err";
return weekstring[9];
break;
}
}
char* HAPM(byte h12)
{
char *H1224[1];
switch (h12)
{
case 1:
H1224[1] = "P";
return H1224[1];
case 0 :
H1224[1] = "A";
return H1224[1];
case 3 :
H1224[1] = " ";
return H1224[1];
default :
H1224[1] = "E";
return H1224[1];
}
}
/////////////////显示英文字符//////////////////////
void lcdCharacter(char character)
{
lcdWrite(LCD_D, 0x00);
for (int index = 0; index < 5; index++)
{
lcdWrite(LCD_D, ASCII[character - 0x20][index]);
}
lcdWrite(LCD_D, 0x00);
}
////////////////////////显示中文汉字//////////////
void lcdChinese(byte row,byte page,byte data)
{
gotoXY(row * 8,page);
for (int index = 0; index < 12; index++ )
{
lcdWrite(LCD_D, charch[data][index]);
}
gotoXY(row * 8,page+1);
for (int index = 12; index < 24; index++ )
{
lcdWrite(LCD_D, charch[data][index]);
}
lcdWrite(LCD_D, 0x00);
}
//////////////清屏////////////////////////////
void lcdClear(void)
{
for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
{
lcdWrite(LCD_D, 0x00);
}
}
//////////////////// 初始化屏幕 //////////////
void lcdInitialise(void)
{
pinMode(PIN_SCE, OUTPUT);
pinMode(PIN_RESET, OUTPUT);
pinMode(PIN_DC, OUTPUT);
pinMode(PIN_SDIN, OUTPUT);
pinMode(PIN_SCLK, OUTPUT);
digitalWrite(PIN_RESET, LOW);
digitalWrite(PIN_RESET, HIGH);
lcdWrite(LCD_CMD, 0x21); // LCD 扩展命令模式
lcdWrite(LCD_CMD, 0xBf); // LCD 偏置电压设定
lcdWrite(LCD_CMD, 0x04); // LCD 温度补偿设定
lcdWrite(LCD_CMD, 0x12); // LCD 对比度 设定
lcdWrite(LCD_CMD, 0x0C); // LCD 增量模式
lcdWrite(LCD_C, 0x20);
lcdWrite(LCD_C, 0x0C);
}
///////////// 英文字符串显示 ///////////////
void lcdString(char *characters)
{
while (*characters)
{
lcdCharacter(*characters++);
}
}
//////////////// 屏幕写操作 //////////////
void lcdWrite(byte dc, byte data)
{
digitalWrite(PIN_DC, dc);
digitalWrite(PIN_SCE, LOW);
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
digitalWrite(PIN_SCE, HIGH);
}
////gotoXY 设定光标位置
////x - range: 0 to 84
////y - range: 0 to 5
//////////////字符位置设定////////////////
void gotoXY(int x, int y)
{
lcdWrite( 0, 0x80 | x); // 列
lcdWrite( 0, 0x40 | y); // 行
}
//////////////字符串滚动///////////////
void stringScroll(String message)
{
for (int i = scrollPosition; i < scrollPosition + 11; i++)
{
if ((i >= message.length()) || (i < 0))
{
lcdCharacter(' ');
}
else
{
lcdCharacter(message.charAt(i));
}
}
scrollPosition++;
if ((scrollPosition >= message.length()) && (scrollPosition > 0))
{
scrollPosition = -10;
}
}
////////////////////////英文格式显示/////////
void displayEng()
{
byte PM;
PM = timeGetcharacter();
gotoXY(0,1);
lcdString("20");
lcdCharacter(year_H);
lcdCharacter(year_L);
lcdCharacter('.');
lcdCharacter(month_H);
lcdCharacter(month_L);
lcdCharacter('.');
lcdCharacter(date_H);
lcdCharacter(date_L);
gotoXY(15,2);
lcdString(weektoString(week));
gotoXY(4,3);
lcdString(HAPM(PM));
if (HAPM(PM)=="P" || HAPM(PM)=="A" )
lcdCharacter('M');
lcdCharacter(hour_H);
lcdCharacter(hour_L);
lcdCharacter(':');
lcdCharacter(minitue_H);
lcdCharacter(minitue_L);
lcdCharacter(':');
lcdCharacter(second_H);
lcdCharacter(second_L);
}
////////////////////////中文显示格式/////////
void displayCh()
{
byte PM;
PM = timeGetcharacter();
gotoXY(0,0);
lcdString("20");
gotoXY(0,1);
lcdCharacter(year_H);
lcdCharacter(year_L);
lcdChinese(2,0,7);
gotoXY(30,0);
lcdCharacter(month_H);
gotoXY(30,1);
lcdCharacter(month_L);
lcdChinese(5,0,8);
gotoXY(53,0);
lcdCharacter(date_H);
gotoXY(53,1);
lcdCharacter(date_L);
lcdChinese(8,0,6);
lcdChinese(2,2,12);
lcdChinese(4,2,13);
lcdChinese(6,2,week-1);
gotoXY(0,4);
lcdString(HAPM(PM));
gotoXY(0,5);
if (HAPM(PM)=="P" || HAPM(PM)=="A" )
lcdCharacter('M');
gotoXY(10,4);
lcdCharacter(hour_H);
gotoXY(10,5);
lcdCharacter(hour_L);
lcdChinese(2,4,9);
gotoXY(30,4);
lcdCharacter(minitue_H);
gotoXY(30,5);
lcdCharacter(minitue_L);
lcdChinese(5,4,10);
gotoXY(53,4);
lcdCharacter(second_H);
gotoXY(53,5);
lcdCharacter(second_L);
lcdChinese(8,4,11);
}
void setup()
{
Wire.begin(); //I2C初始化
Serial.begin(9600); //串口通讯初始化
timeSet(12,10,5,10,58,0,5,true,true);
lcdInitialise();
lcdClear();
}
void loop(void)
{
displayCh();
delay(2000);
}
[/code]
|