#include "STC15W204S.h"
#include <intrins.h>
#define uint unsigned int
#define u32 unsigned long int
#define uchar unsigned char
void Send_Byte_UART1(uchar dat) ;
#include "DS1302.h"
uint aa;
struct sTime Time; //日期时间缓冲区
void Init_MCU()
{
EA = 1; //开总中断
// TMOD |= 0x22; //设定定时器1为16位自动重装方式
// TL1 = 0xfd; //设定定时初值
// TH1 = 0xfd; //设定定时初值
//
// ET1 = 0; //禁止定时器1中断 ==1允许
// TR1 = 1; //启动定时器1
//
// REN=1;
// SM0=0;
// SM1=1;
SCON = 0x50; //8位数据,可变波特率
AUXR |= 0x04; //定时器2时钟为Fosc,即1T
T2L = 0xE0; //设定定时初值
T2H = 0xFE; //设定定时初值
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
AUXR |= 0x10; //启动定时器2
// TMOD|=0x01; //定時器0為模式1
// TH0=(65536-10000)/256; //裝高八位
// TL0=(65536-10000)%256; //裝低八位
// EA=1; //開總中斷
// ET0=1; //開定時器中斷
// TR0=1; //啟動定時器
// //100微秒@11.0592MHz
// AUXR |= 0x80; //定时器时钟1T模式
// TMOD &= 0xF0; //设置定时器模式
// TL0 = 0xAE; //设置定时初值
// TH0 = 0xFB; //设置定时初值
// TF0 = 0; //清除TF0标志
// TR0 = 1; //定时器0开始计时
//5毫秒@11.0592MHz
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x00; //设置定时初值
TH0 = 0x28; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1;
P3M0=0;
P3M1=0;
}
/*串口发送数据*/
void Send_Byte_UART1(uchar dat)
{
ES=0;
SBUF=dat;
while(!TI);
TI=0;
// ES =1;
}
void main()
{
uchar sec;
struct sTime buftime;
Init_MCU();
Init_DS1302 ();
buftime.year=95;
buftime.mon=1;
buftime.day=6;
buftime.hour=23;
buftime.min=59;
buftime.sec=55;
Set_Time(&buftime);
while(1)
{
Get_Time( &Time );
if(Time.sec!=sec)
{
sec=Time.sec;
Send_Byte_UART1(Time.year/10+0x30);
Send_Byte_UART1(Time.year%10+0x30);
Send_Byte_UART1(' ');
Send_Byte_UART1(Time.mon/10+0x30);
Send_Byte_UART1(Time.mon%10+0x30);
Send_Byte_UART1(' ');
Send_Byte_UART1(Time.day/10+0x30);
Send_Byte_UART1(Time.day%10+0x30);
Send_Byte_UART1(' ');
Send_Byte_UART1(Time.hour/10+0x30);
Send_Byte_UART1(Time.hour%10+0x30);
Send_Byte_UART1(' ');
Send_Byte_UART1(Time.min/10+0x30);
Send_Byte_UART1(Time.min%10+0x30);
Send_Byte_UART1(' ');
Send_Byte_UART1(Time.sec/10+0x30);
Send_Byte_UART1(Time.sec%10+0x30);
Send_Byte_UART1(' ');
Send_Byte_UART1(Time.week/10+0x30);
Send_Byte_UART1(Time.week%10+0x30);
Send_Byte_UART1(' ');
Send_Byte_UART1(Time.mon_CTC/10+0x30);
Send_Byte_UART1(Time.mon_CTC%10+0x30);
Send_Byte_UART1(' ');
Send_Byte_UART1(Time.day_CTC/10+0x30);
Send_Byte_UART1(Time.day_CTC%10+0x30);
Send_Byte_UART1('\n');
}
}
}
/*定时器0中断服务程序*/
void Timer_0() interrupt 1
{
if((aa++)>=10000){aa=0;} //定时器记数
}

夜绿猫
- 粉丝: 2
最新资源
- 互联网直播服务管理规定解读.doc
- 算法合集之浅析竞赛中一类数学期望问题的解决方法.pptx
- 现代企业网络营销研讨会.pptx
- 网络慕课的推广与应用.pptx
- 软件需求规格说明书.doc
- (源码)基于机器学习的心电异常事件预测.zip
- 利用征信数据库开拓市场ppt课件.ppt
- 思政课网络教学平台.docx
- (源码)基于C++语言框架的排序算法总结项目.zip
- (源码)基于Arduino的DC电机H桥控制系统.zip
- (源码)基于Arduino的RFID读卡器项目.zip
- 计算机操作系统期末复习资料整合项目-操作系统原理-进程管理-内存管理-文件系统-设备管理-死锁处理-调度算法-同步机制-虚拟内存-分页分段-银行家算法-磁盘调度-系统调用-中断处理.zip
- (源码)基于React和Vue框架的现代简约博客系统.zip
- 南京大学计算机系统基础课程实践项目-包含程序设计与计算机系统实验PA及配套实验Lab-旨在通过实践加深对计算机系统原理的理解-涵盖汇编语言编程处理器架构模拟操作系统内核.zip
- (源码)基于PythonArduino框架的机械式音乐放大器.zip
- (源码)基于FTL Spacecrew Universal Cockpit的控制器系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


