-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreen.c
98 lines (78 loc) · 1.76 KB
/
green.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
95
96
97
98
#include <mega32.h>
#include <delay.h>
#include <stdlib.h>
#include <alcd.h>
#define push1 PINA.1
#define push2 PINA.2
#define push3 PINA.3
#define push4 PINA.4
float adc_data;
char up[5], low[5];
float up_limit=25, low_limit=18;
void disp_limit()
{
delay_ms(110);
ftoa(low_limit,0,low);
ftoa(up_limit,0,up);
lcd_gotoxy(0,1);
lcd_puts("Limits: ");
lcd_puts(low);
lcd_puts(" - ");
lcd_puts(up);
}
interrupt [ADC_INT] void adc_isr(void)
{
char disp[16];
// Read the AD conversion result
adc_data=ADCW/4; //1.5/10.24;
ftoa(adc_data,2,disp);
lcd_gotoxy(0,0);
lcd_puts("Temp: ");
lcd_puts(disp);
lcd_puts(" C");
}
void main(void)
{
ADMUX=0b11000000;
ADCSRA=(1<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (1<<ADIE) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
lcd_init(16);
lcd_clear();
#asm("sei")
DDRA =0b11000000;
while (1)
{
delay_us(10);
ADCSRA |= (1<<ADSC);
delay_ms(10);
if(adc_data<low_limit)
{
PORTA = 0b10000000;
}
else if(adc_data>up_limit)
{
PORTA = 0b01000000;
}
else
{
PORTA = 0b00000000;
}
//limit
disp_limit();
if(push1==0&&up_limit>low_limit) {
low_limit+=1;
disp_limit();
}
if(push2==0) {
low_limit-=1;
disp_limit();
}
if(push3==0&&up_limit>low_limit) {
up_limit-=1;
disp_limit();
}
if(push4==0) {
up_limit+=1;
disp_limit();
}
}
}