-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCAPSense.c
78 lines (66 loc) · 1.85 KB
/
CAPSense.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifdef __XC__
#include <xc.h>
#else
#include <htc.h>
//#include <stddef.h>
#endif
#include "IOCycle.h"
#include "DS18B20.h"
#include "IOConfig.h"
#include "CAPSense.h"
bit WaitForStartDeciSecond;
bit WaitForEndDeciSecond;
bit GotCapSenseFlag;
void CAPSENSECycleIdle(void)
{
unsigned char _temp;
CurrentIOStatus=IO_STATUS_OK;
CurrentIOCycle=IO_CYCLE_START;
// select capsense
CPSCON1 = CSMASK[CurrentIOPin];
CPSON=0;
TMR0IE=0;
_TMR0_MSB=0;
TMR0=0;
WaitForStartDeciSecond=0;
WaitForEndDeciSecond=0;
GotCapSenseFlag=0;
// force TMR0 TO CLOCK CAPSENSE
if(CurrentIOSensor.Config == IOCONFIG_CAP_SENSE_OFF)
CPSCON0= 0b10000001;
else if(CurrentIOSensor.Config == IOCONFIG_CAP_SENSE_LOW)
CPSCON0= 0b10000101;
else if(CurrentIOSensor.Config == IOCONFIG_CAP_SENSE_MEDIUM)
CPSCON0= 0b10001001;
//if(CurrentIOSensor == IOCONFIG_CAP_SENSE_HIGH)
else
CPSCON0= 0b10001101;
OPTION_REG=0B00100000;
TMR0CS=1;
TMR0IE=0;
Timer0Overflow=1;
WaitForStartDeciSecond=1;
GotCapSenseFlag=0;
}
void DoCAPSENSECycle(void)
{
if(CurrentIOCycle==IO_CYCLE_IDLE)
CAPSENSECycleIdle();
else if(CurrentIOCycle==IO_CYCLE_START)
{
if(GotCapSenseFlag)
{
WorkingSensorData.BYTE[0]=0;
WorkingSensorData.BYTE[1]= _TMR0_MSB>>8;
WorkingSensorData.BYTE[2]= (_TMR0_MSB & 0xff);
WorkingSensorData.BYTE[3]= _TMR0;
_TMR0_MSB=0;
_TMR0=0;
CurrentIOCycle=IO_CYCLE_END;
CurrentIOStatus= IO_STATUS_OK;
CPSON=0;
TMR0CS=0;
TMR0IE=0;
}
}
}