MINI LED CHRISTMAS TREE
Christmas tree control circuit
#define Row_A GP0_bit
#define Row_B GP1_bit
#define Row_C GP2_bit
#define Row_D GP4_bit
#define Row_E GP5_bit
unsigned int i, j, k, loop=120;
// Pin I/O direction and data values for lighting up each LED
const unsigned short TRISIO_Data[]={0x3c, 0x39, 0x2b, 0x0f, 0x0f, 0x2b, 0x39, 0x3c, \
0x3a, 0x1b, 0x1b, 0x3a, 0x2d, 0x2d, 0x2e, 0x2e, 0x1d, 0x1d, 0x1e, 0x1e};
const unsigned short PORT_Data[] = {0x01, 0x02, 0x04, 0x10, 0x20, 0x10, 0x04, 0x02, \
0x01, 0x04, 0x20, 0x04, 0x02, 0x10, 0x01, 0x10, 0x02, 0x20, 0x01, 0x20};
// Four user defined LED glow patterns
const unsigned short Pattern_Data1[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, \
0, 0, 0, 0, 0, 0}; // Border LEDs ON
const unsigned short Pattern_Data2[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, \
0, 1, 0, 0, 0, 1}; // Light 14, 16, and 20
const unsigned short Pattern_Data3[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, \
0, 1, 1, 0, 1, 1}; // Light 13, 17, and 19
const unsigned short Pattern_Data4[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
1, 1, 1, 1, 1, 1}; // Light all
void ALL_LEDs_OFF(){
GPIO = 0x00;
TRISIO = 0xFF;
}
void LED_ON(unsigned short num){
TRISIO = TRISIO_Data[num-1];
GPIO = PORT_Data[num-1];
Delay_us(500);
}
void Display_Pattern(unsigned short m){
for(j=1; j<=20; j++){
switch (m) {
case 1 : if(Pattern_Data1[j-1] == 1) LED_ON(j);
break;
case 2 : if(Pattern_Data2[j-1] == 1) LED_ON(j);
break;
case 3 : if(Pattern_Data3[j-1] == 1) LED_ON(j);
break;
case 4 : if(Pattern_Data4[j-1] == 1) LED_ON(j);
break;
} //case end
}
}
void main() {
CMCON0 = 7;
ANSEL = 0;
GPIO = 0;
TRISIO = 0xFF;
do {
for(k=0; k<loop; k++){
Display_Pattern(1);
}
for(k=0; k<loop; k++){
Display_Pattern(2);
}
for(k=0; k<loop; k++){
Display_Pattern(3);
}
for(k=0; k<loop; k++){
Display_Pattern(4);
}
ALL_LEDs_OFF();
Delay_ms(200);
for(k=0; k<loop; k+=4){
Display_Pattern(4);
}
ALL_LEDs_OFF();
Delay_ms(200);
for(k=0; k<loop; k+=4){
Display_Pattern(4);
}
ALL_LEDs_OFF();
Delay_ms(200);
for(k=0; k<loop; k+=4){
Display_Pattern(4);
}
ALL_LEDs_OFF();
Delay_ms(500);
} while(1) ;
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น