-
Notifications
You must be signed in to change notification settings - Fork 0
/
heater.c
72 lines (65 loc) · 1.47 KB
/
heater.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
/*********************************************************************
*
* Dew heater PWM controm
*
*********************************************************************
* FileName: heater.c
* Dependencies:
* Processor: PIC18F2550
* Complier: XC8 v1.45
*
* Software License Agreement
*
* Copyright © 2011-2019 Sylvain Girard
*
* Author Date Comment
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Sylvain Girard 05/04/2012 Creation
********************************************************************/
#define _HEATER_C
#include <xc.h>
#include "system.h"
#include "hid_focus.h"
unsigned int heat = 0;
void warm_up(unsigned int pwm)
{
if (pwm == 0)
{
T2CONbits.TMR2ON = 0;
CCP1CON = 0;
LATCbits.LATC2 = 0;
}
else
{
if (pwm > 1023)
{
T2CONbits.TMR2ON = 0;
CCP1CON = 0;
LATCbits.LATC2 = 1;
}
else
{
PR2 = 255;
CCPR1L = (pwm >> 2) & 0xFF;
CCP1CON = (pwm << 4) & 0x30;
TRISCbits.TRISC2 = 0;
T2CON = 3; // prescaler 1:16
T2CONbits.TMR2ON = 1;
CCP1CON |= 0x0F; // PWM Mode
}
}
}
void cmd_fhr(void)
{
answer( heat);
}
void cmd_fhl(void)
{
unsigned int h;
if (read_number(&h, 2) == TRUE)
{
heat = h;
warm_up(h);
answer(heat);
}
}