Commit 6637616fbc5f6bf24d4b64dc7dc87410181bb78e
1 parent
4436ff81
code de température effectif
Showing
1 changed file
with
53 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,53 @@ |
1 | +#include <avr/io.h> // for the input/output register | |
2 | +#include <avr/interrupt.h> | |
3 | +#include <util/delay.h> | |
4 | +#include <string.h> | |
5 | +#include <stdio.h> | |
6 | +#include <stdlib.h> | |
7 | + | |
8 | +#include "libretour.h" | |
9 | + | |
10 | +#define PRESCALER 1024 | |
11 | +#define TIME_SLOT 20 | |
12 | +#define BAUDRATE 103 | |
13 | + | |
14 | +#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) | |
15 | +#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) | |
16 | + | |
17 | +char Donnee[24]; | |
18 | +float temp; | |
19 | + | |
20 | +// équivalent de analogueRead() | |
21 | +int analogReadNew(uint8_t pin) { | |
22 | + //Selection de la fréquence du prescaler | |
23 | + ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); | |
24 | + //Définition de la référence de tension | |
25 | + ADMUX |= (1<<REFS0)|(1<<ADLAR); | |
26 | + //Sélection de l'entrée analogique selon le pin | |
27 | + ADMUX = (ADMUX&0xf0)|pin; | |
28 | + //Activation de l'ADC | |
29 | + ADCSRA |= (1<<ADEN); | |
30 | + //Lancement de la conversion | |
31 | + ADCSRA |= (1<<ADSC); | |
32 | + //On attend la fin de la conversion | |
33 | + while(bit_is_set(ADCSRA, ADSC)); | |
34 | + //Résultat | |
35 | + return ADCH; | |
36 | +} | |
37 | + | |
38 | +int main() | |
39 | +{ | |
40 | + int reading; | |
41 | + init_serial(); | |
42 | + while(1){ | |
43 | + reading=analogReadNew(0); | |
44 | + temp = reading * 1.9607843; | |
45 | + dtostrf(temp, 4, 1, Donnee); | |
46 | + //send_serial('T'); | |
47 | + //send_serial('='); | |
48 | + //RETOUR | |
49 | + retour(Donnee); | |
50 | + _delay_ms(2000); | |
51 | + } | |
52 | + return 0; | |
53 | +} | ... | ... |