Commit 679fa31a949cd18167e18840df5e0e97e10313b8
1 parent
d44c4579
Fichiers RPI
Showing
4 changed files
with
17 additions
and
80 deletions
Show diff stats
site/fichiersRPI/fichiersRPI.zip
No preview for this file type
site/fichiersRPI/load.sh
site/upload/binaire.c
... | ... | @@ -4,6 +4,9 @@ |
4 | 4 | #include <string.h> |
5 | 5 | #include <stdio.h> |
6 | 6 | #include <stdlib.h> |
7 | + | |
8 | +#include "libretour.h" | |
9 | + | |
7 | 10 | #define PRESCALER 1024 |
8 | 11 | #define TIME_SLOT 20 |
9 | 12 | #define BAUDRATE 103 |
... | ... | @@ -14,86 +17,21 @@ |
14 | 17 | char Donnee[24]; |
15 | 18 | float temp; |
16 | 19 | |
17 | -void init_serial(void) | |
18 | -{ | |
19 | - /* ACHTUNG : we suppose UBRR value < 0xff */ | |
20 | - /* Not true in all case */ | |
21 | - uint8_t baudrate = BAUDRATE; | |
22 | - /* Set baud rate */ | |
23 | - UBRR0H = 0; | |
24 | - UBRR0L = baudrate; | |
25 | - /* Enable transmitter *///task_led_red(); | |
26 | - //task_send_serial('A'); | |
27 | - UCSR0B = (1<<TXEN0); | |
28 | - /* Set frame format */ | |
29 | - UCSR0C = 0x06; | |
30 | - | |
31 | -} | |
32 | - | |
33 | -void send_serial(unsigned char c) | |
34 | -{ | |
35 | - loop_until_bit_is_set(UCSR0A, UDRE0); | |
36 | - UDR0 = c; | |
37 | -} | |
38 | - | |
39 | - | |
40 | -void send_msg2(char Donnee[]){ | |
41 | - | |
42 | - while (( UCSR0A & (1<<UDRE0)) == 0){}; | |
43 | - | |
44 | - for (int i = 0; i < strlen(Donnee); i++){ | |
45 | - while (( UCSR0A & (1<<UDRE0)) == 0){}; | |
46 | - UDR0 = Donnee[i]; | |
47 | - if (i == (strlen(Donnee) - 1)){ | |
48 | - send_serial('\n'); | |
49 | - send_serial('\r'); | |
50 | - } | |
51 | - } | |
52 | -} | |
53 | - | |
54 | -void send_msg(char Donnee[]){ | |
55 | - int i=0; | |
56 | - for(i=0; i<strlen(Donnee); i++){ | |
57 | - if (i==strlen(Donnee)-1){ | |
58 | - send_serial(Donnee[i]); | |
59 | - send_serial('\n'); | |
60 | - send_serial('\r'); | |
61 | - } | |
62 | - else{ | |
63 | - send_serial(Donnee[i]); | |
64 | - } | |
65 | - _delay_ms(100); | |
66 | - } | |
67 | -} | |
68 | - | |
69 | - | |
70 | 20 | // équivalent de analogueRead() |
71 | 21 | int analogReadNew(uint8_t pin) { |
72 | - /* | |
73 | - // Définition de la référence de tension | |
74 | - ADMUX |= (1 << REFS0); | |
75 | - // On sélectionne notre pin | |
76 | - ADMUX |= pin & 0x07; | |
77 | - | |
78 | - // On lance la conversion | |
79 | - sbi(ADCSRA, ADSC); | |
80 | - | |
81 | - // Le bit sera désactivé à la fin de la conversion | |
82 | - while(bit_is_set(ADCSRA, ADSC)); | |
83 | - | |
84 | - // Lire ADCL en premier est obligatoire, sinon l'ADC se bloque | |
85 | - uint8_t low = ADCL; | |
86 | - | |
87 | - // Récupérer le résultat | |
88 | - return ((ADCH << 8) | low); | |
89 | - */ | |
22 | + //Selection de la fréquence du prescaler | |
90 | 23 | ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); |
24 | + //Définition de la référence de tension | |
91 | 25 | ADMUX |= (1<<REFS0)|(1<<ADLAR); |
26 | + //Sélection de l'entrée analogique selon le pin | |
92 | 27 | ADMUX = (ADMUX&0xf0)|pin; |
28 | + //Activation de l'ADC | |
93 | 29 | ADCSRA |= (1<<ADEN); |
94 | - | |
30 | + //Lancement de la conversion | |
95 | 31 | ADCSRA |= (1<<ADSC); |
32 | + //On attend la fin de la conversion | |
96 | 33 | while(bit_is_set(ADCSRA, ADSC)); |
34 | + //Résultat | |
97 | 35 | return ADCH; |
98 | 36 | } |
99 | 37 | |
... | ... | @@ -105,9 +43,10 @@ int main() |
105 | 43 | reading=analogReadNew(0); |
106 | 44 | temp = reading * 1.9607843; |
107 | 45 | dtostrf(temp, 4, 1, Donnee); |
108 | - send_serial('T'); | |
109 | - send_serial('='); | |
110 | - send_msg2(Donnee); | |
46 | + //send_serial('T'); | |
47 | + //send_serial('='); | |
48 | + //RETOUR | |
49 | + retour(Donnee); | |
111 | 50 | _delay_ms(2000); |
112 | 51 | } |
113 | 52 | return 0; | ... | ... |
site/upload/inventaire.ini