⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtc.c

📁 已经上传的YF-320240-3.5寸彩屏(可由单片机控制)的测试程序。主CPU为MEGA128
💻 C
字号:
#include <iom128v.h>
#include "rtc.h"
#include "lcd.h"
#include <eeprom.h>

/***************************************************************
 address     data
 0           second
 2           minutes
 4           hour
 8           month
 9           year
 A           register A
 B           register B
 C           register C
 D           register D
 E           2000year high byte
***************************************************************/
struct Time time;
void ReadTime(void)//时间是BCD码
{   
	    while(REG_A & 0x80);
	    time.second = SECOND;
		time.minute = MINUTE;
		time.hour   = HOUR;
		time.day    = DAY;
		time.month  = MONTH;
		time.year_L   = YEAR;
		time.year_H   = REG_E;
}
void DisTime(unsigned int x,unsigned char y,unsigned char front,unsigned char back)
{
    unsigned char temp;
	ReadTime();
	temp = time.hour>>4;//hour的十位数
	Dis_Ascii(x,y,temp+0x30,front,back);
	x+=8;
	temp = time.hour & 0x0f;
	Dis_Ascii(x,y,temp+0x30,front,back);
	x+=8;
	Dis_Ascii(x,y,':',front,back);
	x+=8;
	temp = time.minute>>4;
	Dis_Ascii(x,y,temp+0x30,front,back);
	x+=8;
	temp = time.minute & 0x0f;
	Dis_Ascii(x,y,temp+0x30,front,back);
	x+=8;
	Dis_Ascii(x,y,':',front,back);
	x+=8;
	temp = time.second>>4;
	Dis_Ascii(x,y,temp+0x30,front,back);
	x+=8;
	temp = time.second & 0x0f;
	Dis_Ascii(x,y,temp+0x30,front,back);
	
}
void DisTimeAll(unsigned int x,unsigned char y,unsigned char front,unsigned char back)
{
    unsigned char temp[11];
	ReadTime();
	temp[0] = (time.year_H >> 4)+0x30;
	temp[1] = (time.year_H &0x0f)+0x30;
	temp[2] = (time.year_L >> 4)+0x30;
	temp[3] = (time.year_L & 0x0f)+0x30;
	temp[4] = '/';
	temp[5] = (time.month >> 4)+0x30;
	temp[6] = (time.month & 0x0f)+0x30;
	temp[7] = '/';
	temp[8] = (time.day >> 4)+0x30;
	temp[9] = (time.day & 0x0f)+0x30;
	temp[10] = 0;
	Display(x,y,temp,BIG,front,back);
	
	temp[0] = (time.hour >> 4)+0x30;
	temp[1] = (time.hour & 0x0f)+0x30;
	temp[2] = '/';
	temp[3] = (time.minute >> 4)+0x30;
	temp[4] = (time.minute & 0x0f)+0x30;
	temp[5] = '/';
	temp[6] = (time.second >> 4)+0x30;
	temp[7] = (time.second & 0x0f)+0x30;
	temp[8] = 0;
	Display(x+32,y+25,temp,BIG,front,back);
	
}
void SetTime(void)
{
    REG_B=0xb2;
    SECOND = 0; //second
    MINUTE = 0; //minutes
    HOUR = 0;   //hour
    DAY = 0;   //day
    MONTH = 0;  //month
    YEAR = 0;  //year
	REG_E = 0x20;//year high byte
    REG_A = 0x20;
	REG_B = 0x12;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -