-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpwm.c
More file actions
45 lines (43 loc) · 761 Bytes
/
pwm.c
File metadata and controls
45 lines (43 loc) · 761 Bytes
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
#include "pwm.h"
#include "stc15f2k60s2.h"
typedef unsigned char BYTE;
void InitPWM()
{
//freq = sysclk/2; io = p1.1
ACC = P_SW1;
ACC &= ~(CCP_S0 | CCP_S1);
P_SW1 = ACC;
CL = 0;
CH = 0;
CMOD = 0X02;
PCA_PWM0 = 0X00;
CCAP0H = CCAP0L = 0xcc;
CCAPM0 = 0X42;
CR = 1;
}
void UpdateDC(int newDC)
{
CR = 0;
CCAP0H = CCAP0L = newDC;
CR = 1;
}
//int Str2Int(char* pStr, int n)
//{
// int result = 0;
// int fact = 1;
// int i = n-1;
// for(; i >= 0; i--)
// {
// result += fact*(pStr[i]-'0');
// fact *= 10;
// }
// if(result <0 || result >100)//if input illegal,set result 20,means that duty cycle is 20%
// result = 20;
// return result;
//}
//void ClearString(char* pStr, int n)
//{
// int i = 0;
// for(; i < n; i++)
// pStr[i] = '\0';
//}