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

📄 ds12887.c

📁 DS12887A是Dallas公司的一款内置电池的时钟芯片。该程序基于GCC
💻 C
字号:

#include "delay.h"
#include "ds12887.h"
#define timer_sec (*(volatile unsigned char *)0x2000) 
#define timer_min (*(volatile unsigned char *)0x2002) 
#define timer_hour (*(volatile unsigned char *)0x2004) 
#define timer_week (*(volatile unsigned char *)0x2006) 
#define timer_day (*(volatile unsigned char *)0x2007)
#define timer_moth (*(volatile unsigned char *)0x2008) 
#define timer_year (*(volatile unsigned char *)0x2009) 

#define timer_ra (*(volatile unsigned char *)0x200a) 
#define timer_rb (*(volatile unsigned char *)0x200b) 
#define timer_rc (*(volatile unsigned char *)0x200c) 
#define timer_rd (*(volatile unsigned char *)0x200d) 


	unsigned char sec_buf,min_buf,hour_buf,sec0,sec1,min0,min1,hour0,hour1;
	unsigned char year,moth,day,week,hour,min,sec;
	unsigned char year_buf,moth_buf,day_buf,week_buf,year0,year1,moth0,moth1,day0,day1;
	unsigned char tab2[]={'0','1','2','3','4','5','6','7','8','9'};
	unsigned char tab3[]={"  日一二三四五六"};

  
	//////////////////////////////////////////////////////////////
	void disp(unsigned char data)
	{
//		write_lcm_data=tab2[data];
		delay_nus(100);
	
	}
	/////////
	void disp_week(unsigned char wk)
	{
		wk=wk*2;
//		write_lcm_data=tab3[wk];
		delay_nus(100);
		wk++;
//		write_lcm_data=tab3[wk];
		delay_nus(100);
	
	}
	//////////////////////////////////////////
	void time_set(unsigned int year,
				unsigned int moth,
				unsigned int day,
				unsigned int week,
				unsigned int hour,
				unsigned int min,
				unsigned int sec)
		{
		timer_year=year;
		timer_moth=moth;
		timer_day=day;
		timer_week=week;
		timer_hour=hour;
		timer_min=min;
		timer_sec=sec;
		
		}
	
	
	//////////////////////////////////////
	
	void display_time(unsigned char time_adr)
	{
		sec_buf=timer_sec;
		min_buf=timer_min;
		hour_buf=timer_hour;
		//////////////
		
		sec1=sec_buf/10;
		sec0=sec_buf-sec1*10;
		///
		min1=min_buf/10;
		min0=min_buf-min1*10;
		///
		hour1=hour_buf/10;
		hour0=hour_buf-hour1*10;
		/////////////
//		write_lcm_ins=time_adr;
		delay_nus(100);
		disp(hour1);
		disp(hour0);
//		write_lcm_data=':';
		delay_nus(100);
		disp(min1);
		disp(min0);
//		write_lcm_data=':';
		delay_nus(100);
		disp(sec1);
		disp(sec0);
		
	}
	/////////////////////////////////////
	void display_date(unsigned char date_adr)
	{
		
		year_buf=timer_year;
		moth_buf=timer_moth;
		day_buf=timer_day;
		week_buf=timer_week;
		/////////////////////////////
		year1=year_buf/10;
		year0=year_buf-year1*10;
		///
		moth1=moth_buf/10;
		moth0=moth_buf-moth1*10;
		///
		day1=day_buf/10;
		day0=day_buf-day1*10;
		///
		week=week_buf;
		///
		////////////////////////////
//		write_lcm_ins=date_adr;
		delay_nus(100);
//		write_lcm_ins=date_adr;
		delay_nus(100);
		disp(2);
		disp(0);
		disp(year1);
		disp(year0);
//		write_lcm_data='-';
		delay_nus(100);
		disp(moth1);
		disp(moth0);
//		write_lcm_data='-';
		delay_nus(100);
		disp(day1);
		disp(day0);
//		write_lcm_data='-';
		delay_nus(100);
//		write_lcm_data='(';
		delay_nus(100);
		disp_week(week);
//		write_lcm_data=')';
		delay_nus(100);	
	
	}
	////////////////////////////////
	
	
	

⌨️ 快捷键说明

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