-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.c
More file actions
166 lines (151 loc) · 3.96 KB
/
clock.c
File metadata and controls
166 lines (151 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/***************************************************************************************
* FileName : clock.c
* CopyRight :
* ModuleName :
*
* CPU :
* RTOS :
*
* Create Data : 2017.7.22
* Author/Corportation : yezhihuo
*
* Abstract Description :
*
*--------------------------------Revision History--------------------------------------
* No version Data Revised By Item Description
*
*
***************************************************************************************/
/**************************************************************
* Debug switch Section
**************************************************************/
/**************************************************************
* Include File Section
**************************************************************/
#include"clock.h"
/**************************************************************
* Macro Define Section
**************************************************************/
/**************************************************************
* Struct Define Section
**************************************************************/
/**************************************************************
* Prototype Declare Section
**************************************************************/
/**************************************************************
* Global Variable Declare Section
**************************************************************/
uchar sb = 0; //每增加20次记录1s
uchar clockTag = 0; //0为关闭,1为开启,2为正在向
clockTime time, timeclock;
sbit PWM = P3^5; //震动信号输出
uchar pwmCount, pwmPeriod ; //占空比计数器,占空比标数
uint num;
/**************************************************************
* Function Define Section
**************************************************************/
/**
* @name: void timeFun()
* @description: 中断服务特殊功能寄存器配置(定时器0初始化)
* @param :none
* @return : none
* @notice : 12MHZ
*/
void initTimer()
{
TMOD=0x01; //模式1
TH0 = (65536 - 45874) / 256;
TL0 = (65536 - 45874) % 256; //0.05s
ET0=1; //开定时器
TR0=1; //开定时器中断
EA=1; //开总中断
}
/**
* @name: void timeFun()
* @description: 时钟计时
* @param :none
* @return : none
* @notice : 使用定时器0,程序运行期间始终运行
*/
void timeFun() interrupt 1
{
TH0 = (65536 - 45870) / 256;
TL0 = (65536 - 45870) % 256; //0.05s
if(sb >= 20 ) //20次为1s
{
sb = 0;
if( time.second < 59 ) //60秒
{
time.second++;
}
else
{
time.second = 0;
if( time.minute <59 ) //60分钟
{
time.minute++;
}
else
{
time.minute = 0;
if( time.hour <23 ) ///1小时
{
time.hour++;
}
else
{
time.hour = 0;
}
}
}
if( clockTag == 1 ) //判断闹钟
{
if(time.hour == timeclock.hour && time.minute == timeclock.minute && time.second == timeclock.second)
{
clockTag = 2;
}
}
}
else
{
sb++;
}
}
/**
* @name:void pwmInit();
* @description: 初始化pwm,开启震动
* @param :none
* @return : none
* @notice : 使用定时器1
*/
void pwm() interrupt 3
{
TH1 = 0XCC;
TL1 = 0XCC;
pwmCount++;
num++;
if( num > 60000 )
{
num = 0;
}
if( num % 1000 == 0 ) //从新计数
{
pwmPeriod += 10;
}
if( pwmCount == 100 )
{
pwmCount = 0;
}
if( pwmPeriod > 100 )
{
pwmPeriod = PWM_MODE;
}
if( pwmCount < pwmPeriod ) //控制输出
{
PWM = 1;
}
else
{
PWM = 0;
}
}