栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

蓝桥杯51单片机-DS1302实时时钟

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

蓝桥杯51单片机-DS1302实时时钟

#include
#include

unsigned char num[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//0-9
unsigned char num2[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//0.--9.
unsigned char wirte_address[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};//写寄存器的地址
unsigned char read_address[7] ={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};//读寄存器的地址
unsigned char time[7]={0x50,0x55,0x14,0x05,0x06,0x07,0x22};
//以16进制的形式直接存放在数组中,显示的时候直接除于16即可
//秒 分 时 日 月 周 年
void HC573(unsigned char n)
{
	switch(n)
	{
		case 4:
			P2=(P2 & 0x1f) | 0x80;break;
		case 5:
			P2=(P2 & 0x1f) | 0xa0;break;
		case 6:
			P2=(P2 & 0x1f) | 0xc0;break;
		case 7:
			P2=(P2 & 0x1f) | 0xe0;break;
	}
}
void Initsystem()
{
	HC573(5);
	P0=0x00;
	HC573(4);
	P0=0xff;
}
void Delay(unsigned int t)
{
	while(t--);
}
void SMG_Show(unsigned char dat,unsigned char pos)
{
	HC573(6);
	P0=0x01< 

底层驱动代码

#ifndef __DS1302_H
#define __DS1302_H

#include 
#include 

sbit SCK = P1^7;		
sbit SDA = P2^3;		
sbit RST = P1^3; 

void Write_Ds1302(unsigned char temp);//写字节
void Write_Ds1302_Byte( unsigned char address,unsigned char dat );//向DS1302寄存器写入数据
unsigned char Read_Ds1302_Byte( unsigned char address );//从DS1302寄存器读出数据

#endif

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/953625.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号