Aangezien mijn Alfa niet met zijn lichten knippert als je hem op slot zet of van het slot af haalt, heb ik een klein stuk C code geschreven voor een AVR microcontroller. Daarbij heeft het ook de functionaliteit om de fan aan te zetten zodra de auto van het contact afgaat. Dit omdat het nooit goed is om de auto meteen uit te zetten als je even flink getrapt hebt. Als je alleen even naar de super gereden bent is dit natuurlijk overbodig en daarom heb ik ook nog de functionaliteit erin gemaakt om onder het rijden de fan aan en uit te zetten. Als je hem dus van het contact haalt, slaat de fan aan voor de komende paar minuten, druk je ondertussen op de knop, gaat de fan gewoon weer uit en thats it.
Ik zal het van de week even proberen te testen, maar in de debugger lijkt het allemaal te werken. Als het werkt, zal ik er een printje van maken en een behuizinkje bijzoeken zodat iedereen het kan maken.
tot die tijd, hier de code:
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
| /* Include default libraries */
#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
/* Define program constants */
#define FAN_MINUTES 3
#define BLINK_OPEN 1
#define BLINK_CLOSE 2
int overflows;
int seconds;
/* Main function */
int main (void)
{
/* Initialize I/O Ports */
/* Remote control (open) is on PB0 */
/* Remote control (close) is on PB4 */
// Are inputs, all i/o's are default inputs
DDRB = 0x00;
PORTB = 0x00;
/* The output for the lights is on PC5 */
/* The output for the fan is on PC2 */
DDRC = 0x24;
/* Initialize Timer */
/* We use timer 0 because we don't need a complex timer */
/* Set default timer operation */
TCCR0 = 0x00;
/* Set intial value */
TCNT0 = 0x00;
/* Set timer overflow interrupt */
TIMSK = 0x01;
/* We count the number of loops, not a specified value */
/* Initialize Interrupts */
/* Interrupt for remote control is on interrupt 2, positive edge */
/* Interrupt for contact switch is on interrupt 1, negative edge */
/* Interrupt for button is on interrupt 0, positive edge */
MCUCR &= 0xF0;
MCUCR |= 0x0B;
MCUCSR &= 0x9F;
/* Set interrupts active */
GICR &= 0x03;
GICR |= 0xE0;
/* Enable interrupts */
sei ();
/* Infinite loop */
while (1) {}
}
/* Button pressed, switch fan on or off */
ISR(SIG_INTERRUPT0)
{
//Pressed button
//Check if the fan is on or off
if (!(PINC & 0x04))
{
//Fan was off, switch it on
PORTC |= 0x04;
}
else
{
//Fan was on, switch it off and reset all the timers etc.
//Turn the fan off
PORTC &= 0xFB;
//Reset seconds and overflows
overflows = 0;
seconds = 0;
//Turn off the counter and reset counter
TCCR0 = 0x00;
TCNT0 = 0x00;
}
}
/* Contact is turned off, switch fan on */
ISR(SIG_INTERRUPT1)
{
//Set timer and counters to default values
TCNT0 = 0x00;
overflows = 0;
seconds = 0;
//Turn on timer with prescaler 256
TCCR0 = 0x04;
}
/* Doors are being opened or closed, blink! */
ISR(SIG_INTERRUPT2)
{
volatile unsigned short blinks;
volatile unsigned short blinked;
if (PORTB == 0x01)
blinks = BLINK_OPEN;
else
blinks = BLINK_CLOSE;
for (blinked = 0; blinked < blinks; blinked++)
{
//Turn on
PORTC |= 0x20;
//Wait
_delay_ms (500);
//Turn off
PORTC &= 0xDF;
//Wait
_delay_ms (500);
}
}
/* Timer overflow occured. Count and check if wait time is passed */
ISR(SIG_OVERFLOW0)
{
overflows++;
if (overflows == 15625)
{
overflows = 0;
seconds++;
if (seconds == (60 * FAN_MINUTES))
{
//Turn the fan off
PORTC &= 0xFB;
//Reset seconds
seconds = 0;
//Turn off the counter and reset counter
TCCR0 = 0x00;
TCNT0 = 0x00;
}
}
} |
PS: sorry voor de tech in dit topic, maar Alfa's willen nog wel eens warm lopen en dat de lichten niet knipperen is gewoon irritant. Vandaar dat ik het hier even post.
Als je interesse hebt als het een keer werkt voor een kant en klaar product, gooi me even een DM-tje en dan kijk ik wat ik kan doen.
A byte walks into a bar and orders a pint. Bartender asks him "What's wrong?" Byte says "Parity error." Bartender nods and says "Yeah, I thought you looked a bit off."