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

📄 1302.c

📁 DS1302的驱动程序。主程序用C语言编写
💻 C
字号:
/******************************************************
** Copyright (C), 1988-1999, Gxzjy.Djx.Dzjys       ****
** File name: DS1302                               ****
** Author: mingxin  Version:  1.1V  Date:2005.11.4 ****
** Description:  what is use DS1302  ,The main is to **
**         set the time to 1302 and display the time **
** Function List: display(),init_ds1302(),main() 	 **
**                write1302_byte(),read1302_byte()   **
** Others:  when program runing  you will have see   **
			the  LED show "hh.mm.ss" six number      **
******************************************************/

#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
#define disport P0

code uchar disp_data[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar disp[6]={1,2,3,4,5,6};

void delay(uchar x);
void display();

void init_ds1302();
void write1302_byte(uchar add,uchar dat);
uchar read1302_byte(uchar add);

main()
{	
	uchar k;
		init_ds1302();		
	while(1)
	{
		k=read1302_byte(0x85);	//read hour
		disp[0]=k&0x30;disp[0]>>=4;
		disp[1]=k&0x0f;
		k=read1302_byte(0x83);	//read min
		disp[2]=k&0x70;disp[2]>>=4;
		disp[3]=k&0x0f;	
		k=read1302_byte(0x81);	//read sec
		disp[4]=k&0x70;disp[4]>>=4;
		disp[5]=k&0x0f;
		display();
	}
}
void init_ds1302()
{
	write1302_byte(0x8e,0x00);
	write1302_byte(0x80,0x45);	//write sec
	write1302_byte(0x82,0x41);	//write min
	write1302_byte(0x84,0x11);	//write hour
}
void display()
{
	uchar i,j=0x01;
	uchar *k;
	k=&disp_data;

	disport=0;
	for(i=0;i<6;i++)
	{
		if ((i==3)|(i==1))
			disport=*(k+disp[i])|0x80;
		else
			disport=*(k+disp[i]);
		P1=j;
		j=j<<1;
		delay(3);
	}
	delay(3);
	disport=0;
}
void delay(uchar x)
{
	uchar i,j;
	for(j=0;j<x;j++)
	for(i=0;i<120;i++)
	{;}
}

⌨️ 快捷键说明

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