El micro funciona a 16 Mhz.
#define LONG_DELAY __delay_cycles(14);
#define SHORT_DELAY __delay_cycles(1);
#define BIT_HIGH P1OUT |=BIT0; LONG_DELAY; P1OUT &= ~BIT0; SHORT_DELAY;
#define BIT_LOW P1OUT |=BIT0; SHORT_DELAY; P1OUT &= ~BIT0; LONG_DELAY;
Datos
Los datos son un array de 24 bits RGB
// (MSB.........LSB)
unsigned char red1[]={1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
unsigned char red2[]={0,1,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
unsigned char red3[]={0,0,0,1,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
unsigned char green1[]={0,0,0,0,0,0,0,0, 1,1,1,0,0,0,0,0, 0,0,0,0,0,0,0,0};
unsigned char red1[]={1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
unsigned char red2[]={0,1,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
unsigned char red3[]={0,0,0,1,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
unsigned char green1[]={0,0,0,0,0,0,0,0, 1,1,1,0,0,0,0,0, 0,0,0,0,0,0,0,0};
Una función para que recibe como parametro el array con los datos del color.
void sendColor(unsigned char *color){
int n;
for (n=0; n<24 br="" n=""> if (color[n]) {
BIT_HIGH
} else {
BIT_LOW
}
}
}24>
int n;
for (n=0; n<24 br="" n=""> if (color[n]) {
BIT_HIGH
} else {
BIT_LOW
}
}
}24>
El bucle principal envia datos a tres leds conectados en serie.
int main(){
while(1){
sendColor(red1);
sendColor(red2);
sendColor(green1);
__delay_cycles(100000000);
sendColor(green1);
sendColor(red1);
sendColor(red2);
__delay_cycles(10000000);
}
}