-
Notifications
You must be signed in to change notification settings - Fork 0
/
WDT.c
63 lines (53 loc) · 1008 Bytes
/
WDT.c
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
#include"msp430f5438.h"
#include"Global.h"
//WDT_PWM主要为舵机使用
//如果使用WDT_PWM,一个最小WDT溢出周期为2ms/125=16us
//一个PWM周期为2ms,占空比用0~125表示,0表示0%,125表示100%
#ifdef WDT_PWM_Used_
#define WDT_CYCLE 125
unsigned char WDT_cnt = 0;
unsigned char WDT_duty1 = 0;
#endif
void WDT_init()
{
#ifdef WDT_PWM_Used
WDTCTL = WDTPW + WDTSSEL__SMCLK + WDTTMSEL + WDTIS_7;
SFRIE1 |= WDTIE;
P8DIR |= BIT7;
P8OUT |= BIT7;
P8DS |= BIT7;
//更多PWM口定义...
#else
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
#endif
}
#ifdef WDT_PWM_Used
void WDT_PWM_1(unsigned int n)
{
WDT_duty1 = n;
}
//void WDT_PWM_2(unsigned int n)
//{
// WDT_duty2 = n;
//}
#pragma vector = WDT_VECTOR
__interrupt void WDT_ISR()
{
WDT_cnt++;
if (WDT_cnt == WDT_duty1)
{
P8OUT &=~BIT7;
}
// if (WDT_cnt == WDT_duty2)
// {
// P8OUT &=~BIT6;
// }
//更多定义
if (WDT_cnt == WDT_CYCLE)
{
WDT_cnt = 0;
P8OUT |= BIT7;
}
}
#endif