基于 ATMEGA16L的DS1602实时时钟显示北京时间和纽约时间如果改成北京和伦敦时间应该怎么改
时间:10-02
整理:3721RD
点击:
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/sfr_defs.h>
#include <string.h>
#include <stdio.h>
#define INT8U unsigned char
#define INT16U unsigned int
//液晶相关函数
//DS1302相关函数与数据
extern void GetDateTime();
extern INT8U DateTime[];
extern char *WEEK[];
char LCD_DSY_BUFFER_BY[17]; //LCD显示缓冲数组
char LCD_DSY_BUFFER_NY[17];
INT8U NYDateString[4]; //纽约日期存储数组
INT8U NYTimeString[4]; //纽约时间存储数组
void NewYorkTimeChange();
//将获取到的北京时间转换成纽约时间
void NewYorkTimeChange()
{
//获取北京日期和时间并存储,后转换为显示字符
GetDateTime();
//将北京时间和日期转换为纽约时间和日期
strncpy(NYDateString,&DateTime[3],4);
strncpy(NYTimeString,DateTime,4);
if(DateTime[2]>13)
{
NYTimeString[2]=DateTime[2]-13;
}
if(DateTime[2]<13&&DateTime[2]>0)
{
NYDateString[0]= DateTime[3]-1;
NYTimeString[2]=DateTime[2]+11;
}
if(DateTime[2]==13)
{
NYTimeString[2]=0;
}
}
int main()
{
DDRA=0XFF;
DDRC=0XFF;
DDRD=0XFF;
LCDPort_Init();
LCD_Init();
while(1)
{
//获取北京时间和纽约时间
NewYorkTimeChange();
//LCD显示北京时间
sprintf( LCD_DSY_BUFFER_BY,"%02d-%02d-%02d",DateTime[6],DateTime[4],DateTime[3]);
Write_Data_String(0,0,LCD_DSY_BUFFER_BY);
sprintf(LCD_DSY_BUFFER_BY,"%02d:%02d:%02d",DateTime[2],DateTime[1],DateTime[0]);
Write_Data_String(8,0,LCD_DSY_BUFFER_BY);
//LCD显示纽约时间
sprintf( LCD_DSY_BUFFER_NY,"%02d-%02d-%02d",NYDateString[3],NYDateString[1],NYDateString[0]);
Write_Data_String(0,1,LCD_DSY_BUFFER_NY);
sprintf(LCD_DSY_BUFFER_NY,"%02d:%02d:%02d",NYTimeString[2],NYTimeString[1],NYTimeString[0]);
Write_Data_String(8,1,LCD_DSY_BUFFER_NY);
_delay_ms(100);
}
}
#include <avr/io.h>
#include <util/delay.h>
#include <avr/sfr_defs.h>
#include <string.h>
#include <stdio.h>
#define INT8U unsigned char
#define INT16U unsigned int
//液晶相关函数
//DS1302相关函数与数据
extern void GetDateTime();
extern INT8U DateTime[];
extern char *WEEK[];
char LCD_DSY_BUFFER_BY[17]; //LCD显示缓冲数组
char LCD_DSY_BUFFER_NY[17];
INT8U NYDateString[4]; //纽约日期存储数组
INT8U NYTimeString[4]; //纽约时间存储数组
void NewYorkTimeChange();
//将获取到的北京时间转换成纽约时间
void NewYorkTimeChange()
{
//获取北京日期和时间并存储,后转换为显示字符
GetDateTime();
//将北京时间和日期转换为纽约时间和日期
strncpy(NYDateString,&DateTime[3],4);
strncpy(NYTimeString,DateTime,4);
if(DateTime[2]>13)
{
NYTimeString[2]=DateTime[2]-13;
}
if(DateTime[2]<13&&DateTime[2]>0)
{
NYDateString[0]= DateTime[3]-1;
NYTimeString[2]=DateTime[2]+11;
}
if(DateTime[2]==13)
{
NYTimeString[2]=0;
}
}
int main()
{
DDRA=0XFF;
DDRC=0XFF;
DDRD=0XFF;
LCDPort_Init();
LCD_Init();
while(1)
{
//获取北京时间和纽约时间
NewYorkTimeChange();
//LCD显示北京时间
sprintf( LCD_DSY_BUFFER_BY,"%02d-%02d-%02d",DateTime[6],DateTime[4],DateTime[3]);
Write_Data_String(0,0,LCD_DSY_BUFFER_BY);
sprintf(LCD_DSY_BUFFER_BY,"%02d:%02d:%02d",DateTime[2],DateTime[1],DateTime[0]);
Write_Data_String(8,0,LCD_DSY_BUFFER_BY);
//LCD显示纽约时间
sprintf( LCD_DSY_BUFFER_NY,"%02d-%02d-%02d",NYDateString[3],NYDateString[1],NYDateString[0]);
Write_Data_String(0,1,LCD_DSY_BUFFER_NY);
sprintf(LCD_DSY_BUFFER_NY,"%02d:%02d:%02d",NYTimeString[2],NYTimeString[1],NYTimeString[0]);
Write_Data_String(8,1,LCD_DSY_BUFFER_NY);
_delay_ms(100);
}
}
消灭0回复哦,,