Commit 65705671470818dfaee3cdee7d4265452e118a0b

Authored by rguillom
1 parent d16bd857

Début prog

Showing 1 changed file with 63 additions and 5 deletions   Show diff stats
... ... @@ -49,7 +49,7 @@ return ADCH;
49 49  
50 50 // For the I/O
51 51 void output_init(void){
52   -DDRB |= 0x01; // PIN 8 as output
  52 +DDRB |= 0b00011111; // PIN 8-13 as output
53 53 }
54 54  
55 55 void output_set(unsigned char value){
... ... @@ -57,22 +57,80 @@ if(value==0) PORTB &= 0xfe; else PORTB |= 0x01;
57 57 }
58 58  
59 59 void input_init(void){
60   -DDRD &= 0xfb; // PIN 2 as input
61   -PORTD |= 0x04; // Pull-up activated on PIN 2
  60 +DDRD |= 0x7c; // PIN 2-6 as input (Bouton Joystick + boutons)
  61 +DDRC |= 0x03; // PIN 0-1 analogiques comme input (x et y joystick analogique)
62 62 }
63 63  
64 64 unsigned char input_get(void){
65 65 return ((PIND&0x04)!=0)?1:0;
66 66 }
67 67  
  68 +void commande_leds(){
  69 + unsigned char temp_serial, leds;
  70 + temp_serial = get_serial();
  71 + if (temp_serial !=0){
  72 + leds = temp_serial;
  73 + if (leds == 65) PORTB = PORTB | 0x01;
  74 + if (leds == 66) PORTB = PORTB | 0x02;
  75 + if (leds == 67) PORTB = PORTB | 0x04;
  76 + if (leds == 68) PORTB = PORTB | 0x08;
  77 + if (leds == 69) PORTB = PORTB | 0x10;
  78 + if (leds == 70) PORTB = PORTB | 0x20;
  79 +
  80 + if (leds == 97) PORTB = PORTB & 0xfe;
  81 + if (leds == 98) PORTB = PORTB & 0xfd;
  82 + if (leds == 99) PORTB = PORT B & 0xfb;
  83 + if (leds == 100) PORTB = PORT B & 0xf7;
  84 + if (leds == 101) PORTB = PORT B & 0xef;
  85 + if (leds == 102) PORTB = PORT B & 0xdf;
  86 + }
  87 +}
  88 +
68 89 // Dummy main
69 90  
70 91 int main(void){
71 92 init_serial(9600);
72   - ad_init(0); //pas sur que ce soit ici
73 93 output_init();
74 94 input_init();
75 95  
  96 + unsigned char boutons, boutons_anc;
  97 + unsigned char joystick_x, joystick_x_anc;
  98 + unsigned char joystick_y, joystick_y_anc;
  99 +
  100 +
  101 + boutons_anc = PORTD & 0x7C;
  102 + ad_init(0);
  103 + joystick_x_anc = ad_sample();
  104 + ad_init(1);
  105 + joystick_y_anc = ad_sample();
  106 +
  107 + while(1){
  108 + boutons = PORTD & 0x7C;
  109 + ad_init(1);
  110 + joystick_x = ad_sample();
  111 + ad_init(0);
  112 + joystick_y = ad_sample();
76 113  
77   -return 0;
  114 + if (boutons_anc != boutons) send_serial(boutons);
  115 + if ((joystick_x_anc != joystick_x) || (joystick_y_anc != joystick_y){
  116 + send_serial(joystick_x);
  117 + send_serial(joystick_y);
  118 + }
  119 +
  120 + commande_leds();
  121 + }
  122 +
  123 + return 0;
78 124 }
  125 +
  126 +
  127 +
  128 +
  129 +
  130 +
  131 +
  132 +
  133 +
  134 +
  135 +
  136 +
... ...