tlc5947.c
1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <avr/io.h>
#include "tlc5947.h"
#define DLED_CHANNELS 24
#define DDR_DLED DDRD
#define PORT_DLED PORTD
#define PIN_DLED_CLOCK 5
#define PIN_DLED_DATA 4
#define PIN_DLED_LATCH 6
void init_LED_Drivers(int nb){
// LED drivers I/O as outputs
DDR_DLED |= (1<<PIN_DLED_CLOCK) | (1<<PIN_DLED_DATA) | (1<<PIN_DLED_LATCH);
// Set LATCH output low
PORT_DLED &= ~(1<<PIN_DLED_LATCH);
}
void set_LED_Drivers(unsigned int pwm[], int nb){
// Set LATCH output low
PORT_DLED &= ~(1<<PIN_DLED_LATCH);
// 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
PORT_DLED &= ~(1<<PIN_DLED_CLOCK);
// Set DATA as stated by bit #j of i
if(v & 0x0800)
PORT_DLED |= (1<<PIN_DLED_DATA);
else
PORT_DLED &= ~(1<<PIN_DLED_DATA);
// Set CLOCK output HIGH
PORT_DLED |= (1<<PIN_DLED_CLOCK);
v <<= 1;
}
}
// Set CLOCK output low
PORT_DLED &= ~(1<<PIN_DLED_CLOCK);
// Set LATCH output high
PORT_DLED |= (1<<PIN_DLED_LATCH);
// Set LATCH output low
PORT_DLED &= ~(1<<PIN_DLED_LATCH);
}