-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
95 lines (83 loc) · 2.13 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* uA-thermometer for ATTiny13
* (C) 2011 Akafugu Corporation
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
*/
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include "onewire.h"
// duty cycles for temperatures 0C ~ 50C calibrated for 5V with 100kohm resistor
extern const uint8_t temp[51] PROGMEM;
const uint8_t temp[51] PROGMEM = { 0,
0, 6, 11, 16, 21, 26, 32, 37, 43, 48, // 10
54, 59, 65, 70, 75, 82, 86, 92, 98, 103, // 20
110, 115, 121, 126, 131, 137, 144, 148, 154, 159, // 30
163, 168, 173, 178, 184, 189, 194, 200, 205, 211, // 40
216, 222, 226, 232, 237, 242, 247, 255, 255, 255 }; // 50
void show_temp(uint8_t t)
{
OCR0A = pgm_read_byte(temp + t);
}
void WaitLoop(void)
{
for (uint8_t i = 0; i < 10; i++)
_delay_ms(1000);
}
int main(void)
{
// Initialize PWM
// CS00 -> no prescaler for clock
// COM0A1 -> Compare Match Output A Mode
// WGM00 and WGM01 -> fast PWM mode
TCCR0A |=(1<<WGM00)|(1<<WGM01)|(1<<COM0A1)|(1<<CS00);
TCCR0B = (1<<CS00);
// Set PWM pin as output
DDRB |= (1<<PB0);
// Throw away initial temperature measurement
start_meas();
read_meas();
// Splash screen
{
OCR0A = 0;
_delay_ms(1000);
OCR0A = 103;
_delay_ms(500);
OCR0A = 48;
_delay_ms(500);
OCR0A = 159;
_delay_ms(500);
OCR0A = 103;
_delay_ms(500);
OCR0A = 211;
_delay_ms(500);
OCR0A = 159;
_delay_ms(500);
OCR0A = 255;
_delay_ms(500);
OCR0A = 211;
_delay_ms(500);
OCR0A = 255;
_delay_ms(1000);
}
while (1) {
start_meas();
show_temp(read_meas() / 100);
WaitLoop();
/* test code
for (temp = 1; temp <= 50; temp++) {
show_temp(temp);
_delay_ms(2000);
}
*/
}
}