Blame view

tests/atmega2560/ledControl/tlc5947.c 1.44 KB
9ce6804b   pfrison   ledDriver test a ...
1
  #include <avr/io.h>
004b9394   pfrison   Avant début piste
2
  
9ce6804b   pfrison   ledDriver test a ...
3
4
  #include "tlc5947.h"
  
004b9394   pfrison   Avant début piste
5
6
7
8
9
  #define DDR_DLED_CLOCK	DDRE
  #define PORT_DLED_CLOCK	PORTE
  
  #define DDR_DLED_DATA	DDRG
  #define PORT_DLED_DATA	PORTG
9ce6804b   pfrison   ledDriver test a ...
10
  
004b9394   pfrison   Avant début piste
11
12
  #define DDR_DLED_LATCH	DDRB
  #define PORT_DLED_LATCH	PORTB
9ce6804b   pfrison   ledDriver test a ...
13
  
004b9394   pfrison   Avant début piste
14
15
16
  #define PIN_DLED_CLOCK	0x08
  #define PIN_DLED_DATA	0x20
  #define PIN_DLED_LATCH	0x10
9ce6804b   pfrison   ledDriver test a ...
17
18
19
  
  void init_LED_Drivers(int nb){
      // LED drivers I/O as outputs
004b9394   pfrison   Avant début piste
20
21
22
      DDR_DLED_CLOCK |= PIN_DLED_CLOCK;
      DDR_DLED_DATA |= PIN_DLED_DATA;
      DDR_DLED_LATCH |= PIN_DLED_LATCH;
9ce6804b   pfrison   ledDriver test a ...
23
      // Set LATCH output low
004b9394   pfrison   Avant début piste
24
      PORT_DLED_LATCH &= ~PIN_DLED_LATCH;
9ce6804b   pfrison   ledDriver test a ...
25
26
27
28
29
  }
  
  
  void set_LED_Drivers(unsigned int pwm[], int nb){
      // Set LATCH output low
004b9394   pfrison   Avant début piste
30
      PORT_DLED_LATCH &= ~PIN_DLED_LATCH;
9ce6804b   pfrison   ledDriver test a ...
31
32
33
34
35
36
37
38
      // 24 channels per TLC5947
      int i;
      for(i=DLED_CHANNELS*nb-1; i>=0; i--){
          // 12 bits per channel, send MSB first
          int v=pwm[i];
          int j;
          for(j=0; j<12; j++){
              // Set CLOCK output low
004b9394   pfrison   Avant début piste
39
              PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK;
9ce6804b   pfrison   ledDriver test a ...
40
41
42
  
              // Set DATA as stated by bit #j of i
              if(v & 0x0800)
004b9394   pfrison   Avant début piste
43
                  PORT_DLED_DATA |= PIN_DLED_DATA;
9ce6804b   pfrison   ledDriver test a ...
44
              else
004b9394   pfrison   Avant début piste
45
                  PORT_DLED_DATA &= ~PIN_DLED_DATA;
9ce6804b   pfrison   ledDriver test a ...
46
47
  
              // Set CLOCK output HIGH
004b9394   pfrison   Avant début piste
48
              PORT_DLED_CLOCK |= PIN_DLED_CLOCK;
9ce6804b   pfrison   ledDriver test a ...
49
50
51
52
              v <<= 1;
          }
      }
      // Set CLOCK output low
004b9394   pfrison   Avant début piste
53
      PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK;
9ce6804b   pfrison   ledDriver test a ...
54
55
  
      // Set LATCH output high
004b9394   pfrison   Avant début piste
56
      PORT_DLED_LATCH |= PIN_DLED_LATCH;
9ce6804b   pfrison   ledDriver test a ...
57
      // Set LATCH output low
004b9394   pfrison   Avant début piste
58
      PORT_DLED_LATCH &= ~PIN_DLED_LATCH;
9ce6804b   pfrison   ledDriver test a ...
59
  }