Commit 1e53d5cca33a8443bdd10e1873bd15077b4db1f4
1 parent
686fbdf0
UPDATE - Inspiration d'un exemple de la librairie LUFA
Showing
13 changed files
with
0 additions
and
141 deletions
Show diff stats
Moteur.c deleted
... | ... | @@ -1,141 +0,0 @@ |
1 | -#include <avr/io.h> // for the input/output register | |
2 | -#include <util/delay.h> | |
3 | - | |
4 | -// For the serial port | |
5 | - | |
6 | -#define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz | |
7 | - | |
8 | -void init_serial(int speed) //initialisation de la liaison série | |
9 | -{ | |
10 | -/* Set baud rate */ | |
11 | -UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; | |
12 | - | |
13 | -/* Enable transmitter & receiver */ | |
14 | -UCSR0B = (1<<TXEN0 | 1<<RXEN0); | |
15 | - | |
16 | -/* Set 8 bits character and 1 stop bit */ | |
17 | -UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); | |
18 | - | |
19 | -/* Set off UART baud doubler */ | |
20 | -UCSR0A &= ~(1 << U2X0); | |
21 | -} | |
22 | - | |
23 | -void send_serial(unsigned char c) //envoyer un carctère sur le port série | |
24 | -{ | |
25 | -loop_until_bit_is_set(UCSR0A, UDRE0); | |
26 | -UDR0 = c; | |
27 | -} | |
28 | - | |
29 | - | |
30 | -unsigned char get_serial(void) //récupérer un caractère envoyé sur le port série | |
31 | -{ | |
32 | -loop_until_bit_is_set(UCSR0A, RXC0); | |
33 | -return UDR0; | |
34 | -} | |
35 | - | |
36 | - | |
37 | -// For the AD converter | |
38 | - | |
39 | -void ad_init(unsigned char channel) //channel 0 ou 1 | |
40 | -{ | |
41 | -ADCSRA|=(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); | |
42 | -ADMUX|=(1<<REFS0)|(1<<ADLAR); | |
43 | -ADMUX=(ADMUX&0xf0)|channel; | |
44 | -ADCSRA|=(1<<ADEN); | |
45 | -} | |
46 | - | |
47 | - | |
48 | -unsigned int ad_sample(void) //récupère la valeur de sortie du port de conversion analogique/numérique | |
49 | -{ | |
50 | -ADCSRA|=(1<<ADSC); | |
51 | -while(bit_is_set(ADCSRA, ADSC)); | |
52 | -return ADCH; | |
53 | -} | |
54 | - | |
55 | - | |
56 | -// For the I/O | |
57 | - | |
58 | -void output_init(void) | |
59 | -{ | |
60 | - DDRB |= 0x07; // PIN 8, 9, 10 en sortie | |
61 | -} | |
62 | - | |
63 | -void output_set(unsigned char value, unsigned char led) //permet d'allumer et éteindre les led | |
64 | -{ | |
65 | - if(led==1) | |
66 | - { | |
67 | - if(value==0) PORTB &= 0xfe; else PORTB |= 0x01; | |
68 | - } | |
69 | - if(led==2) | |
70 | - { | |
71 | - if(value==0) PORTB &= 0xfd; else PORTB |= 0x02; | |
72 | - } | |
73 | - if(led==3) | |
74 | - { | |
75 | - if(value==0) PORTB &= 0xfb; else PORTB |= 0x04; | |
76 | - } | |
77 | -} | |
78 | - | |
79 | - | |
80 | -void input_init(void) | |
81 | -{ | |
82 | -DDRD &= 0xf3; // PIN 2 et 3 en entrée (2 pour le bouton du joystick, 3 pour D3) | |
83 | -PORTD |= 0x0c; // Pull-up activé sur les PIN 2 et 3 | |
84 | -} | |
85 | -/* | |
86 | -unsigned char input_get(unsigned char bouton) //récupère et retourne l'état des PIN 2 et 3 | |
87 | -{ | |
88 | - if(bouton==1) //joystick | |
89 | - { | |
90 | - return ((PIND&0x04)!=0)?1:0; | |
91 | - } | |
92 | - if(bouton==2) //D3 | |
93 | - { | |
94 | - return ((PIND&0x08)!=0)?1:0; | |
95 | - } | |
96 | -} | |
97 | -*/ | |
98 | - | |
99 | -void led(unsigned char led) //permet de faire clignoter la LED dont le numéro est en paramètre | |
100 | -{ | |
101 | - output_set(1,led); | |
102 | - _delay_ms(50); | |
103 | - output_set(0,led); | |
104 | - _delay_ms(50); | |
105 | -} | |
106 | - | |
107 | - | |
108 | -int main(void) | |
109 | -{ | |
110 | - output_init(); //initialisation des ports | |
111 | - input_init(); | |
112 | - init_serial(9600); //on choisit une vitesse de 9600 bauds pour la transmission série | |
113 | - | |
114 | - while(1) | |
115 | - { | |
116 | - // output_set(1,1); //Allumage de la LED 1 qui indique que l'arduino est sous tension | |
117 | - | |
118 | -//Gestion de la direction avec le joystick | |
119 | - unsigned char r; | |
120 | - // int i=1; | |
121 | - //ad_init(0); //channel 0 pour gauche et droite | |
122 | - //unsigned int a=ad_sample(); | |
123 | - // ad_init(1); //channel 1 pour haut et bas | |
124 | - // unsigned int b=ad_sample(); | |
125 | - //send_serial('d'); //on envoie le caractère 'd' | |
126 | - //led(2); //on fait clignoter la 2ème LED quand on envoie | |
127 | - | |
128 | - //On récupère un carcatère sur la liaison série. | |
129 | - r=get_serial(); | |
130 | - while(r=='a') | |
131 | - { | |
132 | - led(1); | |
133 | - if(r=='z') | |
134 | - { | |
135 | - break; | |
136 | - } | |
137 | - r=get_serial(); | |
138 | - } | |
139 | - } | |
140 | -return 0; | |
141 | -} |
Config/LUFAConfig.h renamed to lufa/Config/LUFAConfig.h
Descriptors.c renamed to lufa/Descriptors.c
Descriptors.h renamed to lufa/Descriptors.h
LUFA VirtualSerial.inf renamed to lufa/LUFA VirtualSerial.inf
USB_gadget.c renamed to lufa/USB_gadget.c
USB_gadget.h renamed to lufa/USB_gadget.h
VirtualSerial.c renamed to lufa/VirtualSerial.c
VirtualSerial.h renamed to lufa/VirtualSerial.h
VirtualSerial.txt renamed to lufa/VirtualSerial.txt
asf.xml renamed to lufa/asf.xml
doxyfile renamed to lufa/doxyfile
makefile renamed to lufa/makefile