【蓝桥杯(51) STC15F2K60S2】之 “DS1302“实验 | 您所在的位置:网站首页 › 蓝桥杯ds1302程序 › 【蓝桥杯(51) STC15F2K60S2】之 “DS1302“实验 |
相关代码:
主函数部分:
#include “STC15F2K60S2.H” #include “absacc.h” #include “ds1302.h” unsigned char SMGNoDot_CA[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; unsigned char Write_DS1302[7] = {0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; unsigned char Read_DS1302[7] = {0x81,0x83,0x85,0x87,0x89,0x8b,0x8c}; //21年2月26日星期五24点59分30秒 unsigned char Time[7] = {0x30,0x59,0x23,0x26,0x02,0x05,0x21}; void Delay(unsigned char t) { while(t–); } void config() { unsigned char i; Write_Ds1302_Byte(0x8e,0x00); for(i=0;i unsigned char i; for(i=0;i XBYTE[0xc000] = 0xff; XBYTE[0xe000] = 0xff; } void DisSMG(unsigned char pos,unsigned char dat) { XBYTE[0xe000] = 0xff; XBYTE[0xc000] = 0x01 XBYTE[0x8000] = 0xff; config(); while(1) { Read_DS1302C(); Display(); } } DS1302驱动.c文件:/* 程序说明: DS1302驱动程序 软件环境: Keil uVision 4.10 硬件环境: CT107单片机综合实训平台 8051,12MHz 日 期: 2011-8-9 */ #include #include sbit SCK=P1^7; sbit SDA=P2^3; sbit RST = P1^3; // DS1302复位 void Write_Ds1302(unsigned char temp) { unsigned char i; for (i=0;i RST=0; nop(); SCK=0; nop(); RST=1; nop(); Write_Ds1302(address); Write_Ds1302(dat); RST=0; } unsigned char Read_Ds1302_Byte ( unsigned char address ) { unsigned char i,temp=0x00; RST=0; nop(); SCK=0; nop(); RST=1; nop(); Write_Ds1302(address); for (i=0;i>=1; if(SDA) temp|=0x80; SCK=1; } RST=0; nop(); SCK=0; nop(); SCK=1; nop(); SDA=0; nop(); SDA=1; nop(); return (temp); } DS1302驱动.h文件:#ifndef __DS1302_H #define __DS1302_H //void Write_Ds1302(unsigned char temp); void Write_Ds1302_Byte( unsigned char address,unsigned char dat ); unsigned char Read_Ds1302_Byte( unsigned char address ); #endif |
CopyRight 2018-2019 实验室设备网 版权所有 |